1

I have an image that is 441x269. Following up from here, I'm trying to extract sub-images from it, like this:

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

But it crashes when it gets to this:

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

or if, after the np.copy command, I do this:

misc.imsave(newfile, rect)

Put together, this is the code that can be used to reproduced the problem:

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)

Why? As far as I can see, all the given parameters fit within the image, and they form a normal rectangle.

The error I get is this:

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

What am I doing wrong?

3
  • Please include a complete minimal example that reproduces the problem. Commented May 22, 2014 at 9:51
  • Okay! I've edited the question to include reproducable code. Commented May 22, 2014 at 10:02
  • 2
    Are you sure the image has size 441x269? If img has fewer than 302 rows, img[302:441, 31:160] will give an array with zero size. Maybe the actual shape of the array is (269, 441)? Commented May 22, 2014 at 12:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.