Image posterization resembling Obama's Hope Campaign

In my computer science 120 course, our professor gave us a project in which we have to render an image to resemble Obama's "hope" poster, where the image is posterized. Our teacher gave use an example code where an image was converted into a "ghost" image, basically the colors were inverted. The problem is I don't know how to implement the colors within the code to posterize it. Here's the code and the RGB values needed to posterize the input image:

Light blue .44, .59, .62
Navy 0, .19, .30
Dark Red .84, .10, .13
Beige .99, .89, .65

//
// Sample main() function for CS 120 project 4.
//
// Kevin Wortman, November 2012. This code is public domain.
//

#include <iostream>

#include "csufmedia.h"

using namespace std;

int main() {
// load an image to work on
load_canvas("donuts.ppm");

// These two nested loops change the color of every pixel in the
// image. In this case we invert every intensity value. This makes
// the image look ghost-like. You will need nested loops like these
// to achieve the posterize effect.
int x, y; // counter variables
for (x = 0; x < canvas_width(); x++) { // loop through every x coordinate
for (y = 0; y < canvas_height(); y++) { // and through every y coordinate

// get the red, green, and blue intensities for the pixel at
// coordinate (x, y)
double r = get_red(x, y),
g = get_green(x, y),
b = get_blue(x, y);

// compute new RGB intensities
double new_r = 1 - r, // Inversion. You will need different code here
new_g = 1 - g, // to do posterization.
new_b = 1 - b;

// Update the color of the pixel in the canvas.
set_pixel(x, y, new_r, new_g, new_b);
}
}

// Example of drawing a rectangle.
rectangle(10, 10, // top-left corner: (10, 10)
20, // width: 20 pixels
40, // height: 40 pixels
1, 0, 0); // RGB: 1, 0, 0 (red)

// Example of drawing a semicircle.
vertical_semicircle(50, 10, // top-left corner: (50, 10)
20, // inner radius: 20 pixels
25, // outer radius: 25 pixels
true, // make it rightward not leftward
0, 1, 0); // RGB: 0, 1, 0 (green)

// Save the canvas into a new PPM file.
save_canvas("ghost.ppm");

return 0;
}

Google tells me that posterization means reducing the number of colors into an image.
Since you have a list of colors to use, I suppose you have to replace the color of each pixel of the image with the color of your list that is closest to it.

All you have to figure out is how to determine for each pixel which color of your list should be used.
Last edited on
I'm really lost. could you maybe help me by making some code?
You have to replace the computation of new_r, new_g and new_b with your own code.

That code should, for any pixel color (r,g,b), compute the new color (new_r,new_g,new_b) as one of the four authorized colors (light blue, navy dark red, beige).

What you have to do is determine a criterion that will tell you which of the four colors to use.
well it doesnt matter. we finished. you didnt help much. its okay though. all obama's fault. fricken communist! idiots shouldve voted for romney! have fun living in the united states of china!
help me out then!!? :D
^
cpscnewb i said ill show you how to do everything but the posterization if we can make a trade?
you didnt help much.

I helped, I just didn't write it for you.
Topic archived. No new replies allowed.