Formula to insert a red cross if there are color pixels
Formula to insert a red cross if there are color pixels
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
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Formula to insert a red cross if there are color pixels
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.
2) You could use "-draw".
The rest is merely scripting.
Code: Select all
convert in.jpg -fuzz 15% +transparent red sparse-color:
The rest is merely scripting.
snibgo's IM pages: im.snibgo.com
Re: Formula to insert a red cross if there are color pixels
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?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.2) You could use "-draw".Code: Select all
convert in.jpg -fuzz 15% +transparent red sparse-color:
The rest is merely scripting.
thanks
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Formula to insert a red cross if there are color pixels
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.
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.
snibgo's IM pages: im.snibgo.com
Re: Formula to insert a red cross if there are color pixels
I am using Windows, Batch file.
Yes actually I'm not very good at all in scripting and compiling.
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
What I have now very simply is this:
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
Code: Select all
composite -geometry +1325+30 scartologo.bmp Screenshot.jpg Final.jpg
Thanks!
Andrea
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Formula to insert a red cross if there are color pixels
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
snibgo's IM pages: im.snibgo.com
Re: Formula to insert a red cross if there are color pixels
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
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Formula to insert a red cross if there are color pixels
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.
Please paste the exact commands you are using. Please put a sample input image somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
Re: Formula to insert a red cross if there are color pixels
I am using IM 6.8.8-9 Q16 64 bit on Windows 7.
The code I am using now is:
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
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
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Formula to insert a red cross if there are color pixels
Sorry. In my code, I omitted the % signs in ...
... should be ...
Code: Select all
if not "RED_PX"=="" composite ^
Code: Select all
if not "%RED_PX%"=="" composite ^
snibgo's IM pages: im.snibgo.com