     fclose(fp);
 }
 
-void changeColorPPM(PPMImage *img)
-{
-    int i;
-    if(img){
-
-         for(i=0;i<img->x*img->y;i++){
-              int avg = (img->data[i].red + img->data[i].green + img ->data[i].blue) / 3;
-
-              /*
-              img->data[i].red=RGB_COMPONENT_COLOR-img->data[i].red;
-              img->data[i].green=RGB_COMPONENT_COLOR-img->data[i].green;
-              img->data[i].blue=RGB_COMPONENT_COLOR-img->data[i].blue;
-              */
-
-              img->data[i].red = avg;
-              img->data[i].green = avg;
-              img->data[i].blue = avg;
-         }
-    }
-}
-
+// Allocates memory and initializes a filter for 2D convolution
 Filter * initializeFilter()
 {
     int data[FILTER_SIZE * FILTER_SIZE] = {0, 0, 0, 0, 0,


        outImage->data = outputData_h;

        writePPM(outstr,outImage);

    }

    free(outputData_h);
    free(outImage);
    cudaFree(imageData_d);

    clock_t begin, end;
    double time_spent = 0.0;

    char instr[80];
    char outstr[80];
    int i = 0;

    PPMImage images[301];

    PPMPixel *imageData_d, *outputData_d, *outputData_h;
    // get filter for convolution
    Filter * filter_h = initializeFilter();

    cudaError_t cuda_ret;

    // read in 301 frames
    for(i = 0; i < 301; i++) {
        sprintf(instr, "infiles/tmp%03d.ppm", i+1);
        images[i] = *readPPM(instr);
    }

    PPMImage *image;
    image = &images[0];
    // malloc space for output data on host
    outputData_h = (PPMPixel *)malloc(image->x*image->y*sizeof(PPMPixel));

    // malloc space for input and output on device
    cuda_ret = cudaMalloc((void**)&(imageData_d), image->x*image->y*sizeof(PPMPixel));
    if(cuda_ret != cudaSuccess) FATAL("Unable to allocate device memory");

