Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Image/Pixel-Color Operations > Additional Commands >

Image/Pixel-Color Operations

CCD. - Calculate Color Distance

Previous Top Next


MiniRobotLanguage (MRL)

 

CCD. Command

Calculate Color Distance

 

 

Intention

 

This command will tell you, how similar two colors are. For this the command calculates the "Color-Distance" between these two given colors.

There are several Modes of operation for the CCD.-Command, all these may give different results. You may use 3.4 System-Colors as parameter with this command.

 

1. Color Distance on TOS

 

' White Color

$$COA=&HFFFFFF

' Black Color

$$COB=&H000000

CCD.$$COA|$$COB

DBP.$$000

ENR.

 

Result is: 441673 which is the maximum Color Distance in this mode.

 

 

2. Color Distance to Variable.

 

This is exactly the same, just that we put the result into a variable instead of using the stack.

 

$$COA=&HFFFFFF

$$COB=&H000000

CCD.$$COA|$$COB|$$COD

DBP.$$COD

ENR.

 

 

3. Color Distance in IEE-FP-Format

 

This is exactly the same, just that we put the result has a maximum precision.

 

$$COA=&HFFFFFF

$$COB=&H000000

CCD.$$COA|$$COB|$$COD|F

DBP.$$COD

ENR.

 

Result is: 441.67295593006371

 

Here are some other results:

 

&HFFFFFF/&HFFFFFE = 1

&HFFFFFF/&HFFFEFE = 1.41421356237309505

 

This way you can really get the most accurate color distance between two colors.

 

4. Color Distance as percentage from 0% to 100%.

 

This is exactly the same, just that we get the result as a percentage from 0% to 100%.

Fractions will not be calculated, as they will also not be used in places where such a color tolerance can be specified.

 

$$COA=&HFFFFFF

$$COA=&HFFFFFF

$$COB=&H000000

CCD.$$COA|$$COB|$$COD|P

DBP.$$COD

ENR.

 

Result is: 100

 

 

1. Extract Object from known Background using CCD. as a Tolerance-Factor

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.

 

Maha_01RemoveBG_03         ->clip0007   clip0009
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.

 

clip0008

 

 

 

 

Syntax

 

CCD.P1|P2[|P3][|P4]

 

Parameter Explanation

 

P1 - Color A to calculate the distance from.

    You can use 3.4 System-Colors values like S1,S2 etc.

 

P2 - Color B to calculate the distance to

    You can use 3.4 System-Colors values like S1,S2 etc.

 

P3 - (optional) - Variable for the result. If omitted, TOS is used.

 

P4 - (optional) - Can be omitted then a integer result is delivered,

   which is in the range from 0 to 441673.

 P - Calculates a percentage result between 0 and 100

 F - Calculates a Extended precision result. This is

     between 0 and 441.67295593006371  

 

 

 

 

Example

 

'***********************************

' CCD.-Sample

'***********************************

'

$$COA=&HFFFFFF

$$COB=&H0

CCD.$$COA|$$COB|$$COD|P

DBP.$$COD

ENR.

 

 

 

Remarks

CCD. is a speed-optimized Operation that will only use 180 to 200 Ticks.

 

 

 

 

Limitations:

 

-

 

 

 

See also:

 

    CAL. - mathematical CALculation

    IDP. / NDP. - If desktop dpi Setting

    IPC. / NPC. - If-Pixel-Colour

    GPC. - Get-Pixel-Colour

    ! UCV. - Undercover Graphics