Ignore transparent pixels in subimage search

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
EdenResident
Posts: 2
Joined: 2018-11-01T01:46:50-07:00
Authentication code: 1152

Ignore transparent pixels in subimage search

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Ignore transparent pixels in subimage search

Post 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.
snibgo's IM pages: im.snibgo.com
EdenResident
Posts: 2
Joined: 2018-11-01T01:46:50-07:00
Authentication code: 1152

Re: Ignore transparent pixels in subimage search

Post 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?
Post Reply