<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > Image/Pixel-Color Operations |
Smart Package Robot 's Pixel Pixel Processing Operations
Pixel-Processing Operations are often not really fast but can save you a lot of work.
Using the Getpixel and SetPixel, you can do amazing Pixel-Operations.
Important:
Due to Speed Optimizations, the SPR is unable to STOP immediately while he is in optimzied Pixel-Processing Operations.
Therefore the SPR will not stop unless he is done with the Command. In such case you can just use the Cleanup-Button to "Kill all Robots".
Here is a simple Example that can be adjusted for multiple purposes.
It will remove unwanted Artefacts - for example here a watermark - from a picture.
->
And here is the Script:
Version 1: "Pixel by Pixel".
The structure of this Script is easy to understand and it can be modified for any case.
VAN.$$TIM=#time#
VAF.$$PIA=?exeloc\Igorslab.png
VAF.$$PIB=?exeloc\V1.png
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|0|$$YSZ
PRT.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ
ANA.GetPixelRGB|0|$$XPO|$$YPO|$$RED|$$GRN|$$BLU
CAL.$$ERG=($$RED>&D0)+($$BLU>&HD0)+($$GRN>&HD0)
IVV.$$ERG>2
'ANA.getpixelcolor|1|$$XPO|$$YPO|$$PIX
$$PIX=&HFFFFFF
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
CAL.$$ERG=($$RED>&HC0)+($$RED<&HF0)+($$GRN>&HA9)+($$GRN<&HE0)+($$BLU>&HB9)+($$BLU<&HE9)
IVV.$$ERG>5
$$PIX=&HFFFFFF
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
NEX.
NEX.
CAL.$$TIM=#time#-$$TIM
MBX.Used Time in Seconds: $$TIM
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
Depending on the number of Pixels, the Script will take quite some time ( 20 Minutes for a picture of size 1900x1700) due to the use of not optimized commands.
Therefore this method is perfectly flexible for any automated picture processing need.
Version using ICC.
You can do the same process using the specialized command ICC.:this way its twice as fast. The Script below uses only 8 Minutes compared to the Script above that uses 20 Minutes for a 1900x1700 ( 3 MP) Picture Process.
Note that using the "0" in the RMax-Field will set R/G/BMax to &HFF.
VAN.$$TIM=#time#
VAF.$$PIA=?exeloc\Igorslab.png
VAF.$$PIB=?exeloc\V1.png
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
$$PIX=&HFFFFFF
FOR.$$YPO|0|$$YSZ
PRT.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ
ICC.0|$$XPO|$$YPO|&HD0|0|&HD0|0|&HD0|0
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
ICC.0|$$XPO|$$YPO|&HC0|&HF0|&HA9|&HE0|&HB9|&HE9
ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX
EIF.
NEX.
NEX.
CAL.$$TIM=#time#-$$TIM
MBX.Used Time in Seconds: $$TIM
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
There is another command that can be used to speed up this process that is RIC..
Using this command, will shorten the code more and make it even faster.
While the result is the same, this Script will only take 6 Minutes to process the same picture.
Version using RIC.
VAN.$$TIM=#time#
VAF.$$PIA=?exeloc\Igorslab.png
VAF.$$PIB=?exeloc\V1.png
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
$$PIX=&HFFFFFF
FOR.$$YPO|0|$$YSZ
PRT.$$YPO/$$YSZ
FOR.$$XPO|1|$$XSZ
RIC.0|$$XPO|$$YPO|&HD0|0|&HD0|0|&HD0|0|$$PIX
RIC.0|$$XPO|$$YPO|&HC0|&HF0|&HA9|&HE0|&HB9|&HE9|$$PIX
NEX.
NEX.
CAL.$$TIM=#time#-$$TIM
MBX.Used Time in Seconds: $$TIM
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
Optimized Version using RCC.
There is another command that can be used to speed up this process that is RCC..
As RCC. will internally process the complete Picture, it will do the Job in 1-2 Seconds.
VAN.$$TIM=#time#
VAF.$$PIA=?exeloc\Igorslab.png
VAF.$$PIB=?exeloc\V1.png
ANA.Load|0|$$PIA
ANA.GetRes|0|$$XSZ|$$YSZ
$$PIX=&HFFFFFF
RCC.0|&HD0|0|&HD0|0|&HD0|0|$$PIX
RCC.0|&HC0|&HF0|&HA9|&HE0|&HB9|&HE9|$$PIX
CAL.$$TIM=#time#-$$TIM
DMP.1
MBX.Used Time in Seconds: $$TIM
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
Alternatively you can choose this Setup.
Quickly remove a watermark from a b/w picture.
VAN.$$TIM=#time#
VAF.$$PIA=?exeloc\Igorslab.png
VAF.$$PIB=?exeloc\V1.png
ANA.Load|0|$$PIA
ANA.TriColor|0|&H90FFFF
ANA.bw|0|760
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
-> ->
->
' Turning a b/w picture into a 3D-Logo
$$PAB=?exeloc\Pics\P3.jpg
$$BOR=4
CAL.$$BOB=$$BOR/2
IEF.$$PAB
ANA.Load|1|$$PAB
'ANA.Show|1!
ELS.
MBX.File does not exist:$crlf$$$PAT
EIF.
ANA.GetRes|1|$$XPO|$$YPO
CAL.$$XPA=$$XPO+$$BOR
CAL.$$YPA=$$YPO+$$BOR
' Make a Resized Version of P3
ANA.New|2|$$XPA|$$YPA|1
ANA.New|3|$$XPA|$$YPA
' Now mix Shiftzed and Resized Version
ANA.bsh|2|1|$$BOB|$$BOB|1
ANA.Invert|1
ANA.bw|2|600
ANA.Show|1!
ANA.Show|2!
ANA.Logic|3|1|2|A XOR B|RGB
ANA.Show|3!
ANA.Invert|3
ANA.Show|3!
ENR.
' Changing the first two lines like this, will produce the second picture:
$$BOR=2
CAL.$$BOB=$$BOR