Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Pixel-Operation >

Image/Pixel-Color Operations

ANA.GetPixelRGB - Get the Color as RGB of a Single Pixel of an IR

Previous Top Next


MiniRobotLanguage (MRL)

 

ANA.GetPixelRGB

Get the Color of a Single Pixel from an Image-Register (IR) in three values for Red, Green and Blue

 

 

Intention

 

This command will read the color of a Single Pixel in an IR. It will return the Color in its Red, Green and Blue Component.

As we use 24-bit Colors, the returned color will be 0.255 (0-&HFF) for each Component Red, Green and Blue.

 

You can use this command together with other Commands like ANA.SetPixelRGB.

 

1. Remove Green Background on a picture using an SPR-Script

In this Sample we will remove the Background on a picture using the SPR.

For this we will read the Pixel, check if its mostly Green, and in that case replace

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". Freerun

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.

 

Editordbw

 

  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

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>&H80)+($$GRN>$$BLU)+($$GRN>$$RED))

    IVV.$$ERG>2

      ANA.getpixelcolor|1|$$XPO|$$YPO|$$PIX

      ANA.Setpixelcolor|0|$$XPO|$$YPO|$$PIX

    EIF.    

  NEX.

NEX.

CAL.$$TIM=#time#-$$TIM

DBP.Used Time in Seconds: $$TIM

ANA.Show|0!

ENR.

 

 

 

Sara_Green     Maha_01RemoveBG_03

This box is filled and it is drawn with inverted background color.                                                 The second Part of the Script will draw 2500 random Lines.

 

Speeddump gpc

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.

 

Sara_Green     Maha_01Sarah_3

The Script used 306 Seconds to complete process the picture.

 

 

Here is the Speed-Dump:

SPD1

 

 

 

 

Syntax

 

ANA.GetPixelRGB[|P1][|P2][|P3][|P4][|P5][|P6]

 

Parameter Explanation

 

P1 - Source Image-Register number

P2 - X1 - Upper Left Coordinat X-Value

P3 - Y1 - Upper Left Coordinat Y-Value

P4 - opt. Variable for returned Color-Value RED. If omitted TOS is used.

P5 - opt. Variable for returned Color-Value GREEN. If omitted TOS is used.

P6 - opt. Variable for returned Color-Value BLUE. If omitted TOS is used.

 

The color values will always be in the range between 0-255. This is  Hexadacimal: 0 - &HFF.

 

 

 

Example

 

See above.

 

 

 

 

Remarks

The ANA.GetPixelRGB is optimized for Speed. It will use only about 400 to 600 Ticks. Therefore the Robot could read more then 30000 Pixels per Second.

 

 

 

Limitations:

 

-

 

 

See also: