Detect images with drops with ImageMagick

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
bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Detect images with drops with ImageMagick

Post by bekalariak »

Hi,

I have a big amount of pictures which I will use to do some timelapses. Well, some of them have drops of rain and I would like to apply a filter (yes, cover the camera would have been a good idea..). I think one of the best options is to use ImageMagick, but i do not know what way to choose. To my mind come several options, as using histogram on each picture ( convert picture.jpg -verbose -identify +verbose histogram:hist_picture.jpg) and configure a threshold or something like that or using spectrum/colorspectrum and also configure a threshold. I would like to know if you know any mehod that can be used to this situation and which could be the most effective. The purpose is only to conclude YES/NO DROPS for each picture.


Extra information: I am using perl scripts to do other filters and using mysql tables to save the information for each pic.

PD: cover the cameras
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Detect images with drops with ImageMagick

Post by snibgo »

Can you show sample images with and without drops? You can upload to anywhere on the web, and paste the URLs here.
snibgo's IM pages: im.snibgo.com
bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Re: Detect images with drops with ImageMagick

Post by bekalariak »

Yes, of course --> https://drive.google.com/drive/folders/ ... sp=sharing

Three of them are examples of pics that should not be included in the video and other two yes (first and last).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Detect images with drops with ImageMagick

Post by fmw42 »

Do edge detection and compute the density or amount of edges. Blurring from the water drops will not produce high quality edges. To compute the density of edges, you can threshold the edge detected image and then measure the average (mean) gray level in the image.

Edges can be computed in many ways: sobel, laplacian, morphology, -edge, -canny. See https://www.imagemagick.org/Usage/convolve/#edgedet

Then you pick a threshold on the mean value. If above the threshold, then no drops and if below the threshold, it has drops.
bekalariak
Posts: 6
Joined: 2018-05-02T06:18:59-07:00
Authentication code: 1152

Re: Detect images with drops with ImageMagick

Post by bekalariak »

To summarize, thank you very much for your answers and advice.

The way you explained probably is much easier than the ones that I did.

This id what I did:

1--> convert pic.jpg -define convolve:scale='!' \
-morphology Convolve Laplacian:0 \
-auto-level pic_laplacian_positives.png

2--> convert pic_laplacian_positives.png -format "%[mean]" info:

I am not get to used to use Imagemagic and dont know if i am using the correct kernel (I will try others too, test/failure..).
Maybe there are more optimal kernels but my little knowledge don't help me.

Anyway, thankyou!!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Detect images with drops with ImageMagick

Post by snibgo »

bekalariak wrote:-define convolve:scale='!' -morphology Convolve Laplacian:0
That is an edge detector. The result has positive and negative values, with a mean close to zero. "-auto-level" will make the result positive, with a mean close to 50%. This isn't useful for comparing images -- they will all have roughly the same mean.

Edge detector values are usually small, so I suggest you should use HDRI.

Instead, you can take the absolute value of the edge detector ("-evaluate Abs 0"). This leaves positive values alone, and makes negative values positive. Then you can take the mean, and comparisons of means between images is meaningful.

Code: Select all

magick -precision 16 toes.png -define convolve:scale="!" -morphology Convolve Laplacian:0 -evaluate Abs 0 -format %[fx:mean] info:
 
0.008843092928576947
(Sorry, your example images are too large for me to download.)
snibgo's IM pages: im.snibgo.com
Post Reply