Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. #include <omp.h>
  2. #include "pnm.c"
  3.  
  4. int moyenne(grey_image_type * image, int index)
  5. {
  6. /* les pixels sont répartis comme suis :
  7. a b c
  8. d e f
  9. g h i
  10. avec e le pixel de coordone i*/
  11. unsigned char a, b, d, f, h, i;
  12. int width = image->width;
  13. a = image->pixels[index - width - 1];
  14. b = image->pixels[index - width];
  15. d = image->pixels[index - 1];
  16. f = image->pixels[index + 1];
  17. h = image->pixels[index + width];
  18. i = image->pixels[index + width + 1];
  19. return 128-a-a-b-d+f+h+i+i;
  20. }
  21.  
  22. void color_to_grey (color_image_type *color_image, grey_image_type *grey_image){
  23. int i, j;
  24. int width=color_image->width; int height = color_image->height;
  25. for(i=0; i<width; i++){
  26. for(j=0; j<height; j++){
  27. grey_image->pixels[width*j+i+1]=(unsigned char)(((int) color_image->pixels[width*j+i+1].r * 299) + ((int) color_image->pixels[width*j+i+1].g * 587) + ((int) color_image->pixels[width*j+i+1].b * 114))/1000;
  28. }
  29. printf("i : %d\n", i);
  30. }
  31. }
  32.  
  33. int main(int argc, char const *argv[])
  34. {
  35. color_image_type *color_image;
  36. grey_image_type *grey_image, *transform_grey_image, *egalise_grey_image, *grey_image_test;
  37. char *filename_input, *filename_output;
  38. double start, end_grey, end_transform, end_egalise;
  39. int width, height;
  40. int H[256]={0};
  41. int C[256]={0};
  42.  
  43.  
  44. if (argc != 2) printf("Usage : %s image\n",argv[0] );
  45. filename_input = (char*)argv[1];
  46. color_image = loadColorImage(filename_input);
  47. width = color_image->width;
  48. height = color_image->height;
  49. grey_image = createGreyImage(width, height);
  50. grey_image_test = createGreyImage(width, height);
  51. color_to_grey(color_image, grey_image_test);
  52. transform_grey_image = createGreyImage(width, height);
  53. egalise_grey_image = createGreyImage(width, height);
  54. filename_output = malloc (6+strlen(filename_input));
  55.  
  56. printf("Debut parallelisation\n");
  57. start = omp_get_wtime();
  58.  
  59. #pragma omp parallel
  60. {
  61. #pragma omp for
  62. for (int i = 0; i < width * height; ++i)
  63. grey_image->pixels[i] = (color_image->pixels[i].r * 299 + color_image->pixels[i].g * 587 + color_image->pixels[i].b * 114)/1000;
  64. #pragma omp barrier
  65. end_grey = omp_get_wtime();
  66.  
  67. #pragma omp for
  68. for (int i = 0; i < height * width; ++i)
  69. {
  70. if (i % width != 0 && i % width != width-1 && i / width != 0 && i / width != height - 1)
  71. transform_grey_image->pixels[i] = moyenne(grey_image, i);
  72. else
  73. transform_grey_image->pixels[i] = grey_image->pixels[i];
  74. }
  75. #pragma omp barrier
  76. end_transform = omp_get_wtime();
  77.  
  78. #pragma omp for
  79. for (int i = 0; i < height * width; ++i)
  80. {
  81. #pragma omp atomic
  82. H[grey_image->pixels[i]]++;
  83. }
  84. }
  85. C[0]=0;
  86. for (int i = 1; i < 256; ++i)
  87. {
  88. C[i]=C[i-1] + H[i];
  89. }
  90. #pragma omp parallel
  91. {
  92. #pragma omp for
  93. for (int i = 0; i < height * width; ++i)
  94. egalise_grey_image->pixels[i] = 256 * C[grey_image->pixels[i]] / C[255];
  95. }
  96. end_egalise = omp_get_wtime();
  97. printf("Fin parallelisation\n");
  98. printf("Temps d'execution :\nGrey %f\nTransform %f\nEgalise %f\n", end_grey - start, end_transform - end_grey, end_egalise - end_transform);
  99.  
  100. sprintf(filename_output,"out1_%s",filename_input);
  101. saveGreyImage(filename_output, grey_image_test);
  102. sprintf(filename_output,"out2_%s",filename_input);
  103. saveGreyImage(filename_output, transform_grey_image);
  104. sprintf(filename_output,"out3_%s",filename_input);
  105. saveGreyImage(filename_output, egalise_grey_image);
  106.  
  107.  
  108.  
  109. free(filename_output);
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement