c++ - Ordered Bayer Dithering in Openframeworks -


i trying apply ordered bayer dithering algo on image in openframeworks , not able result.

wikipedia link : http://en.wikipedia.org/wiki/ordered_dithering

the algo :--

foreach y     foreach x        oldpixel := pixel[x][y] + (pixel[x][y] * threshold_map_4x4[x mod 4][y mod 4])        newpixel := find_closest_palette_color(oldpixel)        pixel[x][y] := newpixel 

my code :--

void testapp::setup(){         int factor = 0;         float array[4][4] = {{1,9,3,11},{13,5,15,7},{4,12,2,10},{16,8,14,6}};          for(int = 0 ; i<4;i++){             for(int j = 0 ; j<4;j++){                 array[i][j] = array[i][j]/17;             }         }          img1.loadimage("hello.jpg");         img1.resize(999,999);         img1.update();          img2 = img1;          pix = img1.getpixels();         pix2 = img2.getpixels();          for(int k  = 0 ; k < 999 ; k++){             for(int j = 0 ; j < 999*3 ; j+=3){             factor = array[k%4][j%4];             pix2[k*999 + j] +=  ( pix2[k*999 + j]  * factor );             pix2[k*999 + j + 1] +=  ( pix2[k*999 + j + 1]  * factor );             pix2[k*999 + j + 2] +=  ( pix2[k*999 + j + 2]  * factor );                  pix[k*999 + j] = ( pix2[k*999 +j] + 128 ) / 256 ;                 pix[k*999 + j+1] = ( pix2[k*999 +j+1] + 128 ) / 256 ;                 pix[k*999 + j+2] = ( pix2[k*999 +j+2] + 128 ) / 256 ;               }           }          img1.update();          }       //--------------------------------------------------------------     void testapp::update(){         }      //--------------------------------------------------------------     void testapp::draw(){          img1.draw(0,0);      } 

where doing wrong ?

maybe rounding problem? put code snippets together:

int factor = 0; float array[4][4] = {{1,9,3,11},{13,5,15,7},{4,12,2,10},{16,8,14,6}}; array[i][j] = array[i][j]/17;  // values betwenn 0.0 , 1.0  factor = array[k%4][j%4]; // here factor become 0 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -