I am using this amazing software on windows and the more I use it, the more it amazes me how powerful it is. I have an application described as follows and I am struggling to come up with a command line so would be grateful for some help from any experts on this forum.
I have a frame capture (say 800x800) which has a 400x400 picture repeated four times (i.e. like 4 quadrants – tope left, top right, bottom left and bottom right all have the same picture)
What I want to do is take a small section of the picture from one quadrant at a certain location,
e.g. a 100x100 area at x=50, y=100. (Note that this small section of the picture will be the same as at x=450, y=100 and at x=450, y=100 and at x=450, y=450)
And then look for this 100x100 area is each quadrant and probably save the result in text file (perhaps use –metric) to indicate if the same 100x100 area was matched in each quadrant.
The other idea I have been thinking is to blur / fuzz the first time this 100x100 area is found and then continue searching.
Has anyone got an idea to help me out here?
Thanks in advance.
Scot
Searching smaller part of an image which is repeated.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Searching smaller part of an image which is repeated.
compare can search a smaller image against a larger image and return an image that is the match score. You just need to be able to find the coordinates of the best matches (by thresholding and getting the coordinates of non-black).
see
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
and the last mandril example at
http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
see
viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
and the last mandril example at
http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
Last edited by fmw42 on 2010-01-26T12:20:53-07:00, edited 1 time in total.
Re: Searching smaller part of an image which is repeated.
Thanks for the feedback. I have been looking at more info on this and have come up with a set of 4 commands that will do the job for me. However I am really strruggling to feed the output of 1st command to the next and so on so that the whole thing can be processed in one go. Alternatively, if someone could give me some guidance on how to put the following commands in a batch file, I would be really grateful.
This is what I want to do:
convert -extract 100x100+0+0 mainimage.jpg 1stpart.jpg
compare -verbose -extract 100x100+0+0 mainimage.jpg 1stpart.jpg null:2>res.txt
convert mainimage.jpg -region 100X100+0+0 -negate -threshold 100 mainimage2.jpg
compare -dissimilarity-threshold 1 -verbose -extract 100x100+425+0 mainimage2.jpg.jpg 1stpart.jpg null:2>>res.txt
Is there a way to execute the above 4 commands in a single batch file? so that results of each comparison are stored in the same file (result.txt)
Thanks again.
This is what I want to do:
convert -extract 100x100+0+0 mainimage.jpg 1stpart.jpg
compare -verbose -extract 100x100+0+0 mainimage.jpg 1stpart.jpg null:2>res.txt
convert mainimage.jpg -region 100X100+0+0 -negate -threshold 100 mainimage2.jpg
compare -dissimilarity-threshold 1 -verbose -extract 100x100+425+0 mainimage2.jpg.jpg 1stpart.jpg null:2>>res.txt
Is there a way to execute the above 4 commands in a single batch file? so that results of each comparison are stored in the same file (result.txt)
Thanks again.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Searching smaller part of an image which is repeated.
Unfortunately compare is rather old and does not recognize some of the options when put into one command, such as:
compare -dissimilarity-threshold 1 zelda3.png \( zelda3.png[64x64+0+0] -negate -threshold 100 \) null:
compare: unrecognized option `-negate' @ compare.c/CompareImageCommand/908.
note that -extract 100x100+0+0 mainimage.jpg is the same as mainimage.jpg[100x100+0+0], except -extract will probably apply to both images the way you have expressed it and perhaps that is what you want to do.
see parenthesis processing at http://www.imagemagick.org/Usage/basics/#parenthesis
I would also recommend specifying -metric rmse.
Also your -threshold 100 is in raw graylevel values in range 0-255 if Q8 IM or 0-65535 if Q16 IM. If you want 100% you must add the percent symbol. Not sure exactly what you are doing here.
Perhaps if you post links to your images and explain what you need, someone can help further.
But unless the IM folks modify compare to know about -negate, your commands cannot be combined into one.
As you have two compares, these will still be two separate commands. I am not sure what you are trying to feed from the second line to the third?
compare -dissimilarity-threshold 1 zelda3.png \( zelda3.png[64x64+0+0] -negate -threshold 100 \) null:
compare: unrecognized option `-negate' @ compare.c/CompareImageCommand/908.
note that -extract 100x100+0+0 mainimage.jpg is the same as mainimage.jpg[100x100+0+0], except -extract will probably apply to both images the way you have expressed it and perhaps that is what you want to do.
see parenthesis processing at http://www.imagemagick.org/Usage/basics/#parenthesis
I would also recommend specifying -metric rmse.
Also your -threshold 100 is in raw graylevel values in range 0-255 if Q8 IM or 0-65535 if Q16 IM. If you want 100% you must add the percent symbol. Not sure exactly what you are doing here.
Perhaps if you post links to your images and explain what you need, someone can help further.
But unless the IM folks modify compare to know about -negate, your commands cannot be combined into one.
As you have two compares, these will still be two separate commands. I am not sure what you are trying to feed from the second line to the third?
Re: Searching smaller part of an image which is repeated.
Hi,
Thank you for taking the time to explain further, I really appreciate that. Thanks also for telling me about the use of brackets, I didn’t know.
Ok, may be if I show an example image, then you could give me some guidance or tell me a better way of doing this.
AS I cannot attach it here, I have uploaded an example picture at the following address:
http://imageshare.web.id/images/ffgmruy52sjd83lyuwr.jpg
I have a frame capture which will have 4, 8 or 16 pictures (usually always similar but sometimes one or more can be different). The example shows that the picture in 4th quadrant (bottom right) is different.
What I want to do is to be able to select 1 (ideally 2 to 3) small area in the picture of quadrant 1, save it and then use it as a reference to find if it exists in pictures of other 3 quadrants. If it matches, then it proves that the pictures in each quadrant are the same and if it differs, then it proves that the picture is not the same in that quadrant.
The reason I used the negate command was because earlier I wanted to just find out that small image in the large one and it was taking too long and always finding the same area. Hence I decided to negate the area that was found in the first search so that the search could continue to quadrant 2, 3 or 4.
However then I felt that in order to speed up the process, it was probably better to give coordinates in each compare command. Having a negate command just shows the areas in each quadrant that the command tried to match (just for reference)
So to summarise, I want to select a small area in the picture in first quadrant (top left), use it as a reference and see if it exists in pictures in the other 3 quadrants and save the results of each compare in a single text file which I will then process later on.
This is what I have come up as a set of commands so far and I want to be able to put them in a batch file and run in one go (instead of typing individual commands).
convert -extract 70x40+30+120 main.png part.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+30+120] part.png null:2>result.txt
convert main.png -region 70x40+30+120 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+297+120] part.png null:2>>result.txt
convert main1.png -region 70x40+297+120 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+30+320] part.png null:2>>result.txt
convert main1.png -region 70x40+30+320 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+297+320] part.png null:2>>result.txt
convert main1.png -region 70x40+297+320 -negate -threshold 100% main1.png
However when I put all these commands in a batch file and execute the batch file Vs when I type each command 1 by 1 using command prompt, the data stored in results.txt file is different and I cant figure out why!
Basically for this example, only the 4th compare should give different value.
Thanks again for taking the time to help me.
Regards
Thank you for taking the time to explain further, I really appreciate that. Thanks also for telling me about the use of brackets, I didn’t know.
Ok, may be if I show an example image, then you could give me some guidance or tell me a better way of doing this.
AS I cannot attach it here, I have uploaded an example picture at the following address:
http://imageshare.web.id/images/ffgmruy52sjd83lyuwr.jpg
I have a frame capture which will have 4, 8 or 16 pictures (usually always similar but sometimes one or more can be different). The example shows that the picture in 4th quadrant (bottom right) is different.
What I want to do is to be able to select 1 (ideally 2 to 3) small area in the picture of quadrant 1, save it and then use it as a reference to find if it exists in pictures of other 3 quadrants. If it matches, then it proves that the pictures in each quadrant are the same and if it differs, then it proves that the picture is not the same in that quadrant.
The reason I used the negate command was because earlier I wanted to just find out that small image in the large one and it was taking too long and always finding the same area. Hence I decided to negate the area that was found in the first search so that the search could continue to quadrant 2, 3 or 4.
However then I felt that in order to speed up the process, it was probably better to give coordinates in each compare command. Having a negate command just shows the areas in each quadrant that the command tried to match (just for reference)
So to summarise, I want to select a small area in the picture in first quadrant (top left), use it as a reference and see if it exists in pictures in the other 3 quadrants and save the results of each compare in a single text file which I will then process later on.
This is what I have come up as a set of commands so far and I want to be able to put them in a batch file and run in one go (instead of typing individual commands).
convert -extract 70x40+30+120 main.png part.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+30+120] part.png null:2>result.txt
convert main.png -region 70x40+30+120 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+297+120] part.png null:2>>result.txt
convert main1.png -region 70x40+297+120 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+30+320] part.png null:2>>result.txt
convert main1.png -region 70x40+30+320 -negate -threshold 100% main1.png
compare -dissimilarity-threshold 0.5 -verbose -metric RMSE main.png[70x40+297+320] part.png null:2>>result.txt
convert main1.png -region 70x40+297+320 -negate -threshold 100% main1.png
However when I put all these commands in a batch file and execute the batch file Vs when I type each command 1 by 1 using command prompt, the data stored in results.txt file is different and I cant figure out why!
Basically for this example, only the 4th compare should give different value.
Thanks again for taking the time to help me.
Regards
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Searching smaller part of an image which is repeated.
I don't follow exactly all you are trying, but I would just do:
compare -dissimilarity-threshold 1 -metric rmse 4houses.jpg 1house.jpg comparison.png
Where I have cropped the full upper left corner house image (without the white border). You can crop a smaller area if you want.
This will produce two images, comparison-0.png and comparison-1.png
If you look at comparison-1.png, it will be white in 3 corners where the best matches occur (relative to the upper left corners of each image). If you read the coordinates of the white areas, that will tell you where the upper left corner of the 1house.jpg image best matches relative to the upper left corner of the 4house.jpg image.

