Convert PIL image to skimage?

I have an image loaded in my code (very long and unnecessary, will not be posted here) that I need to work with skimage to detect blobs in the image. However, for some reason, all the images and attempts I have used do not work.

The image is modified by PIL in the code above so that the objects I'm trying to find are only white (255, 255, 255) and all others are black. This code should only identify their positions. I tried a lot of different things to get this to work (converting them to a numpy array, not converting them to ect of a numpy array.)

I follow these instructions: http://scikit-image.org/docs/dev/auto_examples/plot_blob.html for the basics, but this is not really a tutorial but an example.

I think the rgb2gray function is problematic as it returns nothing but 0, while printing (numpy.array (img)) returns values ​​between 0 and 1, indicating that information loss occurs when rgb2gray is called.

Here's the code that seems problematic:

img_gray = rgb2gray(numpy.array(img)) # Convert to numpy array for skimage
print(img_gray)
print(numpy.array(img))
img_blobs = blob_doh(img_gray, threshold=0.01, max_sigma=500)
print(img_blobs)

      

How can I fix this?

EDIT:

This is what each of the images, arrays and lists prints:

[[ 0.          0.          0.         ...,  0.          0.          0.        ] #img_gray
 [ 0.          0.00392157  0.01568627 ...,  0.          0.          0.        ]
 [ 0.          0.01176471  0.05882353 ...,  0.          0.          0.        ]
 ..., 
 [ 1.          0.99607843  0.96078431 ...,  0.          0.          0.        ]
 [ 1.          1.          0.98039216 ...,  0.          0.          0.        ]
 [ 1.          1.          0.99215686 ...,  0.          0.          0.        ]]
[[[  0   0   0] #img
  [  0   0   0]
  [  0   0   0]
  ..., 
  [  0   0   0] #img
  [  0   0   0]
  [  0   0   0]]

 [[  0   0   0] #img
  [  1   1   1]
  [  4   4   4]
  ..., 
  [  0   0   0] #img
  [  0   0   0]
  [  0   0   0]]

 [[  0   0   0] #img
  [  3   3   3]
  [ 15  15  15]
  ..., 
  [  0   0   0] #img
  [  0   0   0]
  [  0   0   0]]

 ..., 
 [[255 255 255] #img
  [254 254 254]
  [245 245 245]
  ..., 
  [  0   0   0] #img
  [  0   0   0]
  [  0   0   0]]

 [[255 255 255] #img
  [255 255 255]
  [250 250 250]
  ..., 
  [  0   0   0] #img
  [  0   0   0]
  [  0   0   0]]

 [[255 255 255]
  [255 255 255]
  [253 253 253]
  ..., 
  [  0   0   0]
  [  0   0   0]
  [  0   0   0]]]
[] #img_blobs

      

+3


source to share


1 answer


This will read image files (using PIL) into an image:

from skimage import io
img = io.imread("./path/to/image.png")

      



Since you've already read the images and wanted to do the data transformation yourself, you can see how the plugin authors did it: https://github.com/scikit-image/scikit-image/blob/master/skimage/io/_plugins/pil_plugin. py

0


source







All Articles