Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In [ ]: def warp_images (imgs, baseim, srcpts, basepts): Warp a collection of images to align them with a central base image using provided point

image text in transcribed

image text in transcribed

image text in transcribed

In [ ]: def warp_images (imgs, baseim, srcpts, basepts): Warp a collection of images to align them with a central base image using provided point correspondences to estimate the warping. Parameters imgs : list of 2D numpy.array (dtype=float) The arrays containing the input grayscale images baseim : int The index of the image which is the central base image srcpts: list of 2D numpy.array, each of size 2xNclicks x,y coordinates of points clicked by the user for each peripheral image basepts : list of 2D numpy.array, each of size 2xNclicks x,y coordinates of correponding locations in the base image Returns imgs_warped: list of 2D numpy.array (dtype=float) Tist of the resulting warped images, all of which will have the same shape # first estimate all the homographies homs = list() for i in range(len(imgs)): if (i == baseim): H = #identity matrix elif: H = compute_homography(...) #compute homography based on clicked points homs.append(H) # compute where the corners of each warped image end up # and the upper left and lower-right corners of a rectangle # that will enclose all of them ul np.array([0,0]) np.array([0,0]) for i in range(len(imgs)): ir s ul s Ir = #original coorner coordinates cx = np.array([...]) #warped coordinates cx_warped - apply_homography (homs[i].cx) np.min(...) np.max(...) #round these to integer valued coordinates ul = np.floor(ul) np.floor(r) # for debugging purposes, you may find it very useful at # this point to use plt.plot to plot out the warped # corner Locations and the bounding rectangle in the # code above. Irs # generate the coordinates of pixels in the output image that # cover the bounding rectangle determined above ogrid_y, ogrid_x = np. mgrid[...] # Loop over each input and warp it imgs_warped - list() for i in range(len(imgs)): #input pixel grid igrid_y, igrid_x = np.mgrid[...] # reshape igridy and igrid_x into a 2xN array so we can use # our applyHomography function on them. you can do # this with some combination of flatten() and stack() incoords = .... # transform pixel coordinates warpedcoords - apply_homography (homs[i], incoords) # note: griddata expects coords to be Nx2 and values to be Nxl so # make sure you transpose / flatten as necessary # brightness values reshaped as a Nxl array bvalues wcoords # use griddata to warp img_warped = griddata ....) imgs_warped.append(img_warped) return imgs_warped In [ ]: def warp_images (imgs, baseim, srcpts, basepts): Warp a collection of images to align them with a central base image using provided point correspondences to estimate the warping. Parameters imgs : list of 2D numpy.array (dtype=float) The arrays containing the input grayscale images baseim : int The index of the image which is the central base image srcpts: list of 2D numpy.array, each of size 2xNclicks x,y coordinates of points clicked by the user for each peripheral image basepts : list of 2D numpy.array, each of size 2xNclicks x,y coordinates of correponding locations in the base image Returns imgs_warped: list of 2D numpy.array (dtype=float) Tist of the resulting warped images, all of which will have the same shape # first estimate all the homographies homs = list() for i in range(len(imgs)): if (i == baseim): H = #identity matrix elif: H = compute_homography(...) #compute homography based on clicked points homs.append(H) # compute where the corners of each warped image end up # and the upper left and lower-right corners of a rectangle # that will enclose all of them ul np.array([0,0]) np.array([0,0]) for i in range(len(imgs)): ir s ul s Ir = #original coorner coordinates cx = np.array([...]) #warped coordinates cx_warped - apply_homography (homs[i].cx) np.min(...) np.max(...) #round these to integer valued coordinates ul = np.floor(ul) np.floor(r) # for debugging purposes, you may find it very useful at # this point to use plt.plot to plot out the warped # corner Locations and the bounding rectangle in the # code above. Irs # generate the coordinates of pixels in the output image that # cover the bounding rectangle determined above ogrid_y, ogrid_x = np. mgrid[...] # Loop over each input and warp it imgs_warped - list() for i in range(len(imgs)): #input pixel grid igrid_y, igrid_x = np.mgrid[...] # reshape igridy and igrid_x into a 2xN array so we can use # our applyHomography function on them. you can do # this with some combination of flatten() and stack() incoords = .... # transform pixel coordinates warpedcoords - apply_homography (homs[i], incoords) # note: griddata expects coords to be Nx2 and values to be Nxl so # make sure you transpose / flatten as necessary # brightness values reshaped as a Nxl array bvalues wcoords # use griddata to warp img_warped = griddata ....) imgs_warped.append(img_warped) return imgs_warped

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

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago

Question

Have roles been defined and assigned?

Answered: 1 week ago