[HELP] Autocrop batch on photo ID

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

newbie1 wrote:Ther is error mesage is:

Code: Select all

convert: missing expression `' @ error/fx.c/FxEvaluateSubexpression/2111.
/home/user/123/test1.sh: 4: [: -eq: unexpected operator
But there is still a output and the output is awalys newid.jpg which is in the else statement.

See my note above. It is failing because the sed is not getting data it expects. Thus the test fails because there is no value produced from sed and so you always get the "else" condition.
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

fmw42 wrote:What is the error message when running the script?

I suspect the sed command is likely not doing the right thing, because the output from compare is now different.

compare -metric rmse rose: \( -size 70x46 xc:red \) null:
28533 (0.435386)

But

compare -metric NCC rose: \( -size 70x46 xc:red \) null:
0

This does not look right. I would expect some difference. But only one value in the range 0 to 1. I suspect one gets zero here because there is not one single pixel in the rose image that is exactly red.

This gives a perfect match thought there is some precision issue that cause the result to be slightly larger than 1.

compare -metric NCC rose: rose: null:
1.00031




Likewise

compare -metric AE -fuzz 10% rose: \( -size 70x46 xc:red \) null:
3220

This is only giving the raw counts. This is probably correct with only one value. It is not normalized and so is going to be image size dependent, unless you divide by the total pixels in the image.

You have to understand that different error measure produce different output. So sed is not finding any parenthesis to locate the value in the parenthesis.

For these measures, just take out the sed command.

value=`compare -metric AE -fuzz 10% image1 image2 null: 2>&1`
I got another error when i take the sed command out:

Code: Select all

convert: unable to parse expression `compare' @ error/fx.c/FxGetSymbol/1828.
/home/user/123/test1.sh: 4: [: -eq: unexpected operator
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [HELP] Autocrop batch on photo ID

Post by fmw42 »

What are your exact commands. If you are using AE or some other measure, you will not be able to use the same threshold. Each measure will need a different calibration of the threshold value.
newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

It works now.

Code: Select all

#!/bin/sh
value=`compare -metric AE -fuzz 10% 2.jpg 5.jpg null: 2>&1`
test=`convert xc: -format "%[fx:$value<420000?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
Now, i know that because using -subimage-search makes it slower.

Thank You! :D
Post Reply