Question: PLEASE HELP ME FIGURE OUT HOW TO CODE THIS SECTION FOR MY HOMEWORK, THERE SHOULD BE NO ADDITIONAL CODE THAT WILL BE REQUIRED. I PROVIDED

PLEASE HELP ME FIGURE OUT HOW TO CODE THIS SECTION FOR MY HOMEWORK, THERE SHOULD BE NO ADDITIONAL CODE THAT WILL BE REQUIRED. I PROVIDED A BASE THAT NEEDS TO BE JUST FILLED IN TO MAKE IT EASIER FOR YOU GUYS. AND I PROVIDED MY NOTES TOO.

#include  #include "Image.h" // REQUIRES: img points to an Image // 0 

AnImageis similar to aMatrix, but containsPixels instead of integers. EachPixelincludes three integers, which represent red, green, and blue (RGB) color components. Each component takes on an intensity value between 0 and 255. ThePixeltype is considered "Plain Old Data" (POD), which means it doesn't have a separate interface. We just use its member variables directly. Here is thePixelstruct and some examples:

struct Pixel { int r; // red int g; // green int b; // blue } (255,0,0) (0,255,0) (0,0,255)
(0,0,0) (255,255,255) (100,100,100)
(101,151,183) (124,63,63) (163,73,164)

Below is a 5x5 image and its conceptual representation as a grid of pixels.

https://eecs280staff.github.io/p2-cv/images/dog_pixels.svg

The maximum size for anImageis given by constants inImage.h. Dimensions of 0 are not allowed. To create anImage, first allocate storage and then use an initializer function. There are several initializer functions, but for now we'll just use the basic one.

Image* img = new Image; // allocate storage in dynamic memory Image_init(img, 5, 5); // initialize it as a 5x5 image 

Once anImageis initialized, it is considered valid. Now we can use any of the functions declared inImage.hto operate on it.

Pixel um_blue = { 0, 46, 98 }; Pixel um_maize = { 251, 206, 51 }; Image_fill(img, um_blue); // fill with blue // fill every other column with maize to make stripes for (int c = 0; c 

To read and write individualPixels in anImage, use theImage_get_pixelandImage_set_pixelfunctions, respectively.

The RMEs inImage.hgive a full specification of the interface for eachImagefunction.

When anImageobject is no longer needed, its storage should be deallocated with thedeleteoperator.

delete img; 

Reading and Writing Images in PPM Format

TheImagemodule also provides functions to read and writeImages from/to the PPM image format. Here's an example of anImageand its representation in PPM.

ImageImage Representation in PPM
https://eecs280staff.github.io/p2-cv/images/image7.pngP3 5 5 255 0 0 0 0 0 0 255 255 250 0 0 0 0 0 0 255 255 250 126 66 0 126 66 0 126 66 0 255 255 250 126 66 0 0 0 0 255 219 183 0 0 0 126 66 0 255 219 183 255 219 183 0 0 0 255 219 183 255 219 183 255 219 183 0 0 0 134 0 0 0 0 0 255 219 183

The PPM format begins with these elements, each separated by whitespace:

  • P3(Indicates it's a "Plain PPM file".)
  • WIDTH HEIGHT(Image width and height, separated by whitespace.)
  • 255(Max value for RGB intensities. We'll always use 255.)

This is followed by the pixels in the image, listed with each row on a separate line. A pixel is written as three integers for its RGB components in that order, separated by whitespace.

To write an image to PPM format, use theImage_printfunction that takes in astd::ostream. This can be used in conjunction with file I/O to write an image to a PPM file.TheImage_printfunction must produce a PPM using whitespace in a very specific wayso that we can usediffto compare your output PPM file against a correct PPM file. See the RME for the full details.

To create an image by reading from PPM format, use theImage_initfunction that takes in astd::istream. This can be used in conjunction with file I/O to read an image from a PPM file. Because we may be reading in images generated from programs that don't use whitespace in the same way that we do, theImage_initfunction must accommodate any kind of whitespace used to separate elements of the PPM format (if you use C++ style I/O with>>, this should be no problem). Other than variance in whitespace (not all PPM files put each row on its own line, for example), you may assume any input to this function is in valid PPM format. (Some PPM files may contain "comments", but you do not have to account for these.)

Seeappendix Afor more information on working with PPM files and programs that can be used to view or create them on various platforms.

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 Mathematics Questions!