Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

15.16 Project 6: Gas Cam Overview You are installing a camera at this gas station, but the quality is too good. Also, it's in color.

15.16 Project 6: Gas Cam Overview You are installing a camera at this gas station, but the quality is too good. Also, it's in color. Neither of these traits are acceptable. Gas station cams are supposed to be poor quality and in black and white (something about smaller storage space). Lucky for you, the camera is periodically generating ppm (portable pixmap) image files, so we can easily manipulate the image. Your job is to write a program that turns these colorful, high quality gas cam images into black and white, poor quality gas cam images. Background Information on PPM and PGM files Pictures can be stored in many formats. You've probably heard of the more common ones, such as jpeg (from the Joint Photographic Experts Group) and gif (Graphics Interchange Format). The vast majority of these formats store the image data in a binary file. There is one format, ppm (portable pixmap) that uses ASCII files to store an image. These ppm files consist of header information and then a long string of numbers representing the red, green, and blue components of each pixel in the image. It is not widely used. Since the images are stored in ASCII, they are much larger than other (binary) formats. However, as these files are (readable) ASCII data, they are a good format for an introductory programming class. The ppm format that is used for this project is shown below. The very first line is always P3. After that, you have three values (width, height, max-color) that can be on a single line or separate lines. Finally, you have the actual RGB values (three integers) for each pixel in the image. There are 3*width*height integers representing width*height pixels. P3 width-in-pixels height-in-pixels maximum-color-value pix-1-1-red pix-1-1-green pix-1-1-blue pix-1-2-red pix-1-2-green pix-1-2-blue ... pix-2-1-red pix-2-1-green pix-2-1-blue pix-2-2-red pix-2-2-green pix-2-2-blue ... ... pix N-1-red pix-N-1-green pix-N-1-blue pix-N-2-red pix-N-2-green pix-N-2-blue ... A very tiny ppm file that is four pixels wide and six pixels tall, with the top two rows the color red, the middle two rows the color green, and the bottom two rows the color blue, is also shown below. P3 4 6 255 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 0 0 255 This program will be manipulating ppm image files. In order to see if your program is working properly, you need to be able to view these images. Your system might (or might not) have a viewer that supports ppm images. If not, then download the free program GIMP (GNU Image Manipulation Program). Download GIMP here. You can use GIMP to convert additional pictures into ppm format for testing if you wish. Simply load an existing image that you have into GIMP and then select the "Export As" option and a file type of PPM image. Make sure to click ASCII when asked how to export. When you use ppm to convert an image into a ppm file, it puts a comment on the second line. You need to delete that comment line, as our program does not handle comments in ppm files. The pgm image file is very similar to the ppm image file. The difference is the magic identifier is P2 and there is only one integer to represent each pixel. An example is shown below. P2 width-in-pixels height-in-pixels maximum-value pix-1-1-intensity pix-1-2-intensity pix-1-3-intensity ... pix-2-1-intensity pix-2-2-intensity pix-2-3-intensity ... ... pix-N-1-intensity pix-N-2-intensity pix-N-3-intensity ... For a grayscale image, each pixel has only one grayscale intensity that usually ranges from 0 through 255. A pixel with a value of 0 is black (absence of light) and a pixel with a value of 255 is white (all light). An example of a pgm image file is shown below. This image is seven (7) columns wide and six (6) rows high. It has 255 as the maximum grayscale intensity that can appear in the image pixel data. This image has a black (intensity=0) border of one pixel wide and a white (intensity=255) interior. P2 7 6 255 0 0 0 0 0 0 0 0 255 255 255 255 255 0 0 255 255 255 255 255 0 0 255 255 255 255 255 0 0 255 255 255 255 255 0 0 0 0 0 0 0 0 Implementation The program will accept the following command line arguments: manipulation command: copy-ppm - Copy the input ppm into another file copy-pgm - Copy the input pgm into another file grayscale - The input will always be ppm and the output will always be pgm shrink - The input will always be pgm and the output will always be pgm input image filename output image filename Example execution commands: ./a.out copy-ppm hq_color.ppm hq_color_copy.ppm ./a.out copy-pgm hq_gray.ppm hq_gray_copy.pgm ./a.out grayscale hq_color.ppm hq_gray.pgm ./a.out shrink hq_gray.pgm lq_gray.pgm There are three files. Templates can be downloaded below. You need to complete image.c. You may write additional functions in image.c if you wish, but do not modify image.h or interface.c. interface.c - the user interface. It prompts the user for an action and performs that action by calling the corresponding function. image.h - definitions of structs and the signatures of the functions to implement. image.c - implementation of the functions listed in .h. Your job is to complete the functions in this file. Compile with gcc -Wall interface.c image.c Just like you can include C libraries like stdio.h in your code, you can also include libraries you have written. Signatures go in the .h file (header file), which is included in other files that use the library with #include "library.h". The implementation of the library goes in the .c file, which is included in the compile command. In the .h file, the include guard below ensures the code is not duplicated when compiled. #ifndef X #define X code #endif Algorithms: grayscale - Convert an RGB pixel to grayscale by averaging the three RGB values into a single value. Use the results of integer division when you average values. Do not use floor, ceiling, or round. shrink - Our algorithm for shrinking an image cuts the width and height of an image in half, thus decreasing the actual size by a factor of four. When shrinking an image, you generate a new pixel that is the average of the grayscale values for each of the pixels in the 2x2 block you are shrinking. See visual below involving a ppm. If your original image has an odd number of rows (or columns), just ignore the last row (or column). For example, if your original image had 9 rows, your new image would only have 4 rows and would be constructed from data found in the first eight rows of the original image (the 9th row is ignored). Notes: Submit to the tester project in Submit mode for grading to verify format and that it passes the example cases. You can assume all files that exist will be in the proper format. When you use real images, ppm and pgm files get big quickly. For example, a regular camera photo converted to one of them might contain over 50 million characters. This makes debugging on real files problematic. However, if you use really small files then it is hard to see them using GIMP or other image display software without zooming in really close; they are just too small. One suggested option for debugging is to create a very small image, such as the ones shown previously. You can examine the output of these files by hand. Once you think your algorithm is working properly, try it on large files. Before tackling grayscale and shrink, we recommend you get copy-ppm and copy-pgm working. The copy commands require you to be able to read and write ppm and pgm image files. Once you get your input and output functions working, then focus on grayscale and shrink. Whitespace does not matter when creating the output image files; it will be ignored by the grader. Try and solve shrink on paper first. Think about how you need to modify i and j and access the blocks of data. How many rows and cols will the resulting image be? You will need to use malloc for the structs and 2D arrays. Remember: every malloc needs a free. Accessing pixel data can be done with code like the following: pImagePPM->pixels[i][j].red = 255;

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_step_2

Step: 3

blur-text-image_step3

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

More Books

Students also viewed these Accounting questions

Question

=+five ways to use research results

Answered: 1 week ago

Question

=+. How does a conclusion differ from a recommendation? [LO-2]

Answered: 1 week ago