ValueError: too many values to unpack (expected 2) while applying cross_correlation_shifts

493 views Asked by At

I am very new to computer vision and wanted to learn about image registration. I wanted to apply the cross_correlation_shifts but I keep getting an error. The code I wrote in jupyter notebook is as follows:

from skimage import io
import image_registration
from image_registration import cross_correlation_shifts
image = io.imread("Images/Mug.jpg")
offset_image = io.imread("Images/rotated_Mug.jpg")
xoff, yoff = image_registration.cross_correlation_shifts(image, offset_image)
print("Offset image ")
print("Pixels shifted by: ", xoff, yoff)

running the code related to cross_correlation_shifts, I get this error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-46-0d64c5cb8855> in <module>
----> 1 xoff, yoff = image_registration.cross_correlation_shifts(image, offset_image)
      2 
      3 print("Offset image ")
      4 print("Pixels shifted by: ", xoff, yoff)

/opt/anaconda3/lib/python3.7/site-packages/image_registration/cross_correlation_shifts.py in cross_correlation_shifts(image1, image2, errim1, errim2, maxoff, verbose, gaussfit, return_error, zeromean, **kwargs)
     87         raise ValueError("Cross-correlation image must have same shape as input images.  This can only be violated if you pass a strange kwarg to correlate2d.")
     88 
---> 89     ylen,xlen = image1.shape
     90     xcen = xlen/2-(1-xlen%2)
     91     ycen = ylen/2-(1-ylen%2)

ValueError: too many values to unpack (expected 2)

The images I am using are of the same mug. the first Mug.jpg is a normal straight image, the rotated one is an image of the same Mug but it was tilted to the right.

Could anyone please tell me what is the problem here ?

1

There are 1 answers

0
Juan On BEST ANSWER

Your images appear to be 2D RGB, so that image1.shape is (say) (512, 512, 3), ie ylen, xlen, num_channels. You need to convert them to grayscale somehow, e.g. with skimage.color.rgb2gray (though watch out as that will rescale your image to floats in [0, 1]).