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.AnalyzeColor in IR

Previous Top Next


MiniRobotLanguage (MRL)

 

ANA.AnalyzeColor

Analyze Color in an Image-Register (IR) and generate an Color-Table

 

 

Intention

 

These Operations work with the "Color Table", this is a sorted list with all colors in the IR.

In fact there are 2 Color-Tables:

0 - Color-Sort (Col_Srt)  - This table contains the Colors sorted by number of Pixel per Color.
   The Top-Entry is the color with the most Pixels. The bottom Entry is the color with the least number of Pixels.

1 - Color-Background (Col_Bgl) - This table is sorted by similarity to the Color that has most Pixel, which is assumed to be the Background Color.

   Here the Top-Entry contains the Background Color and then any further Entry is sorted by Similarity to this Color.

 

This list can be made using the

 

ANA.AnalyzeColor|0|1

 

The Col_Bgl Table can be sorted to another Color using:

 

ANA.Sort_Similar_To|&H26592A|$$MSK

 

 

Thee are several other commands that will only work if the Color-Table has been updated before.

These are:

 

ANA.GetBGColor

ANA.GetSortedColor

ANA.GetColorCount

ANA.SimilarBGColor

ANA.Sort_Similar

ANA.ShowSimArray

ANA.ShowSortArray

ANA.RemoveIndexColors

ANA.RemoveSortedColors

ANA.Reduce_Colors

ANA.ReplaceColorT

 

 

Using this Script:

 

VAN.$$TIM=#time#

VAF.$$PIA=?exeloc\BTC2.jpg

ANA.Load|0|$$PIA

ANA.AnalyzeColor|0|1

ANA.showsortarray|0

MBX.!

ENR.

 

You will get a listing of the color-table, this may lokk like this:

 

clip0138   clip0139     clip0137          

Start of the Color-Tabel, Entries 0 to 41.                        Second part. As you can see, the Entry for "Black" is on position 40.              End of the Color-Table. Entries up to 1318.

 

Using this commands you can work with the list entries in the color table and do significant improvements in pictures.

Now you can improve the image. All colors are already sorted by Quantity (How many Pixels).

 

You can also get a sort on "Color difference to background". For this you can use:

 

VAN.$$TIM=#time#

VAF.$$PIA=?exeloc\BTC2.jpg

ANA.Load|0|$$PIA

ANA.AnalyzeColor|0|1

ANA.ShowSimArray|0

MBX.!

ENR.

 

 

Then you will get something like this:

 

clip0135                   clip0134

 

In this table the black colors will be "on Top" while the White colors will be "bottom".  For this sort the robot assumes that the color that is mostly in the picture "is the background color".

The he will sort all colors "by difference to the background".  This is the result.

 

Using these tables you can significantly improve pictures with your Script.

 

For example you can remove colors from the list and the IR using:

' this command will remove the given color and replace it with another color.

ANA.removeindexcolors|0|300|$$CNV|0

 

VAN.$$TIM=#time#

VAF.$$PIA=?exeloc\BNB.jpg

'VAF.$$PIA=?exeloc\BTC2.jpg

VAF.$$PIB=?exeloc\V1.png

ANA.Load|0|$$PIA

GSB.Reanalyze

ANA.removeindexcolors|0|300|$$CNV|0

ANA.removeindexcolors|0|$$CNV|$$CNT|-1

GSB.Reanalyze

ANA.removeindexcolors|0|$$CNV|$$CNT|-1

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

DBP.Used Time in Seconds: $$TIM

DMP.1

ANA.Save|0|$$PIB

ANA.Show|0!

ENR.

 

:Reanalyze

ANA.AnalyzeColor|0|1

ANA.getcolorcount|0|$$CNT

ANA.getbgcolor|0|$$BGC

CAL.$$CNV=$$CNT-400

RET.

 

 

 

clip0121         -> clip0125

Original Picture                                                                                                        Picture-Result

 

With a few changes, you can see in detail how the Script works:

 

clip0127

 

' Here we have changed the script a bit to show 

' how the commands paint the colors.

' Green -> would be painted in white

' red -> would be painted in black

VAN.$$TIM=#time#

VAF.$$PIA=?exeloc\BNB.jpg

'VAF.$$PIA=?exeloc\BTC2.jpg

VAF.$$PIB=?exeloc\V1.png

ANA.Load|0|$$PIA

GSB.Reanalyze

ANA.removeindexcolors|0|300|$$CNV|&HFF0000

GSB.Reanalyze

ANA.removeindexcolors|0|$$CNV|($$CNT-20)|&H00FF00

ANA.removeindexcolors|0|($$CNT-20)|$$CNT|&HFFFFFF

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

DBP.Used Time in Seconds: $$TIM

DMP.1

ANA.Save|0|$$PIB

ANA.Show|0!

ENR.

 

:Reanalyze

ANA.AnalyzeColor|0|1

ANA.getcolorcount|0|$$CNT

ANA.getbgcolor|0|$$BGC

CAL.$$CNV=$$CNT-400

RET.

 

clip0128

This is the Speed-Dump of the Script. It uses just few Seconds for the complete run.

 

 

 

 

 

 

 

 

Syntax

 

ANA.AnalyzeColors|P1[|P2]

 

Parameter Explanation

 

P1 - Source Image-Register Number

P2 - 0/1 - Force-Reanalyze-Flag. Default is 0.

    Generally the Analyze command will do nothing if this IR has already been analyzed.

 In case you have made changes to the IR and need a new AnalyzeColors then must set the "Force-Flag" to 1.

 

 

Example

 

Remove Green Background

 

To do this, we first Analyze the Picture to generate the Color-Table.

Secondly we sort the Color Table in a way that its sorted by Similarity with the Background Green Color.

Third we remove the Entries that are similar to the Green Color.

The numbers that are used in detail are a bit of trial and error depending on the picture.

 

clip0140           ->         clip0141

 

' This Script will remove a green background

' using special sorting functions.

' The Script is fast and will only take few seconds

VAF.$$PIA=?exeloc\Sara_Green.jpg

ANA.Load|0|$$PIA

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.RemoveIndexColors|0|39300|$$CNT|&HFFFFFF

ANA.Show|0!

ENR.

 

 

 

clip0142

 

 

Remarks

 

-

 

 

 

Limitations:

 

-

 

See also: