Author Topic: Count number of black pixels  (Read 3636 times)

Offline Herbert_W

  • PixInsight Addict
  • ***
  • Posts: 204
    • Skypixels - Astrophotography by Herbert Walter
Count number of black pixels
« on: 2012 February 27 01:57:11 »
Hi,

I want to count the number of black pixels (value = 0) in an image.
Is there a possibility - eventually with Pixelmath?

Thank you and best regards.

Herbert, Austria

Offline vicent_peris

  • PTeam Member
  • PixInsight Padawan
  • ****
  • Posts: 988
    • http://www.astrofoto.es/
Re: Count number of black pixels
« Reply #1 on: 2012 February 27 02:43:23 »
Yes, you can. Put this expression in PixelMath:

iif ($T>0, 0, 1)

Then go to Statistics and see the mean pixel value. Multiply this value by the total number of pixels of your image. This will give you the number of black pixels.


Regards,
Vicent.

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: Count number of black pixels
« Reply #2 on: 2012 February 27 06:12:55 »
It would be nice if the histogram buckets could be exported to .csv. Or some complex XML format if Juan prefers that :)
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity

Offline oldwexi

  • PixInsight Guru
  • ****
  • Posts: 627
    • Astronomy Pages G.W.
Re: Count number of black pixels
« Reply #3 on: 2012 February 27 07:33:25 »
Servus Herbert!
It also works in that way:
PixelMath iif($T>0,1,0)

then open the Histogram and move the left slider a little to the right, that cuts away the shadows and
gives you exactly the count of black pixels which are black (incl. the percentage) in the column "Shadows" of the Histogram .

Aloha Gerald

Offline Juan Conejero

  • PTeam Member
  • PixInsight Jedi Grand Master
  • ********
  • Posts: 7111
    • http://pixinsight.com/
Re: Count number of black pixels
« Reply #4 on: 2012 February 27 08:56:42 »
<pedant_mode>
These expressions can be simplified:

iif( $T > 0, 1, 0 )

is the same as:

$T > 0

Conversely,

iif( $T > 0, 0, 1 )

is equivalent to:

$T <= 0

This is because the result of a relational operator (==, !=, <, <=, >, >=) is a Boolean value, which in PixelMath is always 0=false or 1=true.
</pedant_mode>

Besides that, both tricks are nice and smart ;)

Quote
It would be nice if the histogram buckets could be exported to .csv. Or some complex XML format if Juan prefers that

We have a new 'observer' tool planned which will have this functionality: Histogram. This tool will work like Statistics but showing histograms, with exporting capabilities for text and graphics (e.g., the histogram will be exportable both as an image and in SVG format). The Statistics tool will also have a major revamp by the way. Tabular data will be exported in CSV format, just as DynamicPSF does.
Juan Conejero
PixInsight Development Team
http://pixinsight.com/

Offline Nocturnal

  • PixInsight Jedi Council Member
  • *******
  • Posts: 2727
    • http://www.carpephoton.com
Re: Count number of black pixels
« Reply #5 on: 2012 February 27 09:23:32 »
Sounds great Juan, looking forward to it. Right now I use my own image statistics tool to quickly gather stats for dozens of images into a .csv file. I wrote that years ago when I found out that AIP4WIN had a rather horrendous memory leak when it did statistics on a series of images.
Best,

    Sander
---
Edge HD 1100
QHY-8 for imaging, IMG0H mono for guiding, video cameras for occulations
ASI224, QHY5L-IIc
HyperStar3
WO-M110ED+FR-III/TRF-2008
Takahashi EM-400
PIxInsight, DeepSkyStacker, PHD, Nebulosity