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
#5
To find the pixels in an image that are different from white and later determine the proportion of non-white pixels in the overall image, you can use image processing libraries such as Python's OpenCV. Here's a step-by-step guide:


1. ** Install OpenCV **: If you haven't already, you'll need to install the OpenCV library. You can do this using pip:
pip install opencv-python

2. ** Load and Process the Image **:

   import cv2
   import numpy as np

   # Load the image
   image = cv2.imread('p2.bmp')

   # Convert the image to grayscale
   gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

   # Define the color white (you may need to adjust this based on your image)
   white = [255, 255, 255]

   # Create a mask for non-white pixels
   mask = cv2.inRange(image, np.array(white), np.array(white))

   # Find the non-white pixels in the original image
   non_white_pixels = cv2.countNonZero(mask)

   # Calculate the proportion of non-white pixels in the image
   total_pixels = image.shape[0] * image.shape[1]
   proportion_non_white = non_white_pixels / total_pixels

   # Display the proportion
   print(f"Proportion of non-white pixels: {proportion_non_white:.4f}")
This code will load your image ('p2.bmp'), convert it to grayscale, and create a mask for the non-white pixels. It then calculates the proportion of non-white pixels in the image.

3. ** Adjust the White Threshold **: In the code above, we assumed that white pixels have the RGB values [255, 255, 255]. If your white is slightly different, you may need to adjust these values accordingly.

4. ** Run the Code **: Save your image as 'p2.bmp' in the same directory as the Python script, and run the code. It will print the proportion of non-white pixels in the image.

This code should help you determine whether your BMP image contains non-white pixels, which can be useful for detecting blank PDFs.
buran write Oct-09-2023, 03:01 AM:
Spam link removed
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
  Need help to identify CNA for automation qatester 0 133 May-31-2024, 09:24 AM
Last Post: qatester
  guys please help me , pycharm is not able to identify my xlsx file CrazyGreenYT7 1 2,108 Jun-13-2021, 02:22 PM
Last Post: Larz60+
  Need to identify only files created today. tester_V 5 4,840 Feb-18-2021, 06:32 AM
Last Post: tester_V
  pillow reversing the order of pixels after every row johnEmScott 4 3,236 May-27-2020, 09:42 AM
Last Post: scidam
  Need to identify sheet color in excel workbook chewy1418 2 2,612 Feb-14-2020, 03:26 PM
Last Post: chewy1418
  Convert 400 grayscale pixels into RGB python420 1 2,526 Jan-02-2020, 04:19 PM
Last Post: Clunk_Head
  Need help to identify Mersenne Primes, I do need a search pattern. Pleiades 0 2,011 Dec-03-2019, 11:05 PM
Last Post: Pleiades
  White spaces kdiba 1 2,035 Oct-08-2019, 06:52 PM
Last Post: Aurthor_King_of_the_Brittons
  including the white space parts in str.split() Skaperen 6 3,412 Jun-20-2019, 06:03 PM
Last Post: Skaperen
  replace white space with a string, is this pythonic? Skaperen 1 2,073 Jun-18-2019, 11:36 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

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