int main(int argc, char **argv) { int mod_size = (ROW * COL ) / ( K * K); pixel_t* in = malloc( sizeof(pixel_t) * ROW * COL); pixel_t* out = malloc( sizeof( pixel_t) * ROW * COL); pixel_t** mod_out = malloc( sizeof(pixel_t*) * mod_size); pixel_t** mod_in = malloc( sizeof(pixel_t*) * mod_size); //load raw image loadRawImage( "lena.raw" , ROW, COL, in); single_double_layout(in, mod_size, K*K, mod_in); single_double_layout(out, mod_size, K*K, mod_out); // define 5x5 Gaussian kernel int kernelRow = 5, kernelCol = 5; kernel_t kernel[25] = { 1/256.0f, 4/256.0f, 6/256.0f, 4/256.0f, 1/256.0f, 4/256.0f, 16/256.0f, 24/256.0f, 16/256.0f, 4/256.0f, 6/256.0f, 24/256.0f, 36/256.0f, 24/256.0f, 6/256.0f, 4/256.0f, 16/256.0f, 24/256.0f, 16/256.0f, 4/256.0f, 1/256.0f, 4/256.0f, 6/256.0f, 4/256.0f, 1/256.0f }; // convolve the image stored in 'in' -> 'out' with 'kernel' convolve2DSlow( mod_in, mod_out,ROW, COL, kernel, kernelRow, kernelCol); //write the colvolved image; double_single_layout(out, mod_size, K*K, mod_out); writeRawImage( "lena_conv_single.raw", ROW, COL, out); return 0; }
int main(int argc, char** argv){ Image im; char outfilename[MAX_FILENAME_LENGTH]; int i = 1; printf("%s\n%s\n",OPENING,VERSION); if(argc == 1 || strcmp(argv[1],"-help") == 0 || strcmp(argv[1],"--help") == 0){ usage(argv[0]); } for(;i < argc; i++){ printf("Converting: %s\n",argv[i]); im = readPGMImage(argv[i]); removeExtention(argv[i]); sprintf(outfilename,"%s.sfi",argv[i]); printf(" Writing: %s\n",outfilename); writeRawImage(im,outfilename); } printf("done.\n"); return 0; }
void convertImages(Arguments* args){ FILE* list; JetMasks masks; int x, y,i,j; char imagename[MAX_FILENAME_LENGTH]; char filename[MAX_FILENAME_LENGTH]; MESSAGE("Creating gabor masks."); masks = readMasksFile(args->maskFile); if(args->saveMasks){ for(y = 0; y < masks->size; y++){ char outname[MAX_FILENAME_LENGTH]; sprintf(outname, "mask%03d.pgm",y); writePGMImage(masks->masks[y],outname,0); } } list = fopen(args->imageList,"r"); if(!list){ printf("Error opening file: %s\n", args->imageList); exit(1); } while(fscanf(list, "%s", imagename) == 1){ Image im; Image grid; sprintf(filename, "%s/%s", args->inputDir, imagename); im = readRawImage(filename); MESSAGE1ARG("Processing file: %s",filename); /* Find the number of points in the grid */ i = 0; for( x = args->gridStartX; x < im->width; x += args->gridSpaceX){ for( y = args->gridStartY; y < im->height; y+= args->gridSpaceY){ i++; } } grid = makeImage(i,masks->size,1); /* Compute convolutions */ i = 0; for( x = args->gridStartX; x < im->width; x += args->gridSpaceX){ for( y = args->gridStartY; y < im->height; y+= args->gridSpaceY){ for(j = 0; j < masks->size; j++){ if( i < grid->width ) IE(grid,i,j,0) = convolvePoint(x, y, 0, im, masks->masks[j]); } i++; } } sprintf(filename, "%s/%s", args->sfiDir, imagename); writeRawImage(grid,filename); freeImage(grid); freeImage(im); } fclose(list); }
void convertImages(Arguments* args){ char** mask = NULL; TwoPoints source, dest; FILE* eyeList; char line[ FILE_LINE_LENGTH ]; char filename[MAX_FILENAME_LENGTH]; char imagename[MAX_FILENAME_LENGTH]; char suffix[MAX_FILENAME_LENGTH]; int i; scaleArgs(args, args->scale); dest.x1 = args->eyeLx; dest.y1 = args->eyeLy; dest.x2 = args->eyeRx; dest.y2 = args->eyeRy; /* Prepare file suffix encoding preprocessing settings, blank if not requested */ if (args->configSuffix) { sprintf(suffix,"_%s", imageSuffix(args)); } else { suffix[0] = '\0'; } if(args->maskType == CL_YES){ MESSAGE("Creating Mask."); mask = generateMask(args->sizeWidth, args->sizeHeight, args->ellipseX, args->ellipseY, args->ellipseA, args->ellipseB); } eyeList = fopen(args->eyeFile,"r"); DEBUG_CHECK(eyeList,"Error opening eye coordinates file"); for(i = 1;;i++){ Image pgm; Image geo; Matrix transform; fgets(line, FILE_LINE_LENGTH, eyeList); if(feof(eyeList)) break; if(sscanf(line,"%s %lf %lf %lf %lf",filename, &(source.x1), &(source.y1), &(source.x2), &(source.y2)) != 5){ printf("Error parsing line %d of eye coordinate file. Exiting...",i); exit(1); } /* shift the eye coordinates if neccessary */ source.x1 += args->shiftX; source.y1 += args->shiftY; source.x2 += args->shiftX; source.y2 += args->shiftY; sprintf(imagename,"%s\\%s.pgm",args->inputDir,filename); MESSAGE1ARG("Processing image: %s",filename); pgm = readPGMImage(imagename); if(args->histType == HIST_PRE){ DEBUG(1," Performing Pre Histogram Equalization."); histEqual(pgm,256); } if(args->preNormType == CL_YES){ DEBUG(1," Performing Pre Pixel Normalization."); ZeroMeanOneStdDev(pgm); } if(args->preEdge){ smoothImageEdge(pgm, args->preEdge); } if(args->geoType == CL_YES){ DEBUG(1," Performing Geometric Normalization."); transform = generateTransform(&source,&dest,args->reflect); geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform); } else{ transform = makeIdentityMatrix(3); geo = transformImage(pgm,args->sizeWidth,args->sizeHeight,transform); } if(args->noise != 0.0){ DEBUG(1," Adding Gausian Noise."); gaussianNoise(geo,args->noise); } if(args->histType == HIST_POST){ DEBUG(1," Performing Post Histogram Equalization."); histEqualMask(geo,256, (const char**) mask); } if(args->nrmType == CL_YES){ DEBUG(1," Performing final value normalization and Applying Mask."); ZeroMeanOneStdDevMasked(geo, (const char **) mask); } else{ DEBUG(1," No Value Normalization. Just Applying Mask."); applyMask(geo, (const char **) mask); } if(args->postEdge){ smoothImageEdge(geo, args->postEdge); } if(args->nrmDir){ sprintf(imagename,"%s\\%s%s.nrm", args->nrmDir, filename, suffix); DEBUG_STRING(1," Saving nrm: %s",imagename); writeFeretImage(geo,imagename); } if(args->pgmDir){ sprintf(imagename,"%s\\%s%s.pgm", args->pgmDir, filename, suffix); DEBUG_STRING(1," Saving pgm: %s",imagename); writePGMImage(geo,imagename,0); } if(args->sfiDir){ sprintf(imagename,"%s\\%s%s.sfi", args->sfiDir, filename, suffix); DEBUG_STRING(1," Saving sfi: %s",imagename); writeRawImage(geo,imagename); } freeImage(geo); freeImage(pgm); freeMatrix(transform); } fclose(eyeList); }