Code to compute the absolute error between the colors of the original image’s pixels and the colors of the image after it’s been rotated 360⁰
Code to compute the absolute error between the colors of the original image’s pixels and the colors of the image after it’s been rotated 360⁰
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
Related questions
Question
I dont know how to do this. I am not sure how to calculate any errors with my given code.
question: Absolute color error calculation: Code to compute the absolute error between the colors of the original image’s pixels and the colors of the image after it’s been rotated 360⁰
![import cv2
import numpy as np
from PIL import Image
import math
image = np.array(Image.open("Cones1. png"))
for x in range (3):
ang=int (input("Enter the angle of rotation : "))
angle=math.radians (ang)
cosine=math.cos(angle)
sine=math.sin(angle)
height=image.shape[0]
width=imagel. shape[1]
height1
width1
= round (abs (image.shape[0]*cosine)+abs (image.shape[1]*sine))+1
= round (abs (image.shape[1]*cosine)+abs (image.shape[0]*sine))+1
output=np.zeros ( (height1, width1, image.shape[2]))
originalHeight = round ( ((image.shape[0]+1)/2)-1)
originalwidth = round( ( (image.shape[1]+1)/2)-1)
newHeight= round ( ( (height1+1)/2)-1)
newwidth= round (( (width1+1)/2)-1)
for i in range (height):
for j in range (width):
y=image.shape[0]-1-i-originalHeight
x=image.shape[1]-1-j-originalwidth
newY=round(-x*sine+y*cosine)
newX=round (x*cosine+y*sine)
newY=newHeight-newY
newX=newWidth-newX
if 0 <= newX <width1 and 0 <= newY < height1 and newX>=0 and newY>=0:
output[newY, newX, :]=image[i,j,:1
cv2.imshow("Rotating "+str(ang)+' degrees',output/255.0)
cv2.waitKey(0)
cv2.destroyAllWindows ( )](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F0ec4da7d-d62c-4d19-8443-666a1347c813%2F7ac4f258-ccfe-4d05-8a27-9bff575d5804%2Fwslmger_processed.png&w=3840&q=75)
Transcribed Image Text:import cv2
import numpy as np
from PIL import Image
import math
image = np.array(Image.open("Cones1. png"))
for x in range (3):
ang=int (input("Enter the angle of rotation : "))
angle=math.radians (ang)
cosine=math.cos(angle)
sine=math.sin(angle)
height=image.shape[0]
width=imagel. shape[1]
height1
width1
= round (abs (image.shape[0]*cosine)+abs (image.shape[1]*sine))+1
= round (abs (image.shape[1]*cosine)+abs (image.shape[0]*sine))+1
output=np.zeros ( (height1, width1, image.shape[2]))
originalHeight = round ( ((image.shape[0]+1)/2)-1)
originalwidth = round( ( (image.shape[1]+1)/2)-1)
newHeight= round ( ( (height1+1)/2)-1)
newwidth= round (( (width1+1)/2)-1)
for i in range (height):
for j in range (width):
y=image.shape[0]-1-i-originalHeight
x=image.shape[1]-1-j-originalwidth
newY=round(-x*sine+y*cosine)
newX=round (x*cosine+y*sine)
newY=newHeight-newY
newX=newWidth-newX
if 0 <= newX <width1 and 0 <= newY < height1 and newX>=0 and newY>=0:
output[newY, newX, :]=image[i,j,:1
cv2.imshow("Rotating "+str(ang)+' degrees',output/255.0)
cv2.waitKey(0)
cv2.destroyAllWindows ( )
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage