Identifying whether a jpg image is blank using RUBY programming

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
rubymonk
Posts: 3
Joined: 2018-10-08T13:19:11-07:00
Authentication code: 1152

Identifying whether a jpg image is blank using RUBY programming

Post by rubymonk »

I have an input image known as test.jpg. I want to create a function in Ruby which will identify if the image is white or close to white.(The function should incorporate some noise) and return a boolean value true or false.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identifying whether a jpg image is blank using RUBY programming

Post by fmw42 »

You can do the following in Imageamgick command line:

Code: Select all

convert image -threshold X% -format "%[fx:mean==1?1:0]" info:
for pure white or if you want to allow some dark noise, then change the test to

Code: Select all

convert image -threshold X% -format "%[fx:mean<=0.99?1:0]" info:
put in whatever value you want in place of 0.99 to allow for some black specs to remain after thresholding.

Sorry, I do not know Ruby. But equivalent commands should be available in RMagick or minimagick.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Identifying whether a jpg image is blank using RUBY programming

Post by fmw42 »

Post an example image to some free hosting service such as dropbox.com that won't change the format. Then put the URL here.

My guess is that you need to do some noise filtering, such as from -morphology close.
Post Reply