我对计算机视觉非常陌生,想学习图像配准。我想应用互相关移位,但我一直得到一个错误。 我在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)
运行与交叉相关移位相关的代码时,会出现以下错误:
---------------------------------------------------------------------------
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是一个正常的直线图像,旋转的一个是同一个杯子的图像,但它向右倾斜
谁能告诉我这里有什么问题吗
您的图像显示为2DRGB,因此image1.shape是(比如)(512、512、3),即ylen、xlen、num_通道。您需要以某种方式将它们转换为灰度,例如使用
skimage.color.rgb2gray
(尽管要小心,因为这会将图像重新缩放为[0,1]中的浮动)相关问题 更多 >
编程相关推荐