Vous êtes sur la page 1sur 5

# TE-2101 - Lab II: Image Analysis and Manipulation1

Note: Carefully read all the pages and understand the context, the underlying concepts, and specifications before you start your design and coding. Any image is made up of pixels and the color of each pixel is defined by the value assigned to that particular pixel. In this particular problem for simplicity, we shall consider only grayscale images (http://en.wikipedia.org/wiki/Grayscale). Value of each pixel of a grayscale image ranges from 0-255 (for an eight bit encoding), where 0 corresponds to Black and 255 corresponds to White color.

I.

## Data Preparation & Generation

Randomly generate a 50 X 100 image (an array of 50 rows and 100 columns). The value of each element (pixel) should be between 0 and 255 (whole numbers only). >> Initialize the first three and last three rows and columns to 0. This would act like a black border around the image! Note: The elements (pixels) in first three and last three rows and columns shall be referred as the border elements. Store the entire image (array) into a file. Name this file as Input_image.txt Refer Note 1 in the Appendix.

## II. Data Manipulation / Processing

Contrast adjustment Read the Input.txt file into an array M x N and this is the array for us to process. For all non-border elements of this array, add the value of element at (i, j) with a value as shown below For element value <127, subtract 20 from the value. For element value >127, add 20 to the value. If the value of any element is <0 after the operation then assign the value 0 to it. If the value of any element is >255 after the operation then assign the value 255 to it.

Please refer note 3. TE2101 Lab 2 Assignment AY1213 Semester 2. Bharadwaj V, Avinash S and Srikanth A, 2013. 1
1

Store the resultant modified matrix into a file as Contrast_Image.txt Concept- It is clear that we are making the dark pixels darker and light pixel lighter. Therefore we are increasing the contrast of the image. Refer to Note 2 in the Appendix.

## III. Data Analysis and further processing

Use the following definition of image quality (a) In the Contrast_Image.txt file, Number of elements (pixel) with value 0 80: Dark_Count Number of elements (pixel) with value 175 255: Bright_Count Count of all other pixels: Balanced_Count

Criteria

Image Quality

Dark_Count > Bright_Count and Balanced_Count Balanced_Count > Dark_Count and Bright_Count Bright_Count > Dark_Count and Balanced_Count

## Dark Image Well Balanced Image Bright Image

Display the output such as The image quality is Dark OR The image quality is Well Balanced OR The Image Quality is Bright

Now consider dividing the image into 3 (more-or-less same size) zones: Area_A, Area_B and Area_C row-wise. That is, say, Area_A: Row 0 to j Area_B: Row j+1 to j+1+k Area_C: Row j+1+k+1 to 99 In each area, repeat the above Part (a) to determine the image quality. That is, for each area, declare the status like: Area A - The image quality is Dark 2

Area B - The image quality is Bright Area C - The image quality is Well Balanced Print the above status on the display screen as well as append this into Contrast_Image.txt. Display to the user a message stating that this output has also been recorded in Contrast_Image.txt file.

## Appendix: Note 1 Please find a sample input.txt [for a 15 X 10 image]

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 101 106 147 199 0 0 0 0 0 0 91 52 34 174 0 0 0 0 0 0 70 97 228 227 0 0 0 0 0 0 205 157 3 197 0 0 0 0 0 0 102 155 207 146 0 0 0 0 0 0 33 224 81 139 0 0 0 0 0 0 140 75 6 232 0 0 0 0 0 0 214 12 252 179 0 0 0 0 0 0 220 101 5 105 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Also note that the problem states clearly that the input file should contain image of size 50 X 100; above is just a sample. Code for writing a single character to a file /*Declare a file pointer*/ FILE *myFile; /*Open the file for writing*/

myFile = fopen("output.txt","w"); /*Write a number*/ fprintf(myFile, "%d", 4); /*close the file stream*/ fclose(myFile);

Note 2
Code for reading a single (first) character from a file /*Declare a file pointer to sampleMatrix.txt*/ FILE *myFile; /*number to be input*/ int ip; /*Open the file for reading*/ myFile = fopen("sampleMatrix.txt","r"); /*Read the first integer, 4, to ip*/ fscanf(myFile,"%d", &ip); /*close the file stream*/ fclose(myFile); You may need to use the above code in a loop to read the entire matrix in a row-by-row fashion. Similarly you may need to use the above (write) code for writing each output row.

Note 3
For contrast adjustment, the following is an illustration as what is expected If pixel value = 40, after contrast adjustment it become 20 If pixel value = 185, after contrast adjustment it becomes 205 If pixel value = 10, after contrast adjustment it becomes 0 If pixel value = 240, after contrast adjustment it becomes 255

FOLLOW THE GUIDELINES IN SUBMITTING YOUR REPORT REFER TO THE TEMPLATE PROVIDED.