Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP-- In this assignment we will create Ascii Art out of a *.ppm image. REQUIREMENTS AND EXPLANATION BELOW. C++ MAIN.CPP FILE BELOW #include #include

PLEASE HELP-- In this assignment we will create Ascii Art out of a *.ppm image. REQUIREMENTS AND EXPLANATION BELOW.
C++ image text in transcribed
image text in transcribed
MAIN.CPP FILE BELOW
#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
}
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 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 the Bordet 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[1={'',' } 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

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: 3

blur-text-image

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

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

2. Discuss various aspects of the training design process.

Answered: 1 week ago