ValueError: too many values to unpack (expected 2) while applying cross_correlation_shifts
ValueError: too many values to unpack (expected 2) while applying cross_correlation_shifts
我对计算机视觉还很陌生,想了解图像配准。我想应用 cross_correlation_shifts 但我一直收到错误消息。
我在jupyter notebook中写的代码如下:
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 的图像,但它向右倾斜。
谁能告诉我这里有什么问题吗?
您的图像显示为 2D RGB,因此 image1.shape 是(比方说)(512, 512, 3),即 ylen、xlen、num_channels.您需要以某种方式将它们转换为灰度,例如使用 skimage.color.rgb2gray
(但请注意,这会将您的图像重新缩放为 [0, 1] 中的浮点数)。
我对计算机视觉还很陌生,想了解图像配准。我想应用 cross_correlation_shifts 但我一直收到错误消息。 我在jupyter notebook中写的代码如下:
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 的图像,但它向右倾斜。
谁能告诉我这里有什么问题吗?
您的图像显示为 2D RGB,因此 image1.shape 是(比方说)(512, 512, 3),即 ylen、xlen、num_channels.您需要以某种方式将它们转换为灰度,例如使用 skimage.color.rgb2gray
(但请注意,这会将您的图像重新缩放为 [0, 1] 中的浮点数)。