CS3240: Data Structures and Algorithms

Image Arrays Exercise

due Jan 29

PEER GRADED

In this exercise, you will gain experience with multi-dimensional arrays and use in functions. The application will be to create a simple image processing program that will brighten each pixel value in an image (each element in the array representing the image) by adding to it a constant value making sure the resulting value does not exceed 255. The function you will write that will brighten the image is called brighten(int x) x is the ammount you are increasing all of the image pixel values by. YOU MUST make sure that your images stay in the range of 0 to 255 for each pixel.

Important: THERE may be errors in the code below that you are responsible for finding and fixing ---this is part of the work and will make you learn the SW you are given.

GO to either Gimp - photo editing tool or http://www.fine-view.com/ to download a tool to open up and display PGM files which
is the image format we are using for this project.

Click here to download a sample PGM file to work with.


Details

Introduction - Image Manipulation - Brightening

Today we will be writing an image manipulation routine to gain some valuable experience in programming with multidimensional arrays.  You will be using some open-source code from USF to do image reading from a file into a multi-dimensional array and image writting from such an array to a file.  Download the following 2 files: imageio.h and imageio.cpp . You will use the following main function and insert a loop asking the user whether they wish to brighten the image and by how much or they wish to write to a file. Use the following image x.pgm to test this program. (AS DISCUSSED in class there may be some problems in the following Main code -- to fix this you will need to read the imageio.h and imagio.cpp carefully)

#include <iostream>

#include "imageio.h"

#include <stdlib.h>

using namespace std;





int main()

{ 

    unsigned char **image;

    int rows, cols;

    unsigned char value = 10;

   

    //creates a 2D array image and fills in the values associated with

    //the pixels in the image.  Also, reads in the number of rows and

    //columns in the image and stores in the variables rows, cols. 

    read_pgm_image("image.pgm", image, rows, cols );

    

    switch ( getMenuInput() ) {

        case 1:		brighten(image, rows, cols,  value); 

                      break;  //NEED to prompt for value!!!

        case 2:		write_pgm_image("outputImage.pgm",  image, rows, cols, 

                                       "brightened image", 255);

                      break;

        default:	exit(0);

    }

    


    

    cout << "\nDone!\n\n";

    return 0;

}

 

 

Brightening function

You need to implement the following algorithm:

for (each element in the 2D array image, i) {

     i = i + value;

    if (i > 255) i = 255; //saftey check as pixel value cant be above 255

}

 

 

Deliverables

  1. Show in class to peer grader
  2. Upload code in a zipped file called code.zip to blackboard Image Array Exercise

Evaluation

  1. This exercise will be graded by a peer (fellow student) during class. You must be present on the due date of this exercise hence to get credit on it and to participate in the grading of another student's work. (Only Valid DOCUMENTED Excuse will be allowed for missed peer grading and must be approved by instructor--evaluation process to be determined by instructor)
  2. During the class session when peer grading is started, the professor will disscuss a correct solution with the class and you will use this and guidelines presented and discussed to grade the student's work.
  3. As part of this we will explore different solutions done by students and unexpected logic errors and syntax errors.
  4. Points Ranges
main function is correct and complete 15 points
brighten funciton is correct and complete 30 points
all files included in project as should and runs 5 points

 

© Lynne Grewe