Python 提供零大小数组错误的Numpy.copy(图像数组)

Python 提供零大小数组错误的Numpy.copy(图像数组),python,arrays,image-processing,numpy,computer-vision,Python,Arrays,Image Processing,Numpy,Computer Vision,我有一个图像是441x269。接下来,我尝试从中提取子图像,如下所示: 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) 总而言之,这是可用于重现问题的代码:

我有一个图像是441x269。接下来,我尝试从中提取子图像,如下所示:

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

我做错了什么?

请提供一个完整的、再现问题的最小示例。好的!我已将问题编辑为包含可复制代码。您确定图像大小为441x269吗?如果img少于302行,img[302:441,31:160]将给出一个大小为零的数组。也许阵列的实际形状是269441?