我对计算机视觉非常陌生,我想学习图像配准。我想应用cross_correlation_shifts,但是我一直收到一个错误。我在jupyter笔记本中编写的代码如下:
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)运行与cross_correlation_shifts相关的代码,我得到以下错误:
---------------------------------------------------------------------------
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)我所用的图像都是同一个杯子。第一个Mug.jpg是一个正常的直线图像,旋转的一个是同一个Mug的图像,但它是向右倾斜的。
有人能告诉我这里有什么问题吗?
发布于 2020-12-08 12:08:42
您的图像看起来是2D RGB,因此Image1.form是(例如) (512,512,3),即ylen,xlen,num_channels。您需要以某种方式将它们转换为灰度,例如使用skimage.color.rgb2gray (但是要小心,因为这会使您的图像在0,1中浮动)。
https://stackoverflow.com/questions/65187691
复制相似问题