0

I am currently doing a project where I have to halftoning printing by ordered dithering . However, after doing my dithering processing, my image showing in this way . Does anyone know what I'm doing wrong?

Image dithering(Image input, int orderedDithering[2][2])
{

    Image output = input ;
    int x , y ;
    for( x=0 ; x < input.height ; x++)
    {
        int i = x % 4 ;

        for( y=0; y<input.width; y++)
        {
            int j = y % 4 ;

       #define R(X,Y) input.term[(Y)*input.rowsize+3*(X)+2]
       #define G(X,Y) input.term[(Y)*input.rowsize+3*(X)+1]
       #define B(X,Y) input.term[(Y)*input.rowsize+3*(X)]

          input.term[(y)*input.rowsize+3*(x)+2]  = (R(x,y) < orderedDithering[i][j] ? 0 : 255);
          input.term[(y)*input.rowsize+3*(x)+1]  = (G(x,y) < orderedDithering[i][j] ? 0 : 255);
          input.term[(y)*input.rowsize+3*(x)+0]  = (B(x,y) < orderedDithering[i][j] ? 0 : 255);
        }
    }


    return output ;
}

(https://i.stack.imgur.com/YnCMu.png)

  • First problem: your i, j are in [0, 3], but orderedDithering is 2x2. –  Nov 18 '22 at 09:23
  • Personal note: I prefer the Floyd-Steinberg method. –  Nov 18 '22 at 09:25
  • Me too, but the project is needed in this way – Yahya Haj Ali Nov 18 '22 at 09:27
  • If you make the array [4] the problem is fixed ?! – Yahya Haj Ali Nov 18 '22 at 09:28
  • A few notes on the code: 1) `output` is never modified; 2) as commented above, for the current code to be safe, you should use `int i = x % 2` and `int j = y % 2`; 3) `R(x, y) < orderedDithering[i][j] ? 0 : 255)` will perform the comparison first, and then assign a value of `0` or `255`; I don't know if that's what you intend. – rturrado Nov 18 '22 at 13:42
  • I made 2 of the loops, it solved the problem, thanks – Yahya Haj Ali Nov 18 '22 at 15:14
  • Yes, this is what I want. Thanks for your help I noticed that n must be divided by n by n and not n multiplied by n, I will modify it – Yahya Haj Ali Nov 19 '22 at 08:25

0 Answers0