Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 . ( 2 0 pts . ) Nearest Neighbor: Write code to resize an image using nearest neighbor interpolation for resampling. - Starter code

1.(20 pts.) Nearest Neighbor: Write code to resize an image using nearest neighbor interpolation for resampling.- Starter code available in directory resize.- resize/resample.py: Edit the function nearest_neighbor to implement this part.2.(40 pts.) Bilinear Interpolation: Write code to resize an image using bilinear interpolation for resampling.- Starter code available in directory resize.- resize/resample.py: Edit the function bilinear_interpolation to implement this part.- resize/interpolation.py: Write code for linear and bilinear interpolation in their respective function definitions, you are welcome to write new functions and call them from these functions----------------------- Please do not change the code structure- Do not edit the function "resize"- This part of the assignment can be run using dip_hw1_resize.py (there is no need to edit this file)- Usage: `./dip_hw1_resize.py -i image-name -fx scalex -fy scaley -m method`- image-name: name of the image- scalex, scaley: scale to resize the image (eg. fx 0.5, fy 0.5 to make it half the original size)- method: "nearest_neightbor" or "bilinear"- Please make sure your code runs when you run the above command from prompt/Terminal- Any output images or files must be saved to the "output/" folderclass interpolation:def linear_interpolation(self, Pt1, Pt2, x):"""Computes the linear interpolation value at some iD location x between two 1D points (Pt1 and Pt2).There are no arguments defined in the function definition on purpose. It is left upto the student to define any requierd arguments.Please change the signature of the function and add the arguments based on your implementation.The function ideally takes two 1D points Pt1 and Pt2, and their intensitites I(Pt1), I(Pt2).return the interpolated intensity value (I(x)) at location x """# Write your code for linear interpolation herereturn (1- x)* Pt1+ x * Pt2def bilinear_interpolation(self, Pt1, Pt2, Pt3, Pt4, x, px):"""Computes the bilinear interpolation value at some 2D location x between four 2D points (Pt1, Pt2, Pt3, and Pt4).There are no arguments defined in the function definition on purpose. It is left upto the student to define any requierd arguments.Please change the signature of the function and add the arguments based on your implementation.The function ideally takes four 2D points Pt1, Pt2, Pt3, and Pt4, and their intensitites I(Pt1), I(Pt2), I(Pt3), and I(Pt4).return the interpolated intensity value (I(x)) at location x """# Write your code for bilinear interpolation here# Recall that bilinear interpolation performs linear interpolation three times# Please reuse or call linear interpolation method three times by passing the appropriate parameters to compute this taskinter1= self.linear_interpolation(Pt1, Pt2, x)inter2= self.linear_interpolation(Pt3, Pt4, x)return self.linear_interpolation(inter1, inter2, px)class resample:def resize(self, image, fx=None, fy=None, interpolation=None):"""calls the appropriate funciton to resample an image based on the interpolation methodimage: the image to be resampledfx: scale along x direction (eg.0.5,1.5,2.5)fx: scale along y direction (eg.0.5,1.5,2.5)interpolation: method used for interpolation ('either bilinear or nearest_neighbor)returns a resized image based on the interpolation method"""if interpolation == 'bilinear':return self.bilinear_interpolation(image, float(fx), float(fy))elif interpolation == 'nearest_neighbor':return self.nearest_neighbor(image, float(fx), float(fy))def nearest_neighbor(self, image, fx, fy):"""resizes an image using nearest neighbor approximation for resamplingimage: the image to be resampledfx: scale along x direction (eg.0.5,1.5,2.5)fx: scale along y direction (eg.0.5,1.5,2.5)returns a resized image based on the nearest neighbor interpolation method"""# Write your code for resampling using nearest neighbor interpolation herereturndef bilinear_interpolation(self, image, fx, fy):"""resizes an image using bilinear interpolation approximation for resamplingimage: the image to be resampledfx: scale along x direction (eg.0.5,1.5,2.5)fx: scale along y direction (eg.0.5,1.5,2.5)returns a resized image based on the bilinear interpolation methodNote: Do not write the code to perform interpolation between points in this file.There is a file named interpolation.py, and two function definitions are providedlinear_interpolation: Write your code to perform linear interpolation between two in this functionbilinear_interpolation: Write your code to perform bilinear interpolation using four points in this functions.As bilinear interpolation essentially does linear interpolation three times, you could simply call thelinear_interpolation function three times, with the correct parameters."""# Write your code for resampling using bilinear interpolation herereturn

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions