<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Pixel-Operation > Image/Pixel-Color Operations |
MiniRobotLanguage (MRL)
ANA.SetPixelColor
Set the Color of a Single Pixel from an Image-Register (IR)
Intention
This command will change the color of a Single Pixel in an IR. While that does not Sound much, it enables you to do unlimited complex Image processing,
Together with other Commands like ANA.GetPixelColor.
For Speed-Reasons, this command will never return anything on the TOS.
1. Remove Green Background on Image using an SPR-Script
In this Sample we will remove the Background on a Image using the SPR.
For this we will read the Pixel, check if its mostly Green, and in that case replace it with the colors taken from another Picture.
Due to the use of a nested Loop going "Line by Line" through all Pixels, it is recommended to start the script in the Editor using "Freerun Mode".
Even then the Script still may use several Minutes to finish. You will see in the Editor-Debug-Window the current Line and the last line.
You will not see the Robot Painting unless the Show command is been called which leads to an Update in the Show-Window.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\Sarah_640.jpg
VAF.$$PIB=?pattern\Mahakala2.png
VAF.$$PIC=?pattern\SarahB_640.png
ANA.Load|0|$$PIA
ANA.Load|1|$$PIB
ANA.Show|0!
ANA.Show|1!
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ/2
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
CAL.$$ERG=($$GRN>&H60)+($$GRN>$$BLU)+($$GRN>$$RED))
IVV.$$ERG>2
ANA.getpixelcolor|1|$$XPO|$$YPO|$$PIX
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
NEX.
NEX.
ANA.Save|0|$$PIC
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
ANA.Show|0!
ENR.
->
This box is filled and it is drawn with inverted background color. The second Part of the Script will draw 2500 random Lines.
The Speed-dump shows that the Robot can read about 40.000 Pixels per second.
2. Color-Processing
In this Sample we will additionally change the Colors.For this we use the two Commands:
ANA.getpixelcolor|1|$$XPO|$$YPO|$$PIX
' This is just for example normally you would use ANA.GetPixelColor_RGB which combines these commands.
ANA.Split_Color_RGB|$$PIX|$$COR|$$COG|$$COB
' We Combine the Colors in away that Blue and Green is exchanged.
ANA.Combine_Color_RGB|$$COG|$$COR|$$COB|$$PIX
' And Set the Pixel
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
And then Paint the Picture.
In the SPR you can use virtually unlimited Graphics Sources to be combined.
.
' Here is the Code.
' On my Computer it uses 5 MinutesProcessing time for a Picture of Medium size in the Editor in "Free-Run Mode".
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\Sarah_640.jpg
VAF.$$PIB=?pattern\Mahakala2.png
ANA.Load|0|$$PIA
ANA.Load|1|$$PIB
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ/2
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
CAL.$$ERG=($$GRN>&H80)+($$GRN>$$BLU)+($$GRN>$$RED))
IVV.$$ERG>2
ANA.getpixelcolor|1|$$XPO|$$YPO|$$PIX
ANA.Split_Color_RGB|$$PIX|$$COR|$$COG|$$COB
ANA.Combine_Color_RGB|$$COG|$$COR|$$COB|$$PIX
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
NEX.
NEX.
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
DMP.1
ANA.Show|0!
ENR.
->
The Script used ~300 Seconds to complete process the picture.
Here is the Speed-Dump:
2. Background or Object-Processing
In this Sample we will just fill the background with white color.
The Script takes 207 Second on my computer.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\Sarah_640.jpg
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ/2
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
CAL.$$ERG=($$GRN>&H60)+($$GRN>$$BLU)+($$GRN>$$RED))
IVV.$$ERG>2
ANA.Setpixelcolor|0|$$XPO|$$YPO|&HFFFFFF
EIF.
NEX.
NEX.
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
DMP.1
ANA.Show|0!
ENR.
EXO.?path\
MBX.!
ENR.
->
This is the result of the operation
Here you can see the Speed-Dump of the Script.
3. Remove Object from Background
In this Sample we will have the Background, and a Person on the Background.
This Script will then Paint the Object yellow.
->
If we just
4. Extract Object from known Background
If we do just change 1 Letter in the Script, we get the inverted result.
The Script will then extract the Person from the Baclground.
Hint: This is a very Simple Script it will only work with Pictures that are uncompressed like "-bmp", or ".png" etc.
Using other Formats you will need to apply a Tolerance.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\SarahB_640.png
VAF.$$PIB=?pattern\Mahakala2.png
VAF.$$PIC=?pattern\SarahR_640.jpg
ANA.Load|0|$$PIA
ANA.Load|1|$$PIB
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ/2
ANA.getpixelcolor|0|$$XPO|$$YPO|$$PCA
ANA.getpixelcolor|1|$$XPO|$$YPO|$$PCB
NVV.$$PCA=$$PCB
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PCA
ELS.
' Paint it Yellow
ANA.Setpixelcolor|0|$$XPO|$$YPO|&HFFFF00
EIF.
NEX.
NEX.
ANA.Save|0|$$PIC
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
DMP.1
ANA.Show|0!
ENR.
->
Here we use a known Background to extract Sarah from the second Picture into the third Picture with yellow background.
Here is the Speed-Dump for this Sample.
Syntax
ANA.SetPixelColor[|P1][|P2][|P3][|P4]
Parameter Explanation
P1 - Source Image-Register number
P2 - X1 - Upper Left Coordinat X-Value
P3 - Y1 - Upper Left Coordinat Y-Value
P4 - Variable for Color-Value.
Example
See above.
Remarks
The ANA.SetPixelColor is optimized for Speed. It will use only about 200 to 336 Ticks. Therefore the Robot could write more then 47000 Pixels per Second. In EXE Mode its even faster then in Free-Run Mode (from Editor).
Limitations:
-
See also:
•