Problem Set 7 - Prototyping an algorithm

You will need to read a set of images into your C/C++ code and run your motion detection algorithm on these. The first line of the file is the height of the image, the second line is the width of the image, and the following line is the pixel intensities for the whole image seperated by a space.

C++ Code
C Code
1st Set of Images
2nd Set of Images


Here's the C++ code fragment to read the images. Remember to include fstream.h to use the file I/O routines.

int temp = 0;
unsigned char image[256][256];
ifstream infile("image",ios::in);
infile >> height;
infile >> width;
for (int y = 0; y < height; y++)
{
  for (int x = 0; x < width; x++)
  {
    infile >> temp;
    image[y][x] = (unsigned char)temp;
  }
}
Here's the C code to read the images:

int temp = 0;
unsigned char image[256][256];
FILE * fileptr;
fileptr = fopen("image", "r");
fscanf(fileptr, "%d", &height);
fscanf(fileptr, "%d", &width);
int y, x;
for (y = 0; y < height; y++)
{
  for (x = 0; x < width; x++)
  {
    fscanf(fileptr, "%d", &temp);
    image[y][x] = (unsigned char)temp;
  }
}


Here are the first set of images. You will be reading the ASCII images into your program. Click on the JPG link to see what the image looks like.

ASCII file 1, JPG image1
ASCII file 2, JPG image2
ASCII file 3, JPG image3
ASCII file 4, JPG image4
ASCII file 5, JPG image5
ASCII file 6, JPG image6
ASCII file 7, JPG image7
ASCII file 8, JPG image8
ASCII file 9, JPG image9


Here are the second set of images.
ASCII file 1, JPG image1
ASCII file 2, JPG image2
ASCII file 3, JPG image3
ASCII file 4, JPG image4
ASCII file 5, JPG image5
ASCII file 6, JPG image6
ASCII file 7, JPG image7


Send comments to nma@cory.eecs.berkeley.edu