Advertisement
Guest User

sharpener

a guest
Dec 10th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #include "bmp.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. /*
  5. * Фильтр усиления резкости
  6. */
  7. void bmp_sharpener(bmp_image image)
  8. {
  9.  
  10. /* Получаем линейные размеры изображения */
  11. int w = image.header.width;
  12. int h = image.header.height;
  13.  
  14. /*Создаем копию картинки*/
  15. double *copy = (double*) malloc(3*w*h*sizeof(double));
  16. int n;
  17. for (n=0; n<3*w*h;++n)
  18. copy[n]=image.pixel_array[n];
  19.  
  20. /*Реализуем матрицу усиления резкости*/
  21. int kernel [5][5] ={ {-1,-1,-1,-1,-1},
  22. {-1,-1,-1,-1,-1},
  23. {-1,-1,25,-1,-1},
  24. {-1,-1,-1,-1,-1},
  25. {-1,-1,-1,-1,-1}};
  26. /*Работа с матрицей*/
  27. /* Для всех строк пикселей */
  28. int i,j,r,c,col,line;
  29. double blue2;
  30. double green2;
  31. double red2;
  32. blue2=9; green2=0; red2=0;
  33. for (i = 0; i < h; i++) {
  34. /* Для каждого пикселя */
  35. for(j = 0; j < w; j++){
  36. line=0;
  37. for (r = i-2; r <i+2; r++){ col=0;
  38. for (c = j-2;c<j+2;c++){
  39. /*Границы изображения*/
  40. if(r < 0||r >= h|| c < 0||c >= w) continue;
  41.  
  42. blue2+=copy[0 * h * w + r * w + c]*kernel[line][col];
  43. green2+=copy[1 * h * w + r * w + c]*kernel[line][col];
  44. red2+=copy[2 * h * w + r * w + c]*kernel[line][col];
  45. col++;
  46. }
  47. line++;
  48. }
  49. if (blue2 >1) blue2=1;
  50. if (blue2 <0) blue2=0;
  51. if (green2 >1) green2=1;
  52. if (green2 <0) green2=0;
  53. if (red2 >1) red2=1;
  54. if (red2 <0) red2=0;
  55. image.pixel_array[0 * h * w + i * w + j]=blue2;
  56. image.pixel_array[1 * h * w + i * w + j]=green2;
  57. image.pixel_array[2 * h * w + i * w + j]=red2;
  58.  
  59. }
  60. }
  61. free(copy);
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement