Question: PLEASE HELPP--- C++ In this assignment we will create Ascii Art out of a *.ppm image. Code can be done in main, in the code

PLEASE HELPP--- C++

In this assignment we will create Ascii Art out of a *.ppm image. Code can be done in main, in the code you will need to write the ascii to a new file.

(If the sign_1.ppm image has anything other than numbers recopy it into that file from here: https://drive.google.com/file/d/1aX48pnRG0wW55XU3gGtEQSW1ZR2-G1IY/view?usp=sharing)

PREVIEW OF SIGN_1ppm BELOW

P3 # 8-bit ppm RGB 99 99 255 66 66 66 56 56 56 49 49 49 52 52 52 62 62 62 66 66 66 54 54 54 57 57 57 46 46 46 27 27 27 25 25 25 27 27 27 43 43 43 58 58 58 55 55 55 49 49 49 45 45 45 36 36 36 28 28 28 30 30 30 35 35 35 29 29 29 33 33 33 37 37 37 36 36 36 54 54 54 59 59 59 39 39 39 27 27 27 31 31 31 48 48 48 61 61 61 75 75 75 103 103 103 118 118 118 88 88 88 71 71 71 87 87 87 107 107 107 98 98 98 72 72 72 85 85 85 105 105 105 97 97 97 99 99 99 113 113 113 113 113 113 107 107 107 97 97 97 92 92 92 90 90 90 85 85 85 80 80 80 87 87 87 99 99 99 99 99 99

Ascii art focuses on taking a picture and recreating it using keyboard characters. By using different keyboard characters we can shade an image such that it resembles a particular picture (for example we could use a "B" for a darker pixel, a "." for a lighter pixel, and a " " for the lightest pixel of all. The following is a an ascii art image of the Mona Lisa. From afar it looks like the Mona Lisa, Looking more closely you can see that it's all letters and periods and slashes.

*.ppm is an image format like .jpg or .gif. Unlike those formats, .ppm is a much simpler file format, with no compression, where all the red, green, and blue pixel values are written as numbers from 0 to 255. This is with 0 being no color and 255 being max color. So a rgb triplet of 0,255,0 would yield a green pixel. An rgb triplet of 255,0,255 would be purple. All zeros would be black. All 255 would be white.

The simplicity of the format allows us to easily read it in in C++ and process these types of images.

Here is an example PPM image with how it's represented in data

The first value is the type of .PPM file it is (in this case it's P6, the other one is P3, for our purposes it doesn't matter). The next three values are the total width in pixels followed by the total height (2 by 3). Finally there is a number that represents the maximum value a color can have: 255. This is called 256 colors or 8 bit coloring. Then we get the values of each pixel, reading from left to right. The first pixel has an rgb value of 0,0,0 making the first pixel black. The second pixel has an rgb value of 255 255 0 making it yellow. The third pixel (now starting the second row) has a value of 255 0 0 making it red. We can actually create this picture and look at it.

If you haven't already, download the free version of Sublime Text (https://www.sublimetext.com/) and open a random text document.

Attached to this project is an image called sign_1.ppm. If you download it (by using the download button in the bottom left you should be able to display the image (if you can't display the image -- meaning you don't have software to view .ppm s on your computer which might occur because it's an old file format), drag the file into the bottom left box of this site to view it (http://paulcuth.me.uk/netpbm-viewer/).

Also open the file in sublime text and you should see the following:

P3

# 8-bit ppm RGB

99 99

255

66 66 66...

(If the sign_1.ppm image has anything other than numbers recopy it into that file from here: https://drive.google.com/file/d/1aX48pnRG0wW55XU3gGtEQSW1ZR2-G1IY/view?usp=sharing)

meaning it's 99 by 99. the first three colors you read in represent the red green and blue values for the first pixel (top left). The next three values represent the red green and blue values for the next pixel. After we read in 99 of these triplets, it's time to switch to the next row.

Requirement 1: Read in all these triplets into a 3 Dimensional Array. What are the dimensions of this array? How many For loops would you need? What would be the bounds on these for loops?

After we read in the triplet:

For every triplet we read in, we need to write out an ascii character to another file that represents that pixel. The following array is the one I used to map the average brightness to an ascii character:

char asciiArray[]={'@','%','#','*','+','=','-',':','.',' '};

This is a 11 element arrray. The darkest character is the @ sign and the lightest character is the space (' ').

So let's say the first three pixels are 255,255,255. What we want to do is first take the average of these color values to get the average brightness of the pixel, which, in this case, would be 255 --meaning the brightest possible color. And then we would want to convert this into a value between 0 and 10 (including 10). A division and casting to an integer would do the trick but I'll let you figure that out. Finally we use that number to determine the ascii character we write out.

The following code creates a file named example.txt and writes "hello world out to it. (remember to include fstream)

ofstream myfile; myfile.open ("example.txt");

myfile<<"hello world ";

Looking at main.cpp, the initial function just gets the cursor past all the header information to the first pixel value. After that, sets of 3 values are red green and blue. Read them in, do a calculation, write out an ascii character, repeat, knowing where to put the " " or endl for the next character. There is no test for this, you will know if you got it right from the picture of a stop sign in ascii characters that show up. Get started early! Homework help forum, discord chat!

Requirement 2: Have a file of ascii characters produced that reproduces the stop sign image!

Main.cpp is below

#include

#include

#include

#include

using namespace std;

void getToData(ifstream& infile);

int main(){

ifstream infile;

infile.open("sign_1.txt");

getToData(infile);

int firstRealValue;

infile>>firstRealValue;

cout<

char asciiArray[]={'@','%','#','*','+','=','-',':','.',' '};

/* ofstream myfile;

myfile.open ("example.txt");

myfile<

myfile.close();*/

}

void getToData(ifstream& infile)

{

char trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

infile>>trash;

//infile>>trash;

//infile>>trash;

//infile>>trash;

//*******Trash

//cout<<"Trash"<

}

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!