2015-04-14 36 views
0

我想在Openframeworks中的图像上应用有序的bayer抖动算法,我无法得到结果。在Openframeworks中有序的Bayer抖动

维基百科链接:http://en.wikipedia.org/wiki/Ordered_dithering

的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 

我的代码: -

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 i = 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); 

    } 

我在哪里做错了?

回答

0

也许它是一个四舍五入的问题?我把代码片段放在一起:

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 are now all betwenn 0.0 and 1.0 

factor = array[k%4][j%4]; // here factor will become 0 
+0

oops我的错误...试过了,结果相同 – voltaa7