#include #include #include #include #include #include #define round(x)((x)>=0?(int)((x)+0.5):(int)((x)-0.5)) #define ThrowWandException(wand) { char *description; ExceptionType severity; description=MagickGetException(wand,&severity); (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); description=(char *) MagickRelinquishMemory(description); exit(-1); } int main(int argc, char **argv ) { MagickWand *magick_wand; MagickWand *first_wand; double green, red, blue; int i,j, k; int x,y; int image = 0; int height = 0; int width = 0; int nImages = 0; unsigned long number_wands; char filename[256]; char rgb[128]; char *temp; uint8_t ****array; MagickWandGenesis(); // open the first image and get the height and width first_wand = NewMagickWand(); if(MagickReadImage(first_wand, argv[2]) == MagickFalse) { ThrowWandException(first_wand); } height = MagickGetImageHeight(first_wand); width = MagickGetImageWidth(first_wand); first_wand = DestroyMagickWand(first_wand); printf("height: %d width:%d \n", height, width); // count how many images there are in the input file FILE *count = fopen( argv[1], "r"); if(count != NULL) { while((fgets(filename, sizeof(filename), count)) != NULL) { nImages++; } fclose(count); } printf("number of imagges: %d \n", nImages); // initialize the storage array. array = calloc(nImages, sizeof(array[0])); for(i = 0; i < nImages; i++) { array[i] = calloc(height, sizeof(array[0][0])); for(j = 0; j < height; j++) { array[i][j] = calloc(width, sizeof(array[0][0][0])); for(k = 0; k < width; k++) { array[i][j][k] = calloc(3, sizeof(array[0][0][0][0])); } } } // store each pixel in the storage array. array[nImage][height][width][ { R, G, B} ] FILE *input_file = fopen ( argv[1], "r" ); if ( input_file != NULL ) { while ((fgets(filename, sizeof(filename), input_file)) != NULL ) { temp = strchr(filename, '\n'); if (temp != NULL) *temp = '\0'; magick_wand = NewMagickWand(); MagickReadImage(magick_wand, filename); PixelIterator* iterator = NewPixelIterator(magick_wand); PixelWand **pixels = PixelGetNextIteratorRow(iterator,&number_wands); printf("Image number:%d Filename: %s \n", image, filename); for (i=0; pixels != (PixelWand **) NULL; i++) { for (j=0; j