0

# Error Diffusion Dithering - Stucki

Unsolved
###### Computer Vision

Difficulty: 6 | Problem written by mesakarghm
##### Problem reported in interviews at

Error Diffusion Dithering by Stucki is an approach for image dithering using error diffusion. In error diffusion, the quantization error of the current pixel is added to the pixel on the right and below according to the procedure below:

a: For each point in the image, find the closest color available (for a grayscale image, this is just a thresholding operation fixed at 127 for this problem set).

b: Calculate the difference between the value in the image and the color you have.

c: Now divide up these error values and distribute them over the neighboring pixels which you have not visited yet.

d: When you get to these later pixels, just add the errors distributed from the earlier ones, clip the values to the allowed range if needed, then continue as above.

The set below shows the index of the neighboring pixels along with their diffusal coefficient according to the Stucki Method.

(
(1, 0, 8 / 42),
(2, 0, 4 / 42),
(-2, 1, 2 / 42),
(-1, 1, 4 / 42),
(0, 1, 8 / 42),
(1, 1, 4 / 42),
(2, 1, 2 / 42),
(-2, 2, 1 / 42),
(-1, 2, 2 / 42),
(0, 2, 4 / 42),
(1, 2, 2 / 42),
(2, 2, 1 / 42),
)

Write a program to implement the Stucki Error Diffusion Ditheringmethod in a given 2D matrix (grayscale image). Use the diffusion filter given in the problem set for dividing up the error.

##### Sample Input:
<class 'numpy.ndarray'>
image: [[ 1 7 119 13 12] [ 11 21 61 81 91] [ 5 66 6 5 5] [ 5 66 166 145 155] [ 5 66 136 145 155]]

##### Expected Output:
<class 'numpy.ndarray'>
[[ 0 0 0 0 0] [ 0 0 0 0 0] [ 0 0 0 0 0] [ 0 0 255 255 255] [ 0 0 255 255 255]]

This is a premium problem, to view more details of this problem please sign up for MLPro Premium. MLPro premium offers access to actual machine learning and data science interview questions and coding challenges commonly asked at tech companies all over the world

MLPro Premium also allows you to access all our high quality MCQs which are not available on the free tier.

Not able to solve a problem? MLPro premium brings you access to solutions for all problems available on MLPro

Have an issue, the MLPro support team is available 24X7 to Premium users.