normcrosscorr

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
Ejz
Posts: 3
Joined: 2013-08-02T02:43:24-07:00
Authentication code: 6789

normcrosscorr

Post by Ejz » 2013-08-02T02:53:14-07:00

This issue applies to normcrosscorr script at http://www.fmwconcepts.com/imagemagick/normcrosscorr/

Firstly, there should be

Code: Select all

std=`convert $tmpS -format "%[standard-deviation]" info:`
instead of

Code: Select all

std=`convert $tmpS -format "%[standard_deviation]" info:`
Secondly, i don't understand why if i blur slightly an image the script goes crazy and outputs point that absolutely is not related with position of the image i search.

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normcrosscorr

Post by fmw42 » 2013-08-02T10:29:33-07:00

Which image did you blur? The larger one, the smaller one or both. I will look into it.

At some point the naming of standard deviation in the string format may have been changed. But I will check the script to look into that and update if needed.

Ejz
Posts: 3
Joined: 2013-08-02T02:43:24-07:00
Authentication code: 6789

Re: normcrosscorr

Post by Ejz » 2013-08-03T12:56:28-07:00

Thx for reply, here is my code. It's not ok even without blur.

Code: Select all

# convert wizard: wizard.png
# convert wizard.png -crop 150x50+130+80 +repage subwizard.png
# ./normcrosscorr -s subwizard.png wizard.png corr.png | tail -n 2
Echo:

Code: Select all

Match Coords: (168,326) And Score In Range 0 to 1: (0.0943717)
Position should be (130,80) :-(

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normcrosscorr

Post by fmw42 » 2013-08-03T14:39:23-07:00

Your subsection is not terribly unique (too much white). Nevertheless, in principle, it should have worked. However, there has been an issue with proper normalization since I wrote this script and cannot figure out how to fix it. There is a caution about this in the documentation.

"# WARNING: I believe due to the way ImageMagick normalizes images internally
# to a dynamic range of 0 to 1 before doing any processing, the correlation
# surface will not generally have a perfect match score of +1, but will be
# image dependent and smaller than 1. Nevertheless, it does seem to find the
# correct best match location.
"

All the tests I did, seemed to find a good solution for unique subsections. See
http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
http://www.fmwconcepts.com/imagemagick/ ... /index.php


In principle a perfect match should return a value of 1. But the script is returning smaller values. With your test images, it seems to find something slightly higher in match score at some other locations, because the normalization is not working correctly.

I find the same results as you did with your example.

normcrosscorr1 -s -c white wizard_sub_130_80.png wizard.png wizard_corr.png wizard_location.png

Match Coords: (168,326) And Score In Range 0 to 1: (0.0943717)


But if I cut the input image in half, to avoid those false positives, it does find the correct results.

normcrosscorr1 -s -c white wizard_sub_130_80.png wizardhf.png wizardhf_corr.png wizardhf_location.png

Match Coords: (130,80) And Score In Range 0 to 1: (0.111959)

Strangely, the match score is higher in this case than the previous. The normalization should be independent of the size of the larger image. It does depend upon the size of the smaller image. So this is a mystery to me at the moment.

I will try to review this script further. But I am not sure I will be able to fix the normalization issue.

In the mean time I will modify the script to fix the standard deviation issue and update the warning.

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normcrosscorr

Post by fmw42 » 2013-08-03T18:04:26-07:00

P.S.

You can use IM compare and it can be made faster if you use -similarity-threshold to stop the search when an appropriate match is found and it will find the correct match.


time normcrosscorr wizard_sub_130_80.png wizard.png null:

Match Coords: (168,326) And Score In Range 0 to 1: (0.0943717)

real 0m23.907s
user 0m20.787s
sys 0m7.306s




time compare -metric rmse -subimage-search -similarity-threshold 0 wizard.png wizard_sub_130_80.png null:
0 (0) @ 130,80

real 0m9.236s
user 0m8.980s
sys 0m0.094s

Ejz
Posts: 3
Joined: 2013-08-02T02:43:24-07:00
Authentication code: 6789

Re: normcrosscorr

Post by Ejz » 2013-08-04T11:55:41-07:00

Tried on screenshot, it's ok. Is white so hardly abuses normalization of an image? I can handle amount of white and use -subimage-search

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normcrosscorr

Post by fmw42 » 2013-08-04T14:30:18-07:00

I am still reviewing normcrosscorr. Perhaps I will have some new thoughts to test to figure out what might be happening. But I cannot guarantee that nor when. So you might be better using compare for now.

User avatar
fmw42
Posts: 25274
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: normcrosscorr

Post by fmw42 » 2013-08-24T14:57:56-07:00

I believe that I have finally revised this script to properly normalize so that a perfect match is +1

Post Reply