Page 1 of 1

Ignore transparent pixels in subimage search

Posted: 2018-11-01T02:13:41-07:00
by EdenResident
Hello,
I've attached 2 images big.png and small.png. Is it possible to tell IM to ignore transparent pixels in small.png when doing subimage seach against big.png? That way, the matching metrics would be better.

I'm well aware of the -read-mask feature. In fact, I've created the small_mask.png image by filling the transparent pixels in small.png with black and the rest with white. Using the mask, my matching metrics indeed decreased from 0.15 to 0.09 (exactly what I want). However, create the extra mask is redundant work because the mask is already embedded in the transparent pixels. I've also tried all the -alpha options without expected results.

So, basically, is there a way to activate -read-mask by just using transparent pixels, instead of having to create the actual mask image? Thanks, in advance.
big.png
https://www.dropbox.com/s/w5bo26s42vrmmng/big.png?dl=0
small.png
https://www.dropbox.com/s/0ablbgzxwcrj7 ... l.png?dl=0
small_mask.png
https://www.dropbox.com/s/fwflp6gqq5pv2 ... k.png?dl=0

Re: Ignore transparent pixels in subimage search

Posted: 2018-11-01T05:37:25-07:00
by snibgo
What version of IM?

Please show the command you used. Otherwise we cannot suggest how it could be improved.

I have written process modules eg Process modules for this exact problem.

Code: Select all

convert srchbig.png srchsmall.png -process srchimg NULL:
0.0940821 @ 310,21
However, to use my process modules, you need to rebuild IM from source.

Re: Ignore transparent pixels in subimage search

Posted: 2018-11-01T19:06:26-07:00
by EdenResident
Hi snibgo,

My IM is 7.0.8-14. These are the commands I use to do the image search.

Without mask

Code: Select all

magick compare -metric RMSE -subimage-search big.png small.png -similarity-threshold 0 -dissimilarity-threshold 1 similarity.gif
This one gives 0.15 matching.

With mask

Code: Select all

magick compare -metric RMSE -subimage-search big.png ( -read-mask small_mask.png small.png ) -similarity-threshold 0 -dissimilarity-threshold 1 similarity.gif
This one gives 0.09 matching.

Looks like your process module is exactly what I need. How can I use it?