Image/Pixel-Color Operations

<< Click to Display Table of Contents >>

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

Image/Pixel-Color Operations

ANA.ReplacecolorT

Previous Top Next


MiniRobotLanguage (MRL)

 

ANA.ReplaceColorT

Replace Color with Tolerance - Replace given Colors with another Color directly in the IR, using a Tolerance-Value.

 

 

Intention

 

This Command will directly replace colors in an IR. It will replace Color P2 (and all COlors taht fit to P2 with given Tolerance P3) with Color P4. In Image-Register P1.

This Command is NOT really an Color-Table Operation, as it does not need the Color-Table.

Instead it will directly Replace Color P2 with Color P3 in Image-Register P1 using the Tolerance, which is given in 0-100%.

If Color P2 is prefixed with an ! then the Command will work in a negative mode, means it will replace the Color if it does NOT Fit to the Color P2.

 

In this Script we will replace the Black Color using a Tolerance of 10%, with Green.

 

VAF.$$PIA=?exeloc\Pics\Fux.jpg

ANA.Load|0|$$PIA

ANA.Show|0!

$$SRC=&H000000

$$COL=&H30FF30

ANA.ReplaceColorT|0|$$SRC|10|$$COL

DMP.Speed

ANA.Show|0!

ENR.

 

 

Will bring up this Messagebox.

 

With this picture:

clip0168   clip0170

 

Here is the Speed-Dump:

 

clip0171

 

 

 

 

Syntax

 

ANA.ReplaceColorT|P1|[!]P2[|P3][|P4]

 

Parameter Explanation

 

P1 - Source & Destination Image-Register Number, if omitted 0 is used.

P2 - Color to be replaced with Color in P3.

If Color P2 is prefixed with an ! then the Command will work in a negative mode, means it will replace the Color if it does NOT Fit to the Color P2.

P3 - Color-Tolerance Value between 0-100 which is in Percent. 0 - do not use Tolerance, 100 - Replace any color.
P4 - (opt.) Color that will replace the Color in P2, if omitted &HFFFFFF (White) is used.

 

The Command will leave a 0/1 on the TOS. If the Operation fails, P2 may be "0".

 

Example

 

This Example will show ANA.ReplaceColorT to make a Cleanup of a picture from a social network.

You got that Picture and it has a lot of JPG-Artefacts and the colors are not pure.

The SPR can quickly clean it up.

 

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

' ANA.ReplaceColorT-Sample

' Used to clean up JPG-Artefacts

' Used Sample picture are used for technical reasons and "may or may not be" the opinion of the Script / SPR-Authors.

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

VAF.$$PIA=?exeloc\Pics\Sam1.jpg

NEF.$$PIA

  MBX.File not found.

EIF.

 

ANA.Load|1|$$PIA

ANA.Load|0|$$PIA

ANA.Show|0!

 

'Restore red

$$SRC=&HFF0000

$$COL=&HFF0000

$$TOL=95

ANA.ReplaceColorT|0|$$SRC|$$TOL|$$COL

 

' Restore Blue

$$SRC=&H0000FF

$$COL=$$SRC

$$TOL=90

ANA.ReplaceColorT|0|$$SRC|$$TOL|$$COL

 

'Restore Black

$$SRC=&H0

$$COL=$$SRC

$$TOL=90

ANA.ReplaceColorT|0|$$SRC|$$TOL|$$COL

 

'Restore White

$$SRC=&HFFFFFF

$$COL=$$SRC

$$TOL=90

ANA.ReplaceColorT|0|$$SRC|$$TOL|$$COL

 

ANA.Show|0!

 

' Generate Outline

ANA.cdfxy|0|1|1

ANA.Contrast|1|15000

 

ANA.Invert|1

ANA.Show|1!

 

' IR 2 must not be empty for the MixTar Command

ANA.Copy|0|2

 

' Combine both

ANA.MixTar|1|0|2

DMP.1

ANA.Show|2!

ENR.

 

 

' Below you can see the result of the Operation.

 

 Original Picture with Artefacts                                        First Cleanup - pure Colors                                        Generate Outline to clean up Borders

clip0247   clip0248   clip0249

 

 

 Final Result

clip0250

 

 

 Here is the Speed-Dump of the Operation.

clip0252

Here is the Speed-Dump for the Operation

 

 

This Script will split a Logo into its Color-Components.

 

 

'#EXE:?path\

'#SPI:ForceWrite

 

VAF.$$PIA=?exeloc\KAIF_Logo.png

NEF.$$PIA

  MBX.File not found.

EIF.

 

VAF.$$PIB=?exeloc\KAIF_Separate_

 

' Goldene Farbton

VAR.$$C01=&HB99534

 

' Rosa

VAR.$$C02=&HE5006D

 

' Weiss

VAR.$$C03=&HFFFFFF

 

' Schwarz

VAR.$$C04=&H0

 

' Default Background GRÜN

VAR.$$BGC=&H00FF00

 

' Load Source

VAN.$$BMA=1

ANA.Load|$$BMA|$$PIA

ANA.GetRes|$$BMA|$$XSZ|$$YSZ

'ANA.Show|$$BMA!

 

' Generate P2 für Gold

VAN.$$BMB=2

ANA.Copy|$$BMA|$$BMB

 

' Generate P3 für Rosa

VAN.$$BMC=3

ANA.Copy|$$BMA|$$BMC

 

' Generate P4 für Weiss

VAN.$$BMD=4

ANA.Copy|$$BMA|$$BMD

 

' Generate P5 für Schwarz

VAN.$$BME=5

ANA.Copy|$$BMA|$$BME

 

VAN.$$TOL=4

' Alles ausser Gold ersetzen durch Grün

ANA.ReplaceColorT|$$BMB|!$$C01|$$TOL|$$BGC

ANA.Show|$$BMB!

 

' Alles ausser Rosa ersetzen durch Grün

ANA.ReplaceColorT|$$BMC|!$$C02|$$TOL|$$BGC

 

' Alles ausser Weiss ersetzen durch Grün

ANA.ReplaceColorT|$$BMD|!$$C03|$$TOL|$$BGC

 

' Alles ausser Schwarz ersetzen durch Grün

ANA.ReplaceColorT|$$BME|!$$C04|$$TOL|$$BGC

 

VAN.$$TMB=#dsince#

DBP.$$TMB used

ANA.Show|$$BMB!

ANA.Show|$$BMC!

ANA.Show|$$BMD!

ANA.Show|$$BME!

 

FOR.$$SAV|2|5

  VAR.$$NAM=$$PIBX$$SAV.png

  ANA.Save|$$SAV|$$NAM

NEX.

MBX.Done!

ENR.

 

 

 

 

Remarks

 This Command is really fast and will do its Job in a Second. Of course it will be slower then ANA.ReplaceColorD. This is not really  Color-Table Operation because it does not use the Color-Table.

 

 

Limitations:

 

-

 

 

See also:

 

  ANA.AnalyeColor

  ANA.RemoveIndexColors