Page 1 of 1
Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T03:04:13-07:00
by troller
Hello all.
I am trying to figure out a quick way to do this:
I have a series of images (1920x1080 pixels each) that contain a set of green, yellow and sometimes also red dots. Each dot is a circle with a diameter of roughly 15-16 pixels. I would like to write a formula/script that does this:
1) It looks if in the image there is at least one red pixel (red with a certain fuzz factor, since they are jpg compressed and it is not always pure red)
2) If there is, then it creates a big red cross and position it in a given location on the same image. If there are no red pixels at all, then it does nothing.
How can I do this?
Thanks a lot!
Andrea
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T03:27:57-07:00
by snibgo
1) You could make non-red pixels transparent, and see if "sparse-colors:" emits anything. If it does, you have at least one red pixel.
Code: Select all
convert in.jpg -fuzz 15% +transparent red sparse-color:
2) You could use "-draw".
The rest is merely scripting.
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T03:41:27-07:00
by troller
snibgo wrote:1) You could make non-red pixels transparent, and see if "sparse-colors:" emits anything. If it does, you have at least one red pixel.
Code: Select all
convert in.jpg -fuzz 15% +transparent red sparse-color:
2) You could use "-draw".
The rest is merely scripting.
Thanks but how do I automate that I create the red cross if the sparse-color tells me that there is at least one red pixel?
thanks
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T04:18:18-07:00
by snibgo
Your script would test whether sparse-colour produced any output. If there is output, the script would execute the convert command that draws the cross.
If you need help writing the script, it might be useful if you said what language you would use. But this is an ImageMagick forum, not a scripting forum. There are many sites where you can learn how to script.
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T04:50:28-07:00
by troller
I am using Windows, Batch file.
Yes actually I'm not very good at all in scripting and compiling.
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T05:31:36-07:00
by troller
What I have now very simply is this:
Code: Select all
composite -geometry +1325+30 scartologo.bmp Screenshot.jpg Final.jpg
The pictures "scartologo" and "screenshot" are already saved in the folder. I just need to create a
trigger to do this line; otherwise, this line is just skipped in the overall program.
Thanks!
Andrea
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-03T15:48:51-07:00
by snibgo
Code: Select all
for /F "usebackq" %%L in (`convert ^
Screenshot.jpg -fuzz 15%% +transparent red ^
sparse-color:`) do set RED_PX=%%L
if not "RED_PX"=="" composite ^
-geometry +1325+30 scartologo.bmp Screenshot.jpg Final.jpg
Adjust the 15%% as required.
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-05T09:01:07-07:00
by troller
Thanks,
but it seems that no matter what color I choose as condition, it will always run the command -> merge the two pictures, even if I chose a color that does not even exist in the picture.
Andrea
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-05T09:59:10-07:00
by snibgo
What version of IM are you using?
Please paste the exact commands you are using. Please put a sample input image somewhere like dropbox.com and paste the URL here.
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-06T08:17:08-07:00
by troller
I am using IM 6.8.8-9 Q16 64 bit on Windows 7.
The code I am using now is:
Code: Select all
:loop
@echo off
cd "C:\4300 Results\Screenshot\"
for /F "usebackq" %%L in (`convert ^
Screenshot.jpg -fuzz 1%% +transparent blue ^
sparse-color:`) do set RED_PX=%%L
if not "RED_PX"=="" composite ^
-geometry +94+36 "C:\4300 Results\Screenshot\IM-ACo screenshot script\scartologo1.bmp" Screenshot.jpg Screenshot2.jpg
timeout /t 10
goto loop
where as you can see I am looping the command every 10 seconds and the 2 pictures to be merged are in two different folders; the "screenshot.jpg" picture is automatically updated every 5-6 seconds from another source program and saved in the folder...
At this link you can download both screenshot.jpg and scartologo1.bmp. :
http://we.tl/j3A0LW8N5C
Note that in the script above I purposely wrote +transparent blue with 1% fuzz, and even if there is no blue color on the screenshot.jpg, it would still output the red cross over...
thanks for help!!!
Andrea
Re: Formula to insert a red cross if there are color pixels
Posted: 2014-10-06T12:09:33-07:00
by snibgo
Sorry. In my code, I omitted the % signs in ...
... should be ...