Question: Need a program in C++ that will read in RGB values from a dat file manipulate the values and outfile the values to another dat

Need a program in C++ that will read in RGB values from a dat file manipulate the values and outfile the values to another dat file by use of an array of structs and a loop that will store the values. Then a function to manipulate the values, then finally another loop that will outfile the information to another file. Please answer in c++ and please do not make it too complicated I would like to use it as a reference.

ADT Program- Image Manipulation The purpose of this program is to gain experience with traversing and manipulating 2D arrays, and using an Abstract Data Type (struct). An image is a 2D array of pixels, with each pixel containing an int from 0-255

representing the red, green, and blue colors. Images can be stored as PPM files, which contain the image format at the very top, then the width and height, then the max value for a color, and finally a string of the RGB values for each pixel separated by spaces. For example, a grayscale PGM

The file type header for our color PPM files will be P3. We can create a struct to hold the red, green, and blue values of each pixel, and then create a 2D array of the structs to hold the image data. We can then manipulate the data in the array to create a modified image.

1. Go to the ADT Program folder in D2L and choose one image to work with. I have provided several examples of images and their PPM files you can choose from. You only need one.

2. Download the image file and the corresponding .dat file. A .dat file is just a text file that holds data. The filetype could also have been .txt; it does not matter.

These files are PPM P3 image files, which means the image data is stored in ASCII plain text, so we can read in and work with the numbers.

3. Upload the image file and .dat file into your working folder. For example, if you are working in Repl.it, upload them as files into your repl.

You dont really need to do anything with the image file in your code, it is just for reference. 4. In your C++ file, include a heading in a comment block that includes your name (and partner name if you work with someone), date, and a short description of your program.

5. You have to create a struct that will hold three integers, one for each RGB value.

6. You have to create a 2D array large enough to hold your image data. Determine this by reading it in from the .dat input file. Remember there will be a P3 at the top of your input file. That tells the PPM viewer we are giving it RGB data in ASCII plain text. Dont forget to read in this value, so you can get the image width and height stored next

The data type for the array will be the struct you created! Remember, this program is about writing an array of structs. There is a code example of writing a 1D array of structs in D2L under Week 2 Thursday Struct Code Examples Struct Example Count Words.

7. Write a loop that will read in all the remaining values and store them in your array in order. For example, the first number will be the red value for the pixel stored at [0][0] in your array, the second number will be the green value for [0][0], the third number is [0][0] blue, etc.

8. You have to write a function that will manipulate the image in some way. This means you need to pass in the array as a parameter. Choose one of the manipulations listed in the instructions, or message me if you want to try something different.

9. Write a loop that will traverse your new, modified array and write the data to an output file. The output file can be named with a .dat, .txt., or .ppm file extension. Any should work. Remember that the first line of a PPM file should say P3, so the image viewer knows what type of data you are giving it. Remember that the second line of a PPM file should give the image size. You should already have these stored from your input file. Remember that the third line of a PPM file should give the max value, in our case 255. After this heading information, write out the data from your array, separated with spaces.

Flip the image vertically (swap the order of the image rows)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!