<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > ANA. - Imageworks > Color Table Operations |
These Operations work with the "Color Table", this is a sorted list with all colors in the IR.
This Color-Table is generated using
ANA.AnalyzeColor|0|1
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.
The Col_Bgl Table can be sorted to another Color using:
ANA.Sort_Similar_To|&H26592A|$$MSK
Using the
ANA.AnalyzeColor|0|1
' These are some further commands that can be used after the ANALYZE.
ANA.getcolorcount|0|$$CNT
ANA.getbgcolor|0|$$BGC
you can work with the list entries. For example you can remove colors from the list and the IR.
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.
->
' This Script will remove a green backgroiund
' 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.
The whole process is 1-2 seconds.
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.GetSortedColor|0|$$LOP|$$COL
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.
->
While the artefacts on the white are completely removed, the artefacts in the dark are somehow visible, because we replaced the "dark grey" with black color.
Anyway using this commands you can remove all sorts of dirt and JPG-Artefacts out of pictures.
Speed-Dump of the Script.
The whole process is 1-2 seconds.
With a few changes, you can see in detail how the Script works:
' 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.
You have digitized/scanned some Writing - typically your signature - and want to remove the unused Pixels around, just having White around.
Before: Digitzed Writing After: Cleanup using the SPR
Using this Script the Writing will keep its original Color.
Single, unconnected Dots are removed in Stage 2.
Needs in my example 369 Seconds. Below is a faster Version.
'SPR Script-file: Cleanup Writing
'Purpose:
'Author: Theo Gottwald
'Creation date: 12-28-2021 at 20:11:00
'===========================================================
'#EXE:?path\
'#SPI:ForceWrite
' This Script will clean up the background of a digitized Writing
VAF.$$PIB=?exeloc\ULang5B.png
VAF.$$PIA=?exeloc\ULang3.png
ANA.Load|0|$$PIA
ANA.Show|0!
'ANA.AnalyzeColor|0|1
$$SRC=&HFFF5FF
$$COL=&HFFFFFF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HEADAFE
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HE4F5FF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HC8C0E9
ANA.ReplaceColorT|0|$$SRC|10|$$COL
GSB.Rem_SngPix
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
'===========================================================
' Remove Single unconnceted Dots.
:Rem_SngPix
ANA.GetRes|0|$$XSZ|$$YSZ
FOR.$$YPO|2|($$YSZ-1)
PRT.$$YPO/$$YSZ
FOR.$$XPO|2|($$XSZ-1)
ANA.getpixelcolor|0|$$XPO|$$YPO|$$PIX
JIV.$$PIX=&HFFFFFF|EndLoop
ANA.getpixelcolor|0|($$XPO+1)|$$YPO|$$PAA
ANA.getpixelcolor|0|$$XPO|($$YPO+1)|$$PAB
ANA.getpixelcolor|0|($$XPO-1)|$$YPO|$$PAC
ANA.getpixelcolor|0|$$XPO|($$YPO-1)|$$PAD
ANA.getpixelcolor|0|($$XPO+1)|($$YPO+1)|$$PAE
ANA.getpixelcolor|0|($$XPO-1)|($$YPO+1)|$$PAF
ANA.getpixelcolor|0|($$XPO+1)|($$YPO-1)|$$PAG
ANA.getpixelcolor|0|($$XPO-1)|($$YPO-1)|$$PAH
CAL.$$ERG=($$PAA=&HFFFFFF)+($$PAB=&HFFFFFF)+($$PAC=&HFFFFFF)+($$PAD=&HFFFFFF)+($$PAE=&HFFFFFF)+($$PAF=&HFFFFFF)+($$PAG=&HFFFFFF)+($$PAH=&HFFFFFF)
IVV.$$ERG>5
ANA.Setpixelcolor|0|$$XPO|$$YPO|&HFFFFFF
EIF.
:EndLoop
NEX.
NEX.
RET.
The Speed-Dump was taken after the first round so the Line-execution count may not be accurate.
FASTER VERSION:
Using this Script the Writing will keep its original Color.
Single, unconnected Dots are removed in Stage 2.
This is technically the same Script as above, but twice as fast, as its using new Pixel-Commands
Needs 193 Seconds.
'
'SPR Script-file: RemoveColors
'Purpose:
'Author: Theo Gottwald
'Creation date: 12-28-2021 at 20:11:00
'===========================================================
'#EXE:?path\
'#SPI:ForceWrite
' This Script will clean up the background of a digitized Writing
VAF.$$PIA=?exeloc\ULangK.png
VAF.$$PIB=?exeloc\ULangK1.png
ANA.Load|0|$$PIA
ANA.Show|0!
'ANA.AnalyzeColor|0|1
$$SRC=&HFFF5FF
$$COL=&HFFFFFF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HEADAFE
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HE4F5FF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HC8C0E9
ANA.ReplaceColorT|0|$$SRC|10|$$COL
GSB.Rem_SngPix
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
'===========================================================
:Rem_SngPix
ANA.GetRes|0|$$XSZ|$$YSZ
PRT.Size=$$XSZ,$$YSZ
FOR.$$YPO|2|($$YSZ-1)
PRT.$$YPO/$$YSZ
FOR.$$XPO|2|($$XSZ-1)
ANA.getpixelcolor|0|$$XPO|$$YPO|$$PIX
JIV.$$PIX=&HFFFFFF|EndLoop
ANA.gpc4s|0|$$XPO|$$YPO|$$PAA|$$PAB|$$PAC|$$PAD
ANA.gpc4d|0|$$XPO|$$YPO|$$PAE|$$PAF|$$PAG|$$PAH
CAL.$$ERG=($$PAA=&HFFFFFF)+($$PAB=&HFFFFFF)+($$PAC=&HFFFFFF)+($$PAD=&HFFFFFF)+($$PAE=&HFFFFFF)+($$PAF=&HFFFFFF)+($$PAG=&HFFFFFF)+($$PAH=&HFFFFFF)
IVV.$$ERG>5
ANA.Setpixelcolor|0|$$XPO|$$YPO|&HFFFFFF
EIF.
:EndLoop
NEX.
NEX.
RET.
The Speed-Dump was taken after the first round so the Line-execution count may not be accurate.
FASTER VERSION:
Using this Script the Writing will keep its original Color.
Single, unconnected Dots are removed in Stage 2.
This is technically the same Script as the two Scripts above, but twice as fast, as its using a new Pixel-Command that will read all 8 surrounding Pixels in one Strike.
Needs 101 Seconds.
'
'SPR Script-file: RemoveColors
'Purpose:
'Author: Theo Gottwald
'Creation date: 12-28-2021 at 20:11:00
'===========================================================
'#EXE:?path\
'#SPI:ForceWrite
' This Script will clean up the background of a digitized Writing
VAF.$$PIA=?exeloc\ULangK.png
VAF.$$PIB=?exeloc\ULangK1.png
ANA.Load|0|$$PIA
ANA.Show|0!
'ANA.AnalyzeColor|0|1
$$SRC=&HFFF5FF
$$COL=&HFFFFFF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HEADAFE
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HE4F5FF
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$SRC=&HC8C0E9
ANA.ReplaceColorT|0|$$SRC|10|$$COL
$$TIM=#dtime#
GSB.Rem_SngPix
CAL.$$TMA=#dsince#|i
DBP.Needed: $$TMA Seconds.
DMP.1
MBX.!
ANA.Show|0!
ANA.Save|0|$$PIB
ENR.
'===========================================================
:Rem_SngPix
ANA.GetRes|0|$$XSZ|$$YSZ
PRT.Size=$$XSZ,$$YSZ
FOR.$$YPO|2|($$YSZ-1)
PRT.$$YPO/$$YSZ
FOR.$$XPO|2|($$XSZ-1)
ANA.getpixelcolor|0|$$XPO|$$YPO|$$PIX
JIV.$$PIX=&HFFFFFF|EndLoop
ANA.gpc8|0|$$XPO|$$YPO|$$PAA|$$PAB|$$PAC|$$PAD|$$PAE|$$PAF|$$PAG|$$PAH
CAL.$$ERG=($$PAA=&HFFFFFF)+($$PAB=&HFFFFFF)+($$PAC=&HFFFFFF)+($$PAD=&HFFFFFF)+($$PAE=&HFFFFFF)+($$PAF=&HFFFFFF)+($$PAG=&HFFFFFF)+($$PAH=&HFFFFFF)
IVV.$$ERG>5
ANA.Setpixelcolor|0|$$XPO|$$YPO|&HFFFFFF
EIF.
:EndLoop
NEX.
NEX.
RET.
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.