Python Forum
identify not white pixels in bmp
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
identify not white pixels in bmp
#1
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.

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!!
Reply


Messages In This Thread
identify not white pixels in bmp - by flash77 - Sep-24-2023, 10:07 AM
RE: identify not white pixels in bmp - by DPaul - Sep-24-2023, 12:50 PM
RE: identify not white pixels in bmp - by flash77 - Sep-24-2023, 02:28 PM
RE: identify not white pixels in bmp - by ALIII - Sep-24-2023, 02:51 PM
RE: identify not white pixels in bmp - by flash77 - Oct-04-2023, 04:47 AM
RE: identify not white pixels in bmp - by flash77 - Oct-05-2023, 05:16 PM
RE: identify not white pixels in bmp - by flash77 - Oct-05-2023, 07:52 PM
RE: identify not white pixels in bmp - by flash77 - Oct-07-2023, 04:58 PM
RE: identify not white pixels in bmp - by flash77 - Oct-07-2023, 07:48 PM
RE: identify not white pixels in bmp - by flash77 - Oct-08-2023, 09:21 PM
RE: identify not white pixels in bmp - by flash77 - Oct-09-2023, 06:18 AM
RE: identify not white pixels in bmp - by flash77 - Nov-10-2023, 09:21 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,043 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Need to identify only files created today. tester_V 5 4,722 Feb-18-2021, 06:32 AM
Last Post: tester_V
  pillow reversing the order of pixels after every row johnEmScott 4 3,183 May-27-2020, 09:42 AM
Last Post: scidam
  Need to identify sheet color in excel workbook chewy1418 2 2,570 Feb-14-2020, 03:26 PM
Last Post: chewy1418
  Convert 400 grayscale pixels into RGB python420 1 2,489 Jan-02-2020, 04:19 PM
Last Post: Clunk_Head
  Need help to identify Mersenne Primes, I do need a search pattern. Pleiades 0 1,961 Dec-03-2019, 11:05 PM
Last Post: Pleiades
  White spaces kdiba 1 2,003 Oct-08-2019, 06:52 PM
Last Post: Aurthor_King_of_the_Brittons
  including the white space parts in str.split() Skaperen 6 3,351 Jun-20-2019, 06:03 PM
Last Post: Skaperen
  replace white space with a string, is this pythonic? Skaperen 1 2,039 Jun-18-2019, 11:36 PM
Last Post: metulburr
  Syntax Error : I can't identify what's wrong! caarsonr 11 6,411 Jun-10-2019, 11:18 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020