[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: 26383
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 »

This does not finish for me on IM 6.6.9.7. So I think your version of IM is faulty.

compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null:


Furthermore, my result on a current version of IM gives different values than what you said.

So I think you need to upgrade your version of IM.

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

Should i upgrade my imgaemgaick to version 6.7.8?

User avatar
fmw42
Posts: 26383
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:Should i upgrade my imgaemgaick to version 6.7.8?

I just checked and my 6.6.9.7 was not installed. So I cannot say for sure that your version of IM is bad.

The only indication I have is that my result from


compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null:
143.673 (0.00219231) @ 32,20

is not the same as yours. If you get a return value that is the same, then your unix may be missing the sed command and that could be why it is not returning anything.

This works for me and returns:


value=`compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
echo "$value"
0.00219231


Double check both again and let me know what you get.


If you type

man sed

does that give you the man pages for sed? Or does it say there is no sed command?

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 get me to the man pages for sed.

I think it really is my version of imagemagick. So, i will now update to version 6.7.8

User avatar
fmw42
Posts: 26383
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:It get me to the man pages for sed.

I think it really is my version of imagemagick. So, i will now update to version 6.7.8

Get the latest version 6.7.8.9.

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

The latest is 6.7.8.10 should i install that?

User avatar
fmw42
Posts: 26383
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:The latest is 6.7.8.10 should i install that?
Sure, that should be fine.

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

I don't think i can install the lastest version as my ubuntu synaptic latest version is 6.6.9-7

User avatar
fmw42
Posts: 26383
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 »

I just installed IM 6.7.8.10 and I get this:

compare -metric rmse -subimage-search rose: xc:red null:
143.673 (0.00219231) @ 32,20


compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'
0.00219231


If that does not work, try


compare -metric rmse -subimage-search rose: xc:red null: 2>&1 | tr -cs ".0-9\n" " " | cut -d\ -f 2
0.00219231

User avatar
fmw42
Posts: 26383
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:I don't think i can install the lastest version as my ubuntu synaptic latest version is 6.6.9-7
I do not know what to tell you. try


compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null:
143.673 0.00219231 32 20


compare -metric rmse -subimage-search -dissimilarity-threshold 100% rose: xc:red null: 2>&1 | tr -cs ".0-9\n" " " | cut -d\ -f 2
0.00219231

If that does not work, can you back down to earlier releases of IM?

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

Finally it works!

I updates my imagemagick to the latest version.
The script is:

Code: Select all

#!/bin/sh
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<0.022?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
But there a problem. Its very very slow. When i start the script, it takes about 35 seconds for it to finish.

Is there any way to reduce the time taken ?

User avatar
fmw42
Posts: 26383
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:Finally it works!

I updates my imagemagick to the latest version.
The script is:

Code: Select all

#!/bin/sh
value=`compare -metric rmse -subimage-search 2.jpg 1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<0.022?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg oldid.jpg
else
convert 4.jpg newid.jpg
fi
But there a problem. Its very very slow. When i start the script, it takes about 35 seconds for it to finish.

Is there any way to reduce the time taken ?
You can try to use my script, norcrosscorr, but that requires IM in Q16 HDRI mode. It uses FFT to do fast correlation. See also http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr

You might get a bit speed up by using a simpler error measure than rmse. see http://www.imagemagick.org/Usage/compare/#statistics

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

After testing out different error measure, i realised that the script take too long to finish is because of "-subimage-search".

So, i took out "-subimage-search", but after tooking it out, there an error that say the width and height of the small and large image is different.

Then, I use the OldID and crop out everything except the word "STUDENT".(student1.jpg)
Image

After testing it out, The RMSE difference is too little.
But i found 2 error measure that has quite a difference.

The first one is NCC.
The error between the student1.jpg and oldID.jpg is

Code: Select all

0.0842306
The error between the student1.jpg and newID.jpg is

Code: Select all

0.0514787
However, after putting it into the script, there is an error. It is able to run but the output is wrong.

Code: Select all

#!/bin/sh
value=`compare -metric NCC newID.jpg student1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
test=`convert xc: -format "%[fx:$value<0.065?1:0]" info:`
if [ $test -eq 1 ]; then
convert 4.jpg newid.jpg
else
convert 4.jpg oldid.jpg
fi


The second one is AE -fuzz 10%
The error between the student1.jpg and oldID.jpg is

Code: Select all

372197
The error between the student1.jpg and newID.jpg is

Code: Select all

467993
The same error occur when i run this script. It is able to run but the output is wrong.

Code: Select all

#!/bin/sh
value=`compare -metric NCC newID.jpeg student1.jpg null: 2>&1 | sed -n 's/^.*(\(.*\)).*$/\1/p'`
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
What is wrong in the script?

User avatar
fmw42
Posts: 26383
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 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`
Last edited by fmw42 on 2012-08-13T19:39:56-07:00, edited 2 times in total.

newbie1
Posts: 31
Joined: 2012-05-29T07:31:08-07:00
Authentication code: 13

Re: [HELP] Autocrop batch on photo ID

Post by newbie1 »

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.

Locked