Page 1 of 1
Image change watcher
Posted: 2013-06-06T12:54:27-07:00
by miezazize
Hi everyone,
Im really a newbie and want to make a little CMD script for the following (im on windows):
I have an image that is refreshed every minute,
and when the color of a certain area in the image changes radically
for example: it was white/grey on the previous picture, but it is rather black on the new one
then I want to execute a program and so on...
do you have an idea how to do this?
and what if I want this with a color like r/g/b?
Thanks in advance
Re: Image change watcher
Posted: 2013-06-06T13:01:00-07:00
by GreenKoopa
ImageMagick could do the comparing of the current and previous images. Your script would have to provide those two images, and your script would execute whatever you needed based on IM's result.
ImageMagick provides a number of
program interfaces, or for a simple need it can be more convenient to call the
command-line utilities directly.
Re: Image change watcher
Posted: 2013-06-07T00:09:11-07:00
by miezazize
Okay, I learned how to use "convert -crop", so now I can produce the needed part of the image.
But many other binaries have this "-crop" function, does it mean that all of them can do this? And do I need to create cropped images from the two big images to compare the needed parts separately, or can I use "-crop" with other functions like format, etc. so that the program will display results for only that part of the images?
I just want to get a number that shows how much rather black or rather white is in the image, or count how many pixels are rather red/green/blue, so later I could just compare these numbers with the results from the newer image, and If there is absolutely more red, green and blue, than the newer image must be more white... perhaps this would be a solution?
Sorry, I'm just learning english, and don't know the meaning of very many special words (mostly things in connection with maths), so It s hard for me to understand some explanations. So could you show a sample code or something, if possible?
The task is that, I want to determine if the image is like this:
http://imageshack.us/photo/my-images/23/withoutt.jpg/
Or more like this:
http://imageshack.us/photo/my-images/580/withb.jpg/
Re: Image change watcher
Posted: 2013-06-07T10:18:48-07:00
by GreenKoopa
Is it always the same area of the image that is changed, or must we search for a lightened spot? Searches can be very easy or very difficult depending on your needs.
You could output a
histogram to see the color distribution of the image. To make it simpler, you could output a histogram of only the brightness (or redness or other quality). Depending on your need, you can go much simpler. If you have hard values for "rather black" and "rather white" you can get a count of values past this threshold. You could generate a single value of the overall brightness (or other qualities) of the image. All of these options are reasonably easy. Do you know which of these would be helpful?
Re: Image change watcher
Posted: 2013-06-07T23:27:05-07:00
by miezazize
It is always the same area that I want to check.
Brightness values must be the easiest way. So how can I get it in a single value for that area?
Color is anyway not too important, but if I'm curious, how can I get redness or others? As far as I know, histogram is like a list of colors and their count, but Is there a way to get only the count value for a certain color?
Re: Image change watcher
Posted: 2013-06-08T01:19:16-07:00
by GreenKoopa
Okay, I'll focus on outputting a single number. Here is the mean value of an area set by -crop.
Code: Select all
> convert withb.jpg -crop 90x40+600+70 -print "%[mean]" null:
48070.4
> convert withoutt.jpg -crop 90x40+600+70 -print "%[mean]" null:
29741.7
You are given a value between 0 and QuantumRange (255 for 8-bit, 65535 for 16-bit). Alternatively you can output a number between 0 and 1
Code: Select all
> convert withb.jpg -crop 90x40+600+70 -print "%[fx:mean]" null:
0.733507
> convert withoutt.jpg -crop 90x40+600+70 -print "%[fx:mean]" null:
0.453829
Of course you can output information other than the mean. The first example uses simple
Escapes. The second example uses the more powerful
Fx Expressions.
You can limit processing to the red channel. For escapes, add -channel R before the -print. For Fx Expressions, use %[fx:mean.r]
You can use -colorspace if you need statistics about hue, saturation, lightness, brightness, etc.
Processing before outputting statistics opens the door to much more. Earlier I showed how -crop limits the area examined. Here I use -threshold to output the proportion of pixels above 51% in value (assumes grayscale image).
Code: Select all
> convert withb.jpg -crop 90x40+600+70 -threshold 51% -print "%[fx:mean]" null:
0.999445
> convert withoutt.jpg -crop 90x40+600+70 -threshold 51% -print "%[fx:mean]" null:
0
> convert withb.jpg -threshold 51% -print "%[fx:mean]" null:
0.0523618
> convert withoutt.jpg -threshold 51% -print "%[fx:mean]" null:
0.00877894
So not only can IM detect a spot exists, it is approximately 5% of the total area.
If you are in a Windows batch file, remember to replace every % with %%
Re: Image change watcher
Posted: 2013-06-09T08:02:03-07:00
by miezazize
This is what I have been searching for, thank you very much, works fine
Re: Image change watcher
Posted: 2013-06-30T22:24:36-07:00
by anthony
I do a 'image changed' check when I do IM Example Updates.
The command is...
error=`compare -dissimilarity-threshold 50% \
-metric PAE $new $old null: 2>&1`
Where error is how much of the image has changed. Not this is only the peak of the absolute error difference.
meaning the largest single pixel change in the image.
With the above I case minor changes as less than 5000 in a IM Q16.