plt.imshow doesn't display the image outside of its original domain

Viewed 42

I ran a simple script to register the landmarks (via translation, rotation and scaling) of the Helen data set. I have decided to center all face based on the point between the two eyes, and define that as the center of my system (position 0,0). I have successfully managed to create a data based on registered landmarks. Great, that was the first step.

Second step is to registered the actual images; what's in between the landmarks. I'm using skimage and things are technically working:

dst = np.array(Data[1])
dst[:,1] = -dst[:,1]
fig, ax = plt.subplots()
ax.imshow(Helen1)
plt.scatter(dst[:,0], dst[:,1], color="red", s=1)
plt.show()

Image With Landmarks:

Image With Landmarks

src = np.array(Data_Aligned[1])
src[:,1] = src[:,1]
tform3 = PiecewiseAffineTransform()
tform3.estimate(src,dst)
warped = warp(Helen1, tform3,clip=False)

The problem seems to be in the display function, it seems like the original image is in (0,\infty)^2 and plotting anything outside of this domain returns something blank.

fig, ax = plt.subplots()
plt.xlim([700, 1500])
plt.ylim([700, 1500])
plt.imshow(warped)
plt.scatter(src[:,0], src[:,1], color="red", s=1)
plt.show()

Registered:

Registered

Anyone knows the solution to this problem ? I want the middle of the eyes to be the origin (0,0). Obviously I can move the center around to be within the domain of the original image and it works, here (1000,1000):

Centered at 1000,1000:

Centered at 1000,1000

Anyone knows a way to allow imshow to display outside the original domain of the image ?

1 Answers

This is not an imshow problem, but a warp problem.

The output of warp has the same size as the input. So the "domain" of that image is [0,1600] or something like that, for both axes. So, indeed, you cannot warp your image so its center is at (0,0), because the image domain always starts there.

You need to pick some positive coordinate (preferably the center of the output image) as the origin of your system. Say this origin is o = (1000, 1000). You then display your image with

ysz, xsz, nchan = warped.shape
plt.imshow(warped, extent=(-o[0]-0.5, xsz-o[0]-0.5, ysz-o[1]-0.5, -o[1]-0.5))

This will shift the image within the plot's coordinate system.

Related