# image processing – Floyd Steinberg Dithering Matlab – What am I doing wrong?

## image processing – Floyd Steinberg Dithering Matlab – What am I doing wrong?

The problem is that you tried to improve the pseudocode and remove `oldpixel`

! Note that the algorithm does not calculate an error between the quantized pixel and its corresponding value in the original image, but rather the error between the quantized pixel and the previous value in the dithered image, which may have been updated while scanning the previous pixels.

Bring `oldpixel`

back and review the whole algorithm one more time.

But even after the modifications, you can not expect the results to match the MATLAB output, which could be the result of differences in the details of the two implementations.

Youâ€™re propagating errors in `image_quantized`

instead of in the original image. Remove this quantized image, it is not part of the algorithm.

You need to quantize one pixel, then find the difference with the original value, and propagate that error into future pixels.

Note that Wikipedia pseudocode does this in-place, there is only one copy of the image that works as both input and output.

On this old blog post of mine has MATLAB code for Floyd-Steinberg dithering.

#### image processing – Floyd Steinberg Dithering Matlab – What am I doing wrong?

Assuming you first follow saastns answer (and replying to what it says about the differences between those images) : Id say that by just looking at them in saastns image, Matlabs patterns look like theyre a sideways version of Floyd-Steinberg here, either by rotation, or more probably by transposition (swap x with y, which is a reflexion across the x+y diagonal axis). This cant be imitated by just changing coefficients, the image has to be processed by columns (for x outside of for y, etc).