You can even threshold to isolate further
convert comparison-1.png -black-threshold 93% comparison-1_thresh93.gif

convert comparison-1_thresh93.gif txt: |\
> tail -n +2 |\
> tr -cs "A-Za-z0-9\012" " " |\
> sed '/^[0-9]* [0-9]* 0 .*$/d'
4 7 241 241 241 F1F1F1 rgb 241 241 241
5 7 251 251 251 FBFBFB rgb 251 251 251
6 7 244 244 244 F4F4F4 rgb 244 244 244
273 7 239 239 239 EFEFEF rgb 239 239 239
274 7 245 245 245 F5F5F5 grey96
275 7 241 241 241 F1F1F1 rgb 241 241 241
3 206 241 241 241 F1F1F1 rgb 241 241 241
4 206 250 250 250 FAFAFA grey98
5 206 244 244 244 F4F4F4 rgb 244 244 244
The first two values are the x,y coords, the rest are the color values r g b raw values, then hex then rgb
So just pick out the highest values in each cluster (closest to 255) which are at: (5,7), (274,7) and (4,206)
Note, you can do something similar, but faster using -fft if you recompile to HDRI Q16. See http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
compare -dissimilarity-threshold 1 -metric rmse 4houses.jpg 1house.jpg comparison.png
Where I have cropped the full upper left corner house image (without the white border). You can crop a smaller area if you want.
This will produce two images, comparison-0.png and comparison-1.png
If you look at comparison-1.png, it will be white in 3 corners where the best matches occur (relative to the upper left corners of each image). If you read the coordinates of the white areas, that will tell you where the upper left corner of the 1house.jpg image best matches relative to the upper left corner of the 4house.jpg image.

You can even threshold to isolate further
convert comparison-1.png -black-threshold 93% comparison-1_thresh93.gif

convert comparison-1_thresh93.gif txt: |\
> tail -n +2 |\
> tr -cs "A-Za-z0-9\012" " " |\
> sed '/^[0-9]* [0-9]* 0 .*$/d'
4 7 241 241 241 F1F1F1 rgb 241 241 241
5 7 251 251 251 FBFBFB rgb 251 251 251
6 7 244 244 244 F4F4F4 rgb 244 244 244
273 7 239 239 239 EFEFEF rgb 239 239 239
274 7 245 245 245 F5F5F5 grey96
275 7 241 241 241 F1F1F1 rgb 241 241 241
3 206 241 241 241 F1F1F1 rgb 241 241 241
4 206 250 250 250 FAFAFA grey98
5 206 244 244 244 F4F4F4 rgb 244 244 244
The first two values are the x,y coords, the rest are the color values r g b raw values, then hex then rgb
So just pick out the highest values in each cluster (closest to 255) which are at: (5,7), (274,7) and (4,206)
Note, you can do something similar, but faster using -fft if you recompile to HDRI Q16. See http://www.fmwconcepts.com/imagemagick/ ... mcrosscorr
Re: Searching smaller part of an image which is repeated.
Hi, thanks for the feedback, I have tried your method but the comparison-1 file shows all 4 quadrants as white so it is not working. Also I did try this method before but gave up as it was taking too long to compute.
I have one last question where you may be able to help me.
If I execute a command (for example):
>compare -dissimilarity-threshold 1 -verbose -metric RMSE main1.png[70x40+30+120] part1.png null:2>result.txt
I get a text file (result.txt) that contains the following three lines of information:
main1.png[70x40+297+120]=>main1.png PNG 548x408=>70x40 548x408+297+120 8-bit PseudoClass 256c 0.000u 0:00.000
part1.png PNG 70x40 548x408+30+120 8-bit PseudoClass 256c 2.82KiB 0.000u 0:00.000
main1.png[70x40+297+120]=>2 PNG 548x408=>70x40 548x408+297+120 8-bit DirectClass 0.000u 0:00.015
and while executing the same command (as above), my dos prompt shows the following info:
C:\ImageMagick>compare -dissimilarity-threshold 1 -verbose -metric RMSE main1.png[70x40+297+120] part1.png null:2>>result.txt
Image: main1.png
Channel distortion: RMSE
red: 12524.6 (0.191113)
green: 12524.6 (0.191113)
blue: 12524.6 (0.191113)
all: 12524.6 (0.191113)
C:\ImageMagick>
Is there a way to capture the channel distortion values (shown in the dos prompt / terminal) in a single line of text in a text file?
Thanks and Regards
I have one last question where you may be able to help me.
If I execute a command (for example):
>compare -dissimilarity-threshold 1 -verbose -metric RMSE main1.png[70x40+30+120] part1.png null:2>result.txt
I get a text file (result.txt) that contains the following three lines of information:
main1.png[70x40+297+120]=>main1.png PNG 548x408=>70x40 548x408+297+120 8-bit PseudoClass 256c 0.000u 0:00.000
part1.png PNG 70x40 548x408+30+120 8-bit PseudoClass 256c 2.82KiB 0.000u 0:00.000
main1.png[70x40+297+120]=>2 PNG 548x408=>70x40 548x408+297+120 8-bit DirectClass 0.000u 0:00.015
and while executing the same command (as above), my dos prompt shows the following info:
C:\ImageMagick>compare -dissimilarity-threshold 1 -verbose -metric RMSE main1.png[70x40+297+120] part1.png null:2>>result.txt
Image: main1.png
Channel distortion: RMSE
red: 12524.6 (0.191113)
green: 12524.6 (0.191113)
blue: 12524.6 (0.191113)
all: 12524.6 (0.191113)
C:\ImageMagick>
Is there a way to capture the channel distortion values (shown in the dos prompt / terminal) in a single line of text in a text file?
Thanks and Regards