Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <omp.h>
- #include "pnm.c"
- int moyenne(grey_image_type * image, int index)
- {
- /* les pixels sont répartis comme suis :
- a b c
- d e f
- g h i
- avec e le pixel de coordone i*/
- unsigned char a, b, d, f, h, i;
- int width = image->width;
- a = image->pixels[index - width - 1];
- b = image->pixels[index - width];
- d = image->pixels[index - 1];
- f = image->pixels[index + 1];
- h = image->pixels[index + width];
- i = image->pixels[index + width + 1];
- return 128-a-a-b-d+f+h+i+i;
- }
- void color_to_grey (color_image_type *color_image, grey_image_type *grey_image){
- int i, j;
- int width=color_image->width; int height = color_image->height;
- for(i=0; i<width; i++){
- for(j=0; j<height; j++){
- 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;
- }
- printf("i : %d\n", i);
- }
- }
- int main(int argc, char const *argv[])
- {
- color_image_type *color_image;
- grey_image_type *grey_image, *transform_grey_image, *egalise_grey_image, *grey_image_test;
- char *filename_input, *filename_output;
- double start, end_grey, end_transform, end_egalise;
- int width, height;
- int H[256]={0};
- int C[256]={0};
- if (argc != 2) printf("Usage : %s image\n",argv[0] );
- filename_input = (char*)argv[1];
- color_image = loadColorImage(filename_input);
- width = color_image->width;
- height = color_image->height;
- grey_image = createGreyImage(width, height);
- grey_image_test = createGreyImage(width, height);
- color_to_grey(color_image, grey_image_test);
- transform_grey_image = createGreyImage(width, height);
- egalise_grey_image = createGreyImage(width, height);
- filename_output = malloc (6+strlen(filename_input));
- printf("Debut parallelisation\n");
- start = omp_get_wtime();
- #pragma omp parallel
- {
- #pragma omp for
- for (int i = 0; i < width * height; ++i)
- grey_image->pixels[i] = (color_image->pixels[i].r * 299 + color_image->pixels[i].g * 587 + color_image->pixels[i].b * 114)/1000;
- #pragma omp barrier
- end_grey = omp_get_wtime();
- #pragma omp for
- for (int i = 0; i < height * width; ++i)
- {
- if (i % width != 0 && i % width != width-1 && i / width != 0 && i / width != height - 1)
- transform_grey_image->pixels[i] = moyenne(grey_image, i);
- else
- transform_grey_image->pixels[i] = grey_image->pixels[i];
- }
- #pragma omp barrier
- end_transform = omp_get_wtime();
- #pragma omp for
- for (int i = 0; i < height * width; ++i)
- {
- #pragma omp atomic
- H[grey_image->pixels[i]]++;
- }
- }
- C[0]=0;
- for (int i = 1; i < 256; ++i)
- {
- C[i]=C[i-1] + H[i];
- }
- #pragma omp parallel
- {
- #pragma omp for
- for (int i = 0; i < height * width; ++i)
- egalise_grey_image->pixels[i] = 256 * C[grey_image->pixels[i]] / C[255];
- }
- end_egalise = omp_get_wtime();
- printf("Fin parallelisation\n");
- printf("Temps d'execution :\nGrey %f\nTransform %f\nEgalise %f\n", end_grey - start, end_transform - end_grey, end_egalise - end_transform);
- sprintf(filename_output,"out1_%s",filename_input);
- saveGreyImage(filename_output, grey_image_test);
- sprintf(filename_output,"out2_%s",filename_input);
- saveGreyImage(filename_output, transform_grey_image);
- sprintf(filename_output,"out3_%s",filename_input);
- saveGreyImage(filename_output, egalise_grey_image);
- free(filename_output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement