Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that you had a camera set up on a tripod and you were trying to photograph a certain scene. However, every time you took

Suppose that you had a camera set up on a tripod and you were trying to photograph a certain scene. However, every time you took the picture someone or something entered the scene and ruined the shot for you! For example, consider the 9 images presented below where attempts are being made to photograph the sculpture in the middle of the frame.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

(I will try to send the ppm Images)

If you look closely, you can see that the most of sculpture is visible in each image. The man walking only blocked part of the sculpture, and since he was in a different position in each photo, he usually blocked a different part of the sculpture each time. Might there be a way to combine all of these photos in such as to remove the man from the overall photo?

It turns out that there is using a technique called a median filter. This is a method for removing noise or a man in this case from a set of similar images.

In the median filter we compare individual pixels from each image. We start out by making the assumption that most of the pixels in each image at a specific coordinate (x, y) are same color or very close in value. These are the colors we want. Sometimes, at a particular pixel in a particular image, that pixel will be part of the tourist and that pixel will have a very different color from the other pixels at the same coordinate in the other images. These different colored values are the

noise we are looking for and trying to remove.

In order to pick the correct color for the pixel at each (x, y) coordinate, we can read the color value for that particular coordinate in all the images at the same time, placing them into an array. We can then sort those values, and pick the middle value, i.e., the median value for that list of numbers. Once we know that median value we write it out to our filtered image file. Of course we have to remember that each pixel really contains three values: one for red, one for green, and one for blue. That means for each pixel, we have to find three median values.

If we do the above process for each pixel (i.e. we do it for the red, green, and blue value in each pixel), then the final result will create a good photo without that pesky man.

You are to write a C program that inputs 9 images, applies the median filter to these images, and then writes a resultant image file to the disk with the noise removed. You have been given 9 PPM files, the image format discussed below. The images are all the same height and width. In your code you should open all the image files at the same time for reading, and then open a file for writing called image.ppm (you must use this name!). Create the proper PPM header for this output file; read the header values from one of the input files to determine the correct values. Make sure to skip the header in the other files before you read in the pixel data.

Once you at ready to read the pixel color values, read all the values for the red, green, and blue values for a single pixel from the files, one integer at a time. The first value in the first file, the first value in the second file, the first value in the third file, and so on up to the first value in the ninth file. Calculate the median, and write the result to the result image file. Continue on doing this for every red, green, and blue values for every pixel triplet in the file. Your result image should be noise (person) free!

Note that you will only ever have to store 9 integer values at a time in an array in your program you do not need to store all of the image data! Once you have inputted all 9 values representing a single color (which will be part of an RGB triplet representing a pixel), you will need to sort this data into ascending order (more on this below) and then write the median value to the output file.

You should assume that the input files are named image001.ppm, image002.ppm, . . . , image009.ppm. Example files are provided for you on the class web pages. All file input and output must be done from within your program (i.e. not from redirection on the command line). In addition a PPM file viewer (as an html file that can be loaded into a browser) is provided to allow you to view PPM images. The running of your program should produce exactly the same output as the sample run below.

You should divide your program into a series of function calls from main, each function performing, more or less, a single task (e.g. input, output, compute some value(s), etc). Your main function should be 20 lines or less of executable code (i.e. not counting declarations)! In addition you may not use any global variables (other than preprocessor definitions as needed); all data that must be shared by various functions should be declared in main and then passed to the functions as needed.

Here is a sample run using the images shown above.

image text in transcribed

PPM File Format

A PPM image file is an ASCII test file with a specified format; each file consists of the following in this order:

1. The letter P followed immediately by a magic number indicating the type of PPM file. We will only use files of type P3.

2. The width and height of the image

3. The maximum color value in the image; this will always be 255 in our data files

4. All the RGB pixel data follows as (width height) number of triplets (i.e. one RGB triplet defines one pixel)

Note that all numbers are integers, and that all values are separated by white space. Pixel data is stored in the file in row-major form.

Here is a partial example:

P3 magic number 200 200 width, height of image

18 18 122 (width x hight) #of RGB triplets

22 0 0

0 255 255

45 90 200

Sorting Data

You do not need to write a routine to sort your color data use the one provided in stdlib.h. See below for an example of how you use it.

#include #include 
int values[] = { 88, 56, 100, 2, 25 }; 
int cmpfunc (const void * a, const void * b){ return ( *(int*)a - *(int*)b ); 

}

int main(void){ int n; 
 printf("Before sorting the list is: "); for( n = 0 ; n  
 printf("%d ", values[n]); } 
 qsort(values, 5, sizeof(int), cmpfunc); 
 printf(" After sorting the list is: "); for( n = 0 ; n  
 printf("%d ", values[n]); } 
 printf(" "); 

return(0); }

E E

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions

Question

Discuss the importance of workforce planning.

Answered: 1 week ago

Question

Differentiate between a mission statement and a vision statement.

Answered: 1 week ago