auden
auden

Reputation: 1157

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!

Upvotes: 2

Views: 78

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207455

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)

Upvotes: 1

Related Questions