CSN 455 - Image Processing	Programming Assignment 1 - Due Thursday, Feb. 21

For this assignment, you will implement an image enhancement program which allows a user to choose one of a minimum of three enhancement techniques. You may implement any three of the following:

- digital negative transformation ( ng )

- thresholding with specified threshold value ( th )

- contrast stretching to minimum and maximum values contained in the image (cs)

- contrast stretching with specified maximum and minimum values (cm)

- contrast stretching with percentage of pixels to be discarded from the low end and high end of the

intensity distribution (cp)

- square root transformation (sq)

- histogram equalization (he)

You program should be named enhance, and should have the following command line format:

enhance image.pgm enhanced_image.pgm -code [optional arguments]

where code is a two letter abbreviation corresponding to one of the above enhancement techniques.

Please create a directory called IP in your home directory on eckserver . In the IP directory, create a subdirectory called ENHANCE. Copy the files from / usr /local/classes/ csn455 /ENHANCE as a start for your program to the ENHANCE subdirectory. The files are:

enhance.cc

image_io.c

image_io.h

makefile

Copy the files to your directory, type make to compile and link the program. To run the program type:
enhance /us r/local/images /camera.pg m bright_camera.pg m 2

(You should see an xv window with the display of the camera image, and to its right another xv window with the display of a brightened camera image.)

This assignment can be accomplished by adding code or modifying existing code in the file called enhance.c c. None of the other files should be modified and no new or additional source files should be created

/* image_io.h - INCLUDE FILE FOR IMAGE_IO.C */

struct imagestr {

int rows, cols, depth;

unsigned char **data;

unsigned char **r;

unsigned char **g;

unsigned char **b;

};

typedef struct imagestr image;

unsigned char** alloc_data (int rows, int cols);

image* alloc_imstruct ();

image* read_pnm_file (char *filename);

void write_pnm_file (image* im, char *filename, char *comment);

// brighten.cc - an example image processing program in C++

#include < iostream >

#include < stdlib.h >

#include <string>

#include " image_io.h "

using namespace std;

// function prototypes

image * brighten_image (image * dark_image , int factor);

int main(int argc , char * argv []){

image * imagein , * newimage ;

int factor;

string xvcommand ;

// This checks for the correct number of arguments on the command line

if ( argc < 4){

cout << "usage: enhance inputfile outputfile brighten_factor \n ";

exit(1);

}

// read imput image

imagein = read_pnm_file ( argv[1 ]);

// pop an xv window and display input image

xvcommand = "xv " + string( argv[1 ]) + " - ge +25+25&";

system( xvcommand.c_str ());

// create new brighter image of same size

factor = atoi ( argv[3 ]);	// convert ascii number to integer

newimage = brighten_image ( imagein , factor);

// save new image

write_pnm_file ( newimage , argv[2 ], "doubled pixel values");

// pop an xv window and display transformed image

xvcommand = "xv " + string( argv[2 ]) + " - ge +525+25&";

system( xvcommand.c_str ());

return 0;

}

/*----------------------------------------------------------------

BRIGHTEN IMAGE

this function creates a brightened version of an image

by multiplying the pixel value of each pixel in the array

by some input factor. If the doubled value exceeds 255, the

increased value is maxxed at 255. The function returns the

new image as its result.

INPUTS: dark_image - a pointer to an image stucture containing

the image to be brightened

factor - the brightening factor

----------------------------------------------------------------*/

image * brighten_image (image * dark_image , int factor)

{

int i,j , val;

int rows = dark_image ->rows;

int cols = dark_image ->cols;

unsigned char **data = dark_image ->data;

unsigned char ** newdata ;

image * newim ;

// allocate memory for the image struct and its data

newim = alloc_imstruct ();

newdata = alloc_data (rows, cols);

// compute newdata by multiplying each pixel in data by factor

for ( i =0; i<rows ; i ++){

for (j=0; j<cols ; j++){

val = data[i ][j] * factor;

if (val > 255) val = 255;

newdata[i ][j] = (unsigned char)val;

}

}

newim ->rows=rows;

newim ->cols = cols;

newim ->data = newdata ;

return( newim );

}