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

The ditherImage function has no effect #647

Open
Luke-Tang opened this issue May 11, 2024 · 7 comments
Open

The ditherImage function has no effect #647

Luke-Tang opened this issue May 11, 2024 · 7 comments

Comments

@Luke-Tang
Copy link

import 'package:image/image.dart' as img;

void main() async {
  final cmd = img.Command()
    ..decodePngFile('test_origin.png')
    ..ditherImage()
    ..writeToFile('test_image_dithered.png');
  await cmd.executeThread();
}

origin image
test_origin
converted image
test_image_dithered

The two pictures look similar, but the converted image is smaller.
The expected picture should look something like this:
test_floydSteinberg

@brendan-duncan
Copy link
Owner

I'll look into it.

@brendan-duncan
Copy link
Owner

Wow, I don't know how that function ever worked. What was I thinking?
I'll have to re-work that function.

@brendan-duncan
Copy link
Owner

I pushed some fixes to git. It's nowhere near as extreme as your final example.

@Luke-Tang
Copy link
Author

I appreciate your quick response.

The ditherImage function uses the floydSteinberg algorithm by default.
I tried to use this image to test the new code:
test
But the resulting picture looks like this:
test_david_dithered
The example picture in Floyd-Steinberg_dithering's Wikipedia looks like this:
Michelangelo's_David_-_Floyd-Steinberg
Wikipedia for the Floyd-Steinberg dithering algorithm

@brendan-duncan
Copy link
Owner

That's not a 1:1 comparison. They converted the image to 2-bit black-and-white. I tested doing that and you see the dither pattern.
quantize_neural_dither_2

@brendan-duncan
Copy link
Owner

I'll still be working on improving the quantization and dithering results, by the way. Might take a bit, working on lots of projects.

@zhponng
Copy link

zhponng commented Jun 6, 2024

I have the same situation. The dithered image is not much different from the original image, and the algorithm takes a long time. I look forward to updating it.

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

No branches or pull requests

3 participants