Numpy.copy(图像数组)给出零大小的数组错误

时间:2014-05-22 09:46:11

标签: python arrays image-processing numpy computer-vision

我的图像是441x269。从here跟进,我试图从中提取子图像,如下所示:

rect = np.copy(image[start_x:end_x, start_y:end_y]) 

但是当它达到这个目标时崩溃了:

rect = np.copy (img[302:441, 31:160]) 
ig = ImageViewer(rect)
ig.show()

或者,在np.copy命令之后,我执行此操作:

misc.imsave(newfile, rect)

总之,这是可以用来重现问题的代码:

from skimage.viewer import ImageViewer
import cv2
import scipy.io as sio
from skimage import data, io, color
import numpy as np
from scipy import misc

img = cv2.imread("C:\\PATH_TO_MY_IMAGES.jpg")
img = color.rgb2gray(img)

# the line below creates a problem, but if I try, for example this: 
# np.copy (img[171:441, 33:211]), then no problem

rect = np.copy (img[302:441, 31:160]) 

#try the below and it gives an error. 
ig = ImageViewer(rect)
ig.show()

newfile= "C:\\work_asaaki\\patches\\ss_test\\%d.jpg" % j
misc.imsave(newfile, rect)

为什么呢?据我所知,所有给定的参数都适合图像,它们形成一个普通的矩形。

我得到的错误是:

C:\Program Files (x86)\Anaconda\lib\site-packages\matplotlib\axes.py:2760: UserWarning: Attempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=-0.5, top=-0.5
  + 'bottom=%s, top=%s') % (bottom, top))
C:\Program Files (x86)\Anaconda\lib\site-packages\matplotlib\axes.py:2760: UserWarning: Attempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=0, top=0
  + 'bottom=%s, top=%s') % (bottom, top))
Traceback (most recent call last):
  File "C:\Users\Administrator\.spyder2\.temp.py", line 51, in <module>
    ig = ImageViewer(rect)
  File "C:\Program Files (x86)\Anaconda\lib\site-packages\skimage\viewer\viewers\core.py", line 108, in __init__
    self._update_original_image(image)
  File "C:\Program Files (x86)\Anaconda\lib\site-packages\skimage\viewer\viewers\core.py", line 165, in _update_original_image
    self.image = image.copy()       # update displayed image
  File "C:\Program Files (x86)\Anaconda\lib\site-packages\skimage\viewer\viewers\core.py", line 235, in image
    if clim[0] < 0 and image.min() >= 0:
  File "C:\Program Files (x86)\Anaconda\lib\site-packages\numpy\core\_methods.py", line 21, in _amin
    out=out, keepdims=keepdims)
ValueError: zero-size array to reduction operation minimum which has no identity

我做错了什么?

0 个答案:

没有答案