Page 1 of 1

Calculate coverage of TIFFG4 in percent

Posted: 2011-07-19T08:56:16-07:00
by pictogram
Hello,

i have several TIFFG4 compressed bilevel images and want to calculate the converage of black pixels from a given rectangle of that page. So is it possible to count the black/white pixels of an arbitrary rectangle inside an image?

Re: Calculate coverage of TIFFG4 in percent

Posted: 2011-07-19T10:03:45-07:00
by fmw42
In unix:

numpixels=`convert image[WxH+X+Y] -format "%[fx:w*h]" info:`

totalwhitepixels=`convert xc: -format "%[fx:$numpixels*mean]" info:`
(note mean will be between 0 and 1 in fx expressions)

totalblackpixels=`cconvert xc: -format "%[fx:$numpixels - $totalwhitepixels]" info:`

see subsections at
http://www.imagemagick.org/Usage/files/#read_mods

see string formats and fx calculations
http://www.imagemagick.org/script/escape.php
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx
http://www.imagemagick.org/Usage/transform/#fx_escapes

if on windows, see differences in syntax at http://www.imagemagick.org/Usage/windows/

Re: Calculate coverage of TIFFG4 in percent

Posted: 2011-07-20T23:06:29-07:00
by pictogram
Hello and thank you very much! This code would do, but what i forgott to mention is that those bilevel TIFFs i'm talking about are very large (16200*23700 pixels).
It would take several Minutes so process one image...
Any hints about that? Can i convert the TG4s into something else before (with an other tool) so data is reduced? I don't think that i need to be more precise than 1% steps.

Re: Calculate coverage of TIFFG4 in percent

Posted: 2011-07-21T00:40:57-07:00
by whugemann
The basic trick that Fred suggests is to calculate the mean value of the image. This is supplied in the "mean" line when Identifying with the -verbose option. So it's basically a question of Identifying and then filtering. In a Windows batchfile:

Identify -verbose %1 | FIND "mean"

You can than store the value in an (environment) variable.

Re: Calculate coverage of TIFFG4 in percent

Posted: 2011-07-21T03:40:51-07:00
by pictogram
I understand and find the idea stunning simple. My problem is, that processing the compressed bilevel files takes sooo much time. But even processing uncompressed bilevel TIFFs takes too long. This is a IM problem, because on bit gets converted to 3 or more bytes per pixel by reading in the image.
This takes huge amounts of RAM and time.
Because i don't think this could be changed i need to preprocess the images somehow to make it more handy for IM. One thing is to reduze the size by cummulating pixelareas to single pixels (in respect to the expected precision i need) and output at least a graylevel image.