user16755372
user16755372

Reputation:

Numpy of image> 0

I first binarized an image and then filtered it in python.

Now how can I add every pixel> 0 to a numpy array?

img = Image.open('native.png').convert('RGB')
binarised = img.convert('LA')
# binarised.save('binarised.png')
filtered = ndimage.median_filter(binarised, size = 27)
# Image.fromarray(filtered).save('filtered.png')

width, height = img.size

x = np.array([])
y = np.array([])
for column in range(width):
    for line in range(height):
        if(???):              ### if pixel at column/line > 0 ###
            x = np.append(x, column)
            y = np.append(y, line)

Upvotes: 1

Views: 386

Answers (1)

U13-Forward
U13-Forward

Reputation: 71560

Try this:

        if (filtered[column - 1, line - 1] > 0).all():

Upvotes: 1

Related Questions