Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial version of Floyd Steinberg Dithering #25

Open
wants to merge 26 commits into
base: master
Choose a base branch
from

Conversation

khilanravani
Copy link

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.

khilanravani and others added 25 commits May 28, 2018 15:49
We first extract some information from the image - width, height etc., convert
to luma and compute gradients. Then, for each pixel (x,y), we compute rho = xcos(theta) + ysin(theta).
After a few more transformations and finding the bins with highest values, we generate the
resulting image.
Preliminary Hough transform implementation
It is used to improve contrast in images and works by performing
enhancement on small 'contextual' regions or neighborhood of each
pixel in the given image.
Fix the horizontal kernel of Sobel filter.
* Mean filter version 1
@khilanravani
Copy link
Author

@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.

@khilanravani
Copy link
Author

@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 :-)

@khilanravani
Copy link
Author

@lehins The psudocode for the algo is available at https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering

dithering
:: forall arr e cs . ( MArray arr RGB Double, IP.Array arr RGB Double, IP.Array arr RGB Double)
=> Image arr RGB Double
-> Int -- ^ width of output image
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always ask for those arguments width and height, why is that? It's not C, you can call dims and get the dimensions of the source and result image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lehins Oh yes, very sorry for repeating the mistake. Wont happen again.

@lehins
Copy link
Owner

lehins commented Aug 16, 2018

@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?

@lehins
Copy link
Owner

lehins commented Aug 16, 2018

Oh and, I got no problem with an early PR and will happily discuss the algorithm and implementation with you

@khilanravani
Copy link
Author

@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.

@lehins
Copy link
Owner

lehins commented Aug 16, 2018

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.

@khilanravani
Copy link
Author

@lehins Okay sir, I'll try it out. Thank u! Ping u later.

@khilanravani
Copy link
Author

@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 :
dither2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants