Sep-24-2023, 10:07 AM
Dear community,
I would like to find the pixels of an image that are different from white.
The position is not important; later I would like to determine the proportion of pixels in the overall image that are different from white.
(I want to use this to determine whether a PDF that has been converted to a BMP for analysis is blank.)
The image p2 is completely white except for 1 blue, 1 green and 1 red pixel.
I would like to find these 3 pixels.
Thanks alot!!
I would like to find the pixels of an image that are different from white.
The position is not important; later I would like to determine the proportion of pixels in the overall image that are different from white.
(I want to use this to determine whether a PDF that has been converted to a BMP for analysis is blank.)
The image p2 is completely white except for 1 blue, 1 green and 1 red pixel.
I would like to find these 3 pixels.
import numpy as np from PIL import Image img = Image.open("p2.bmp") numpy_array = np.array(img) # identify not white pixels for i in numpy_array: if i[0] != 255 and [i][1] != 255 and [i][2] != 255: print(i)Unfortunately, I don't understand the following error message:
Traceback (most recent call last): File "D:\Daten\aktuell\leerePDFs_erkennen\main.py", line 22, in <module> if i[0] != 255 and [i][1] != 255 and [i][2] != 255: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()I would be very happy about a tip!!
Thanks alot!!