This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Emma's profile picture

Smart 2 Color Detection and Application

Started by Emma, 01 June 2016 - 07:21 PM
Emma #1
Posted 01 June 2016 - 09:21 PM
Hey guys, so I've been working on some stuff with the new sub-level pixel characters, (specifically using oli414's canvas API)

This is what I have so far:
Spoiler

So as you can see, it's going pretty well, I am able to load actual .bmp files and draw them with relatively high resolution, but with bmps with high color density it gets very blocky as you can see in the second image.

I have determined the problem to come from the way I crudely modified the canvas api to allow setting background and foreground colors using the characters (as you can only have 2 colors per "pixel group" of 2x3). As each pixel would be processed, it's background/foreground colors would overwrite the other pixels in it's block. I would like to do this in a more efficient way so that the 2 most used colors (with some averaging algorithm or something like that) are used as the background and foreground colors. However, I am not sure where to start with this, so any help is very much appreciated. My modified version of oli414's canvas api is here: x8yzegaC
Edited on 01 June 2016 - 07:32 PM
Bomb Bloke #2
Posted 02 June 2016 - 02:34 AM
There are surely better ways to go about it, but my method is to list out all the colours that "should" exist in the current 2x3 space, along with how often they appear. Take whichever colour has the lowest appearance rate, replace with the colour in the list that's most like it (using a lookup chart to get "best matches"), and then iterate until less than three colours remain. Fast with acceptable results, or so I like to think.

(Funny story: a bug in my code meant that it pretty much picked colours from the list randomly. That's since been fixed, but all the screenshots in that linked thread were taken while it was in effect…)

More complex systems might involve spotting high concentrations of eg black with white and replacing them with grey (even if grey doesn't exist in the original image). Some coders have added dithering into the mix (leading to more chaotic images with an illusion of better colour depth), though they haven't relied upon Lua to do it.