- I'd be interested as to whether there are any other common algorithms for this, that use different approaches, or perhaps any Gdip methods that 'simplify' colours/images by replacing colours with nearby colours.
- Also, I'd be interested if anybody uses something like this regularly, or might find this script or a similar script useful. Thanks.
Code: Select all
q:: ;find nearest colour (sum of R/G/B differences, or, sum of squares of R/G/B differences)
;colour list from:
;Progress/SplashImage
;https://autohotkey.com/docs/commands/Progress.htm
vListRGB := "Black=000000,Silver=C0C0C0,Gray=808080,White=FFFFFF,Maroon=800000,Red=FF0000,Purple=800080,Fuchsia=FF00FF,Green=008000,Lime=00FF00,Olive=808000,Yellow=FFFF00,Navy=000080,Blue=0000FF,Teal=008080,Aqua=00FFFF"
oArray := Object(StrSplit(vListRGB, ["=",","])*)
vPfx := !!SubStr(1,0) ? "O)" : "" ;two-way compatibility
for vKey, vValue in oArray
{
RegExMatch(vValue, vPfx "(..)(..)(..)", oMatch1)
vList := ""
for vKey2, vValue2 in oArray
{
if (vValue = vValue2)
continue
RegExMatch(vValue2, vPfx "(..)(..)(..)", oMatch2)
vDiff := 0
Loop, 3
vDiff += Abs(Format("{:i}", "0x" oMatch1[A_Index])-Format("{:i}", "0x" oMatch2[A_Index])) ;raw difference
;vDiff += (Format("{:i}", "0x" oMatch1[A_Index])-Format("{:i}", "0x" oMatch2[A_Index]))**2 ;difference squared
;vDiff := Round(Sqrt(vDiff)) ;difference squared
if (vList = "") || (vDiff < vMin)
vMin := vDiff, vList := vDiff "|" vKey2 " " vValue2
else if (vDiff = vMin)
vList .= "," vKey2 " " vValue2
}
vOutput .= vKey " " vValue "|" vList "`r`n"
}
Clipboard := vOutput
MsgBox, % "done"
return
;==================================================
;RESULTS:
;find nearest colour (sum of R/G/B differences)
Aqua 00FFFF|254|Teal 008080
Black 000000|128|Green 008000,Maroon 800000,Navy 000080
Blue 0000FF|127|Navy 000080
Fuchsia FF00FF|254|Purple 800080
Gray 808080|128|Olive 808000,Purple 800080,Teal 008080
Green 008000|127|Lime 00FF00
Lime 00FF00|127|Green 008000
Maroon 800000|127|Red FF0000
Navy 000080|127|Blue 0000FF
Olive 808000|128|Gray 808080,Green 008000,Maroon 800000
Purple 800080|128|Gray 808080,Maroon 800000,Navy 000080
Red FF0000|127|Maroon 800000
Silver C0C0C0|189|White FFFFFF
Teal 008080|128|Gray 808080,Green 008000,Navy 000080
White FFFFFF|189|Silver C0C0C0
Yellow FFFF00|254|Olive 808000
==================================================
;find nearest colour (sum of squares of R/G/B differences)
Aqua 00FFFF|32258|Teal 008080
Black 000000|16384|Green 008000,Maroon 800000,Navy 000080
Blue 0000FF|16129|Navy 000080
Fuchsia FF00FF|32258|Purple 800080
Gray 808080|12288|Silver C0C0C0
Green 008000|16129|Lime 00FF00
Lime 00FF00|16129|Green 008000
Maroon 800000|16129|Red FF0000
Navy 000080|16129|Blue 0000FF
Olive 808000|16384|Gray 808080,Green 008000,Maroon 800000
Purple 800080|16384|Gray 808080,Maroon 800000,Navy 000080
Red FF0000|16129|Maroon 800000
Silver C0C0C0|11907|White FFFFFF
Teal 008080|16384|Gray 808080,Green 008000,Navy 000080
White FFFFFF|11907|Silver C0C0C0
Yellow FFFF00|32258|Olive 808000
;==================================================
;find nearest colour (square root of: sum of squares of R/G/B differences)
Aqua 00FFFF|180|Teal 008080
Black 000000|128|Green 008000,Maroon 800000,Navy 000080
Blue 0000FF|127|Navy 000080
Fuchsia FF00FF|180|Purple 800080
Gray 808080|111|Silver C0C0C0
Green 008000|127|Lime 00FF00
Lime 00FF00|127|Green 008000
Maroon 800000|127|Red FF0000
Navy 000080|127|Blue 0000FF
Olive 808000|128|Gray 808080,Green 008000,Maroon 800000
Purple 800080|128|Gray 808080,Maroon 800000,Navy 000080
Red FF0000|127|Maroon 800000
Silver C0C0C0|109|White FFFFFF
Teal 008080|128|Gray 808080,Green 008000,Navy 000080
White FFFFFF|109|Silver C0C0C0
Yellow FFFF00|180|Olive 808000
;==================================================
Gdip: image binary data to hex string for OCR - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=35339
GDI_GrayscaleBitmap() - Converts GDI bitmap to Greyscale - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/8279 ... greyscale/