Page 1 of 1

Count white color

Posted: 2012-07-11T11:23:11-07:00
by myspacee
Hello,
Windows user, last version installed.

Reading this link searching a method to identify when my Production fail to generate a PDF file.
Think that counting how many WHITE there is i can easily identify bad file from good one.

Need to count how many white there is, maybe in percert value. Post thumb to help understand problem:
Image
http://static.repubblica.it/laprovincia ... rr/bad.jpg

and pdf files:
http://static.repubblica.it/laprovincia ... r/good.pdf
http://static.repubblica.it/laprovincia ... rr/bad.pdf

Find interesting reply in old post:
cconvert bad.pdf -fill white -opaque white -fill black +opaque white -format "%%[fx:100*mean]" info:

but can't understand how read value.

Anyone can help please?

thank you,
m.

Re: Count white color

Posted: 2012-07-11T18:10:13-07:00
by fmw42
convert bad.pdf -fuzz XX% -fill white -opaque white -fill black +opaque white -format "%%[fx:100*mean]" info:
This changes any color within XX% of white to white (-fuzz XX% -fill white -opaque white), then changes anything that is not white to black (-fill black +opaque white), then computes the mean value (in range 0 to 1) of the binary image and multiplies by 100 to get percent white.

Re: Count white color

Posted: 2012-07-13T06:33:56-07:00
by myspacee
thank you for reply fmw42,
create batch that analize files when created.

have a question, is there any way to cut decimal in % value [98.5866 --> 98] ?

thank you for support,
m.

Re: Count white color

Posted: 2012-07-13T07:20:02-07:00
by Bonzo
Try:

Code: Select all

convert bad.pdf -fuzz XX% -fill white -opaque white -fill black +opaque white -format "%%[fx:round(100*mean)]" info:

Re: Count white color

Posted: 2012-07-15T21:15:08-07:00
by anthony
Bonzo wrote:Try:

Code: Select all

convert bad.pdf -fuzz XX% -fill white -opaque white -fill black +opaque white -format "%%[fx:round(100*mean)]" info:
On DOS you need the double %, under linux (or IMv7 "magick script") you do not.

Re: Count white color

Posted: 2012-07-15T23:59:48-07:00
by whugemann
I think that this question is rather more about DOS batch programming than about ImageMagick. So here is some batch sample code. For explanations see the link below. The code stores the mean value in an environment variable named WP, which may be evaluated by an IF statement. I kept the Convert statement rudimentary -- see the hints of the others in regard to it:

Code: Select all

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
For %%i in (*.pdf) DO (
For /F %%a in ('convert %%i -resize 1x1 -format "%%[fx:100*mean]" info:') DO SET WP=%%a
IF !WP! GEQ 95 (
ECHO %%i = White
) ELSE (
ECHO %%i = Black
)
)