void process(int x0, int y0, int width, int height, char* ims_name, char* imd_name){ pnm imd = pnm_new(width, height, PnmRawPpm); pnm ims = pnm_load(ims_name); unsigned short r,g,b; for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ for(int z=0; z<3; z++){ r = pnm_get_component(ims, y+y0, x+x0,PnmRed); g = pnm_get_component(ims, y+y0, x+x0,PnmGreen); b = pnm_get_component(ims, y+y0, x+x0,PnmBlue); pnm_set_component(imd,y,x,PnmRed, r); pnm_set_component(imd,y,x,PnmGreen, g); pnm_set_component(imd,y,x,PnmBlue, b); } } } pnm_save(imd, PnmRawPpm, imd_name); pnm_free(imd); pnm_free(ims); }
void RGB2LAB(pnm pims, float* LAB, int cols, int rows) { float* LMS = malloc(cols * rows * 3 * sizeof(float)); float tmp; // Conversion du format RGB au format log(LMS) for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { for (int k = 0; k < 3; ++k) { *LMS = 0.0; for (int m = 0; m < 3; ++m) { *LMS += RGB2LMS[k][m] * (float)pnm_get_component(pims, i, j, m); } // Conversion de LMS en log(LMS) if(*LMS >= 1) { *LMS = log10(*LMS); } else if (*LMS < 1){ *LMS = 0; } LMS++; } } } LMS -= cols * rows * 3; // Conversion de log(LMS) en lab for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { for (int k = 0; k < 3; ++k) { tmp = 0.0; for (int m = 0; m < 3; ++m) { tmp += LMS2LAB[k][m] * (*LMS); LMS++; } LMS -= 3; *LAB = tmp; LAB++; } LMS += 3; } } LAB -= cols * rows * 3; LMS -= cols * rows * 3; free(LMS); }
void process(int num, char* ims_name, char* imd_name){ pnm ims = pnm_load(ims_name); int height = pnm_get_height(ims); int width = pnm_get_width(ims); pnm imd = pnm_new(width, height, PnmRawPpm); unsigned short r,g,b; for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ for(int z=0; z<3; z++){ switch (num){ case 1: r = pnm_get_component(ims, y, x,PnmRed); pnm_set_component(imd,y,x,PnmRed, r); pnm_set_component(imd,y,x,PnmGreen, 0); pnm_set_component(imd,y,x,PnmBlue, 0); break; case 2: g = pnm_get_component(ims, y, x,PnmGreen); pnm_set_component(imd,y,x,PnmRed, 0); pnm_set_component(imd,y,x,PnmGreen, g); pnm_set_component(imd,y,x,PnmBlue, 0); break; case 3: b = pnm_get_component(ims, y, x,PnmBlue); pnm_set_component(imd,y,x,PnmRed, 0); pnm_set_component(imd,y,x,PnmGreen, 0); pnm_set_component(imd,y,x,PnmBlue, b); break; } } } } pnm_save(imd, PnmRawPpm, imd_name); pnm_free(imd); pnm_free(ims); }
void process(int factor, char* filter_name,char* ims_name, char* imd_name) { pnm ims = pnm_load(ims_name); int cols = pnm_get_width(ims); int rows = pnm_get_height(ims); int new_cols = factor*cols; int new_rows = factor*rows; pnm imw = pnm_new(new_cols, rows, PnmRawPpm); pnm imd = pnm_new(new_cols, new_rows, PnmRawPpm); // ===== Columns interpolation ===== for(int i=0; i<rows; i++) { for(int j=0; j<new_cols; j++) { float new_j = (float)j / factor; float WF = 0; if (strcmp(filter_name, "box")== 0) WF = 0.5; else if (strcmp(filter_name, "tent")== 0) WF = 1.0; else if (strcmp(filter_name, "bell")== 0) WF = 1.5; else if (strcmp(filter_name, "mitch")== 0) WF = 2.0; float left = new_j - WF; float right = new_j + WF; int l_int = floor(left); int r_int = floor(right); float S = 0.0; for (int k=l_int; k <= r_int; k++) { float h = 0.0; if (strcmp(filter_name, "box")== 0) h = box((float)k-new_j); else if (strcmp(filter_name, "tent")== 0) h = tent((float)k-new_j); else if (strcmp(filter_name, "bell")== 0) h = bell((float)k-new_j); else if (strcmp(filter_name, "mitch")== 0) h = mitch((float)k-new_j); if (k<0) { S += pnm_get_component(ims, i, 0, 0)*h; } else if (k>=cols) { S += pnm_get_component(ims, i, cols-1, 0)*h; } else { S += pnm_get_component(ims, i, k, 0)*h; } } for (int c=0; c<3; c++) { pnm_set_component(imw, i, j, c, (unsigned short) S); } } } // ===== Rows interpolation ===== for(int i=0; i<new_rows; i++) { for(int j=0; j<new_cols; j++) { float new_i = (float) i / factor; float WF = 0; if (strcmp(filter_name, "box")== 0) WF = 0.5; else if (strcmp(filter_name, "tent")== 0) WF = 1.0; else if (strcmp(filter_name, "bell")== 0) WF = 1.5; else if (strcmp(filter_name, "mitch")== 0) WF = 2.0; float above = new_i - WF; float below = new_i + WF; int a_int = floor(above); int b_int = floor(below); float S = 0.0; for (int k=a_int; k <= b_int; k++) { float h = 0.0; if (strcmp(filter_name, "box")== 0) h = box((float)k-new_i); else if (strcmp(filter_name, "tent")== 0) h = tent((float)k-new_i); else if (strcmp(filter_name, "bell")== 0) h = bell((float)k-new_i); else if (strcmp(filter_name, "mitch")== 0) h = mitch((float)k-new_i); if (k<0) { S += pnm_get_component(imw, 0, j, 0)*h; } else if (k>=rows) { S += pnm_get_component(imw, rows-1, j, 0)*h; } else { S += pnm_get_component(imw, k, j, 0)*h; } } for (int c=0; c<3; c++) { pnm_set_component(imd, i, j, c, (unsigned short) S); } } } pnm_save(imd, PnmRawPpm, imd_name); pnm_free(ims); pnm_free(imw); pnm_free(imd); }
void process(int min, int max, char* ims_name, char* imd_name){ pnm ims = pnm_load(ims_name); int height = pnm_get_height(ims); int width = pnm_get_width(ims); pnm imd = pnm_new(width, height, PnmRawPpm); unsigned short r,g,b,min_r,min_g,min_b,max_r,max_g,max_b; min_r = 255; min_g = 255; min_b = 255; max_r = 0; max_g = 0; max_b = 0; for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ for(int z=0; z<3; z++){ r = pnm_get_component(ims, y, x, PnmRed); g = pnm_get_component(ims, y, x, PnmGreen); b = pnm_get_component(ims, y, x, PnmBlue); if(r < min_r){ min_r = r; } if(g < min_g){ min_g = g; } if(b < min_b){ min_b = b; } if(r > max_r){ max_r = r; } if(g > max_g){ max_g = g; } if(b > max_b){ max_b = b; } } } } unsigned short normalize_r, normalize_g, normalize_b; for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ for(int z=0; z<3; z++){ normalize_r = (max - min) / (max_r - min_r) * pnm_get_component(ims, y, x, PnmRed) + (min * max_r - max * min_r) / (max_r - min_r); normalize_g = (max - min) / (max_g - min_g) * pnm_get_component(ims, y, x, PnmGreen) + (min * max_g - max * min_g) / (max_g - min_g); normalize_b = (max - min) / (max_b - min_b) * pnm_get_component(ims, y, x, PnmBlue) + (min * max_b - max * min_b) / (max_b - min_b); pnm_set_component(imd, y, x, PnmRed, normalize_r); pnm_set_component(imd, y, x, PnmGreen, normalize_g); pnm_set_component(imd, y, x,PnmBlue, normalize_b); } } } printf("****** valeurs min r g b ****** \n"); printf("%u \n", min_r); printf("%u \n", min_g); printf("%u \n", min_b); printf("****** valeurs max r g b ****** \n"); printf("%u \n", max_r); printf("%u \n", max_g); printf("%u \n", max_b); printf("****** valeurs normalize r g b ****** \n"); printf("%u \n", normalize_r); printf("%u \n", normalize_g); printf("%u \n", normalize_b); pnm_save(imd, PnmRawPpm, imd_name); pnm_free(imd); pnm_free(ims); }