Search code examples
pythonpython-3.ximage-processingscikit-imagenumpy-ndarray

Properly converting an image for use in blob_log


I'm using scikit-image's blob_log, which takes a parameter image and counts the blobs in it. The docs say

image - 2D or 3D ndarray

Input grayscale image, blobs are assumed to be light on dark background (white on black).

I have a preexisting image, foo.jpg, that I then convert to grayscale using

from PIL import Image
image_gray = Image.open("foo.jpg").convert('LA')

But I'm getting an error (AttributeError: ndim) when I use image_gray as an argument in blob_log. How do I take the grayscale image and properly turn it into a numpy array? Thanks!


Solution

  • You can just do:

    import numpy as np
    from PIL import Image
    
    image_gray = Image.open("foo.jpg").convert('LA')
    numpyImage = np.array(image_gray)