Advertisement
Fahim_7861

floye Steinberg

May 1st, 2021
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1.  
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8. float arr[3][3] = {{1,32,120},{132,252,18},{80,140,255}};
  9.  
  10. float error[3][3]= {};
  11. int step = 1;
  12. for(int i=0; i<3; i++)
  13. {
  14. for(int j=0; j<3; j++)
  15. {
  16. cout << endl << endl;
  17. cout << "Step : " << step << endl;
  18. float pixel = arr[i][j];
  19. // cout << "Old Pixel: " << pixel << endl;
  20. printf("Old Pixel : %.0f \n",pixel);
  21. float newPixel;
  22. //if(pixel < 128) newPixel = 0;
  23. if(pixel < 85)
  24. newPixel = 0;
  25. else if(pixel < 170)
  26. newPixel = 128;
  27. else
  28. newPixel = 255;
  29. // cout << "New Pixel : " << newPixel << endl;
  30. printf("New Pixel : %.0f \n",newPixel);
  31. if(arr[i][j] < 85)
  32. arr[i][j] = 0;
  33. else if(arr[i][j] < 170)
  34. arr[i][j] = 128;
  35. else
  36. arr[i][j] = 255;
  37. float err = pixel - newPixel;
  38. if(i==0&j==0)
  39. error[0][0] = err;
  40. if(j<2)
  41. {
  42. printf("position (%d,%d),newPixel value : %.0f + %.0f * 7/16 = %.0f \n",i,j+1,arr[i][j+1],err,arr[i][j+1]+err*(7.0/16.0));
  43. arr[i ][j+1]+=err*(7.0/16.0);
  44.  
  45. error[i][j+1] = pixel - abs(err*(7.0/16.0));
  46. }
  47. if(i<2)
  48. {
  49. printf("position (%d,%d),newPixel value : %.0f + %.0f * 5/16 = %.0f \n",i+1,j,arr[i+1][j],err,arr[i+1][j]+err*5/16);
  50. arr[i+1][j ]+=err*5/16;
  51.  
  52. error[i+1][j ]=pixel - abs(err*(5.0/16.0));
  53. }
  54. if(i<2 && j>0)
  55. {
  56. printf("position (%d,%d),newPixel value : %.0f + %.0f * 3/16 = %.0f \n",i+1,j-1,arr[i+1][j-1],err,arr[i+1][j-1]+err*3/16);
  57.  
  58. arr[i+1][j-1]+=err*3/16;
  59.  
  60. error[i+1][j-1]=pixel - abs(err*(3.0/16.0));
  61. }
  62. if(i<2&&j<2)
  63. {
  64. printf("position (%d,%d),newPixel value : %.0f + %.0f * 1/16 = %.0f \n",i+1,j+1,arr[i+1][j+1],err,arr[i+1][j+1]+err*1/16);
  65.  
  66. arr[i+1][j+1]+=err*1/16;
  67. error[i+1][j+1]=pixel - abs(err*(1.0/16.0));
  68.  
  69. }
  70.  
  71. cout << "Array updated : " << endl;
  72.  
  73. for(int x=0; x<3; x++)
  74. {
  75. for(int y=0; y<3; y++)
  76. {
  77. float pixel = arr[x][y];
  78. printf("%.0f ",pixel);
  79. }
  80. cout << endl;
  81. }
  82. /*
  83. cout << "Array error : " << endl;
  84. for(int x=0; x<3; x++)
  85. {
  86. for(int y=0; y<3; y++)
  87. {
  88. float pixel = error[x][y];
  89. printf("%.2f ",pixel);
  90. }
  91. cout << endl;
  92. }
  93. */
  94. step++;
  95. }
  96. }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement