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⁰

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter8: Arrays
Section: Chapter Questions
Problem 9PE
icon
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 ( )
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage