Normcrosscorr - Auto crop troubles

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Post Reply
gnome_41
Posts: 4
Joined: 2016-08-03T02:44:43-07:00
Authentication code: 1151

Normcrosscorr - Auto crop troubles

Post by gnome_41 »

Hello all!

I wonder if anybody could help me in my use of Fred's normcrosscorr script.
I'm tring to use it to calculate where a large image needs to be cropped by referencing a smaller image.
So far I have got it to draw a square around the area and output to a new file (as the script was intended to do) - but what I really want, is for it to fill the space outside of the square it draws with one set colour (any will do). This will allow me to use autocrop on Photoshop for the cropping of thousands of images saving me a whole lot of time =]

So far all I've done is add -strokewidth ### to line 516 of the script. This almost has the effect I want but the strokewidth expands from the centre of the line meaning it fills part of the area I want left clear.

Code: Select all

Line 516: 	convert $dir/tmpA2.mpc[${wlo}x${hlo}+0+0] -fill none -strokewidth 1000 -stroke "$color" \
Edit:: is it possible to send the coords of the square to 'compare' so that it can handle the crop instead?

Any help/ideas would be awesome =]
gnome_41
Posts: 4
Joined: 2016-08-03T02:44:43-07:00
Authentication code: 1151

Re: Normcrosscorr - Auto crop troubles

Post by gnome_41 »

Okay, so I've added a crop command to end of line 516 of normcrosscorr and removed -stroke "$color"

Code: Select all

convert $dir/tmpA2.mpc[${wlo}x${hlo}+0+0] -fill none -stroke "$color" -crop ${ws}x${hs}+$ulx+$uly\

Code: Select all

convert $dir/tmpA2.mpc[${wlo}x${hlo}+0+0] -fill none -crop ${ws}x${hs}+$ulx+$uly\
And HUZZAH! it works =]
the output file is now a lovely cropped version of the original photo
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Normcrosscorr - Auto crop troubles

Post by fmw42 »

I will add that option to the script when I get a chance.
gnome_41
Posts: 4
Joined: 2016-08-03T02:44:43-07:00
Authentication code: 1151

Re: Normcrosscorr - Auto crop troubles

Post by gnome_41 »

Awesome =] Great work btw. You help a lot of people out with these scripts :)
gnome_41
Posts: 4
Joined: 2016-08-03T02:44:43-07:00
Authentication code: 1151

Re: Normcrosscorr - Auto crop troubles

Post by gnome_41 »

One final thought on this.
Can you think of a way this could be used as a batch process?
My thoughts so far are to call the script through another script; setting the options as variables that follow a set pattern.
I'll be looking into this on Monday but any help/pointers you have in the meantime would be great.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Normcrosscorr - Auto crop troubles

Post by fmw42 »

Are you processing different pairs of images? If so, then just write a script to loop over each pair calling normcrosscorr for each pair.

If you are processing the same large image, but different small images, then a new script could be created that would loop over each small image and process it against the same large image doing the FFT on the large image only once.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Normcrosscorr - Auto crop troubles

Post by fmw42 »

I have modified the script to add the new mode option of "best" for the large image subsection corresponding to the best match location to the small image. Give it a try and let me know if any problems.
Post Reply