<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Pixel-Operation |
ANA.Pixel-Operations
These Commands work on IR's only.
They can be used to manipulate pictures that you have loaded.
While these Operations can be slow on large pictures, you have a lot of options that you may not have available elsewhere.
Here you can see some Operations that are just Samples.
As the SPR is fast enough even for Pixel-based image-processing, you can do a lot of things. Much easier then with other systems.
And faster then most other Scripting languages.
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 is the Speed-Dump for this Sample.
5. Extract Object from known Background
Using compressed Formats you will need to apply a Tolerance.
We can do this, using the CCD.-Command.
Here we use a Color-Distance of 5%, you can see that sharp borders make trouble.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\SarahB_640.jpg
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
CCD.$$PCA|$$PCB|$$PCR|P
NVV.$$PCR<5
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.
Because we used a ".jpg"-File we still have some artefacts when using a Color-Distance Value of only 5%. In the second Picture we use a value of 10%. This will remove some problems and produce some other.
Thats why you should not use compressed Images for this sort of operations.
Doing Color-Changes/Corrections
In this Sample we will change the Colors in the Picture.
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.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\SarahB_640.jpg
VAF.$$PIC=?pattern\SarahC_640.jpg
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
ANA.New|1|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
CAL.$$RED=$$RED*1.1-70
CAL.$$GRN=$$GRN*1.1-70
CAL.$$BLUE=$$BLU*1.1-70
ANA.SetPixelRGB|1|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
NEX.
NEX.
ANA.Save|1|$$PIC
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
DMP.1
ANA.Show|1!
ENR.
->
This is the Original picture. . The is the picture with the colors changed.
The Speed-dump shows that the Robot can do such correction very fast, yet simple changes on the whole picture can be done faster using other commands.
Picture Mixing
In this Sample we will mix 2 Pictures depending on the relation between Blue and Red.
In the SPR you can use virtually unlimited Graphics Sources to be combined.
.
VAN.$$TIM=#time#
VAF.$$PIA=?pattern\SarahB_640.jpg
VAF.$$PIC=?pattern\SarahC_640.jpg
ANA.Load|0|$$PIA
ANA.Copy|0|1
ANA.Grey|1
ANA.GetRes|0|$$XSZ|$$YSZ
ANA.New|1|$$XSZ|$$YSZ
FOR.$$YPO|1|$$YSZ
DBP.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
IVV.$$BLU>$$RES
ANA.GetPixelRGB|1|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
EIF.
ANA.SetPixelRGB|1|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
NEX.
NEX.
ANA.Save|1|$$PIC
CAL.$$TIM=#time#-$$TIM
DBP.Used Time in Seconds: $$TIM
DMP.1
ANA.Show|1!
ENR.
->->
The Script used ~99 Seconds to complete process the picture. If you change the IVV. to NVV. Command, the result will be the third picture or when using $$BLU and $$GRN the fourth picture.
Here is the Speed-Dump:
Here is another Painting Example:
$$XPA=1600
$$YPA=1200
CAL.$$XPO=$$XPA/2|i
CAL.$$YPO=$$YPA/2|i
$$XSI=100
$$YSI=100
$$XSO=400
$$YSO=300
ANA.New|0|$$XPA|$$YPA
ANA.vgradient|0|&HFF00FF|&H000000
ANA.New|1|$$XPA|$$YPA
ANA.hgradient|1|&H0000FF|&H00FFFF
ANA.Mix|0|1|7
VAN.$$CNT=0
FOR.$$LRA|0|6.28|.0325
CAX.$$SIN=SIN($$LRA)
CAX.$$COS=COS($$LRA)
CAL.$$XPI=$$SIN*$$XSI+$$XPO|i
CAL.$$YPI=$$COS*$$YSI+$$YPO|i
CAL.$$XPJ=$$SIN*$$XSO+$$XPO|i
CAL.$$YPJ=$$COS*$$YSO+$$YPO|i
'ANA.SetPixelColor|1|$$XPI|$$YPI|&HFF0000
ANA.DrawLine|1|$$XPI|$$YPI|$$XPJ|$$YPJ|-1
JIZ.$$XPL|elo
ANA.GetPixelColor|1|$$XPM|$$YPM|$$COA
ANA.GetPixelColor|1|$$XPL|$$YPL|$$COB
ANA.DrawLine|1|$$XPI|$$YPI|$$XPL|$$YPL|$$COA
ANA.DrawLine|1|$$XPJ|$$YPJ|$$XPM|$$YPM|$$COB
ANA.DrawBox|1|$$XPJ|$$YPJ|($$XPJ+15)|($$YPJ+15)|$$COB|1
:elo
VAN.$$XPL=$$XPI
VAN.$$YPL=$$YPI
VAN.$$XPM=$$XPJ
VAN.$$YPM=$$YPJ
IVV.$$CNT>30
ANA.Show|1
$$CNT=0
ELS.
VIC.$$CNT
EIF.
'
NEX.
$$TXT=SPR-Painting-Commands Sample
$$COL=&HFFFFFF
' Backgroundcolor
$$LAA=-2
' Fontname
$$LAC=Segoe UI
$$XP1=320
$$YPI=40
ANA.PrintAt|1|$$TXT|0|$$LAA|($$XP1+2)|($$YP1+2)|39|$$LAC|1
ANA.PrintAt|1|$$TXT|$$COL|$$LAA|$$XP1|$$YP1|39|$$LAC|1
ANA.Show|1!
ENR.
Result of the Painting Script.
Template Script for Pixel-Operations.
VAF.$$PIA=?exeloc\Picture.png
NEF.$$PIA
MBX.No such file.
ENR.
EIF.
ANA.Load|0|$$PIA
ANA.Copy|0|1
ANA.GetRes|0|$$XRE|$$YRE
$$SRC=&HD6E8FF
$$COL=&HFFFFFF
ANA.ReplaceColorT|0|$$SRC|15|$$COL
$$SRC=&HB4E0FF
$$COL=&HFFFFFF
ANA.ReplaceColorT|0|$$SRC|15|$$COL
$$SRC=&H59362C
$$COL=&H29369B
ANA.ReplaceColorT|0|$$SRC|15|$$COL
$$SRC=&H78514B
$$COL=&H00007E
ANA.ReplaceColorT|0|$$SRC|65|$$COL
FOR.$$LOX|1|$$XRE
FOR.$$LOY|1|$$YRE
ANA.getpixelcolor|1|$$LOX|$$LOY|$$PIB
ANA.getpixelcolor|1|($$LOX+1)|$$LOY|$$PIA
ANA.getpixelcolor|1|($$LOX-1)|$$LOY|$$PIC
ANA.getpixelcolor|1|$$LOX|($$LOY-1)|$$PYA
ANA.getpixelcolor|1|$$LOX|($$LOY+1)|$$PYC
IVV.$$PIA=&HFFFFFF
IVV.$$PIB!$HFFFFFF
IVV.$$PIC=&HFFFFFF
ANA.Setpixelcolor|1|$$LOX|$$LOY|&HFFFFFF
EIF.
EIF.
EIF.
IVV.$$PYA=&HFFFFFF
IVV.$$PIB!$HFFFFFF
IVV.$$PYC=&HFFFFFF
ANA.Setpixelcolor|1|$$LOX|$$LOY|&HFFFFFF
EIF.
EIF.
EIF.
NEX.
NEX.
GSB.Save|0
ENR.
'===========================================================
:Save
$$NUM=§§_01
RND.0|999999|$$RND
FMT.$$RND|000000
$$PAT=?exeloc\Save_$$RND.png
IEF.$$PAT
GTO.Save
EIF.
ANA.Save|$$NUM|$$PAT
ANA.Show|$$NUM!
RET.
'===========================================================