How to identify image is totally white?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sripvk1234
Posts: 3
Joined: 2015-04-10T02:59:30-07:00
Authentication code: 6789

How to identify image is totally white?

Post by sripvk1234 »

Could please let me know what options should use to identify the image is totally white
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to identify image is totally white?

Post by snibgo »

If an image is entirely white then the minimum value in each of the RGB channels is 100% (or 1 in a scale of 0.0 to 1.0).

By finding these three values, and taking the minimum of them, a result of "1" means all pixels are white. A lesser value means not all pixels are white.

Code: Select all

convert -precision 15 in.png -format "%[fx:min(minima.r,min(minima.g,minima.b))]" info:
snibgo's IM pages: im.snibgo.com
sripvk1234
Posts: 3
Joined: 2015-04-10T02:59:30-07:00
Authentication code: 6789

Re: How to identify image is totally white?

Post by sripvk1234 »

Thanks for very quick reply. Actually my requirement is we should fill a text and draw an image in totally white images using ImageMagick

Is there any direct commands to do that? If not, could you please suggest me how to do that.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to identify image is totally white?

Post by snibgo »

I don't understand what you want.
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to identify image is totally white?

Post by Bonzo »

I have no idea either - link to a sample showing what you want.

What have you tried? What platform and language are you using?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to identify image is totally white?

Post by fmw42 »

If the image is totally pure white, then the average of the image will be white.

Code: Select all

convert -size 100x100 xc:white -scale 1x1! -format "%[pixel:u.p{0,0}]" info:
white

So test your image the same way

Code: Select all

convert yourimage -scale 1x1! -format "%[pixel:u.p{0,0}]" info:
sripvk1234
Posts: 3
Joined: 2015-04-10T02:59:30-07:00
Authentication code: 6789

Re: How to identify image is totally white?

Post by sripvk1234 »

Thanks to each and everyone for suggestions.

Here is my requirement
For example: There is an image(a.jpg) which is totally white.

As per my requirement, if image is totally white then we should embed or draw another image (logo.jpg) on a.jpg. Similarly, we should add a text on a.jpg.

Could you please let me know commands or options to do it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to identify image is totally white?

Post by fmw42 »

What is your version of IM and platform? scripting is different for Windows and Unix.

What you say totally white, is there any tolerance to slightly not white?
Post Reply