<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Color Table Operations > Image/Pixel-Color Operations |
MiniRobotLanguage (MRL)
ANA.Reduce_Colors
Returns the number of Colors of an IR
Intention
This ccommand will choose 2 similar colors from the color table, calculate the color-mix between these two colors
and then replace both colors with the Mix-Color. This way reducing the number of colors.
This Command needs the ANA.AnalyzeColor Command to count colors in an IR before it will work. It may also need the "Force-Flag" (P2) to be set.
It will also use the Color-Similarity Table, therefore you will need to use the ANA.Sort_Similar_To|$$COL|$$MSK
Command prior using this command.
Using the Tolerance Parameter with another value then 0 will slow down the process, but will also catch a lot more similar colors during the replace.
Somehow using the Tolerance, can be seen as if it is another command, as it will influence the result generally.
Therefore the number of Entries to reduce can be dramatically reduced when using Tolerance.
Using this command is in 5 steps:
1. Use
ANA.AnalyzeColor|0|1
to generate a Color-Table which contains all Colors and number of Pixels.
2. Sort the Color Table with Similarity to the Background Color
' Greenboard-Color, Mask and the color-range that shall be removed must be adjusted per picture
$$COL=&H30FF30
' Colors that do not apply to $$MSK will not be sorted
$$MSK=&HFFFFFF
3. (optional) Use
ANA.GetColorCount|0|$$CNT
to get the total number of colors
4. Use
ANA.Sort_Similar_To|$$COL|$$MSK
to sort the Color-Table by Similarity to the given Color
5. Now call the command to mix/reduce those colors that are most similar to the given color.
' Remove Entries and Paint these Pixels with the Mix-color.
ANA.Reduce_Colors|0|10000|$$CNT|0|-1|2
Here is a Sample-Script.
VAF.$$PIA=?exeloc\Sarah_BG.png
ANA.Load|0|$$PIA
ANA.Show|0!
ANA.AnalyzeColor|0|1
' Greenboard-Color, Mask and the color-range that shall be removed must be adjusted per picture
$$COL=&H30FF30
$$MSK=&HFFFFFF
ANA.GetColorCount|0|$$CNT
DBP.$$CNT
' Sort the Color Table with Similarity to the Background Color
ANA.Sort_Similar_To|$$COL|$$MSK
' Remove Entries and Paint these Pixels white that are Similar to the Background Color
ANA.Reduce_Colors|0|30000|$$CNT|0|-1|2
DMP.6
ANA.Show|0!
ENR.
Reduce Number ofColors in a Picture may result in a Comic-like effect.
Sample Script using Tolerance is very fast due to the low number of Entries to process, yet the colors are reduced by over 13000 Colors in one run:
VAF.$$PIA=?exeloc\Sarah_BG.png
ANA.Load|0|$$PIA
ANA.Show|0!
ANA.AnalyzeColor|0|1
' Greenboard-Color, Mask and the color-range that shall be removed must be adjusted per picture
$$COL=&H30FF30
$$MSK=&HFFFFFF
ANA.GetColorCount|0|$$CNT
DBP.$$CNT
CAL.$$LES=$$CNT-5
ANA.Sort_Similar_To|&H26592A|$$MSK
ANA.Reduce_Colors|0|$$LES|$$CNT|90|-1|2
ANA.GetColorCount|0|$$CNT
DBP.$$CNT
DMP.6
ANA.Show|0!
ENR.
Here we are using a 2 step color-reduction. In the first step we reduces the number of colors from 53870 to 39939.
Speed-Table of this Script.
Syntax
ANA.Reduce_Colors|P1|P2|P3[|P4][|P5][|P6]
Parameter Explanation
P1 - Source and Destination Image-Register Number, if omitted 0 is used.
P2 - Color-Table-Start Index - must be lower then the total number of colors in the Color-Table.
P3 - Color-Table-End Index - In most cases this is the number of Entries in the Color-Table as its given by ANA.GetColorCount|0|$$CNT.
If this number is too high it will automatically be cut down to the maximum. If P3<P2 then these two values will be exchanged.
P4 - 0 or Color-Tolerance-Value. This value is used in the color-replacing part. If >0 the color-replace will also replace
all colors within the Tolerance range of target-color + Tolerance value. This may slow down the process and also lead
to unwanted results if wrongly used.
P5 - if -1 this Parameter is ignored, if 0-8, the command will use a Color-Condition Register (CCR) from 0 to 8 to replace only colors
within this range of the Color-Condition Register.
P6 - 0/1 - 0 - Use Col_Bgl (Backgound-Color Table), 1 - Use Col_Srt (Sorted Colors Table) default is 0
+ 2 Use Color-Ratio Algo for Color-Compare
+ 4 Change color-Mix Mode: 0 - Mix with evaluation by Number Count of Pixels,4 - just take larger color with more pixels
+ 8 Use Inverse CCR (Protect Colors given by the CCR)
+ 16 Use Pixelcount in Mix-Algo, means that colors with more pixels have larger influence on Mixing-Color.
The Command will leave a 0/1 on the TOS. If the Operation fails, TOS will show a "0".
Example
-
Remarks
-
Limitations:
While this command is not a slow command it may still take some seconds to some Minutes to execute, depending on how many colors to remove, the use of Color-Tolerance and the picture-Size.
See also: