hip
hip copied to clipboard
Initial version of Floyd Steinberg Dithering
An outline implementation of Floyd Steinberg Dithering algorithm (The errors calculated are not exactly correct and the values currently used are testing ones). Please note that this is an initial version and so the output generated is only as per the testing values.
@lehins Sir, I have a few doubts regarding the algorithm and so I'm starting a PR at an early stage so as I can discuss a thing or two with you.
@lehins Firstly, I'm a bit confused about finding the R,G and B values in the double range (0, 1). Please forgive me if this is something very silly. I had a bit less time so started a PR early, am still reading and working upon this. Hope you don't mind :-)
@lehins The psudocode for the algo is available at https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering
@khilanravani Why are confused that RGB values are in [0,1] range? What should they be?
Also what does this operation on RGB be does? I couldn't see on the wiki reference you added:
let re = m - 0.1
let be = m - 0.5
let ge = m - 0.85
What are you trying to achieve here?
Oh and, I got no problem with an early PR and will happily discuss the algorithm and implementation with you
@lehins Sir, I need to find the nearest palette color (of R,G and B) and then need to find the error from the original pixel color to those (0.1, 0.5 & 0.85 are just fictional values representing the palette colors R,G and B). Plz forgive me if I'm overlooking something very silly.
I see what's going on. Looks like you'd need to come up with an algorithm for coming up with a palette for a a color image before you can do dithering. Maybe you should first try to get Dithering to work for Luma images going from Double
to Word8
and then try to expand it further afterwards. It seems like you are already close to that.
@lehins Okay sir, I'll try it out. Thank u! Ping u later.
@lehins Here is the implementation for luma images sir. I hope that I got it right. For now, I've hard-coded the color values but can update them soon if you feel that this is the correct way. For your reference, a sample output :