Obama Poster Generator

While playing with the idea of hiding images-within-images (aka steganography), I realized that by applying the right thresholds in The Gimp to the 4-bit downscaled version of the image I was trying to hide, it looked sort of like the posters that President Obama used during his campaign, except without the color. Inspired, I hacked together a MATLAB script that will do a reasonable job of converting an image from normal, full color into an image consisting of a peachy color, dark navy, light blue, and red, in a style similar to the campaign posters.

% This Obama-izes an image, applying the basic four-ish color pattern
% utilized in Obama's campaign posters.

% Format is lines by columns by channels (x, y, 3)
image = imread('guitar.jpg', 'jpg');

% Downsample into five sections based on intensity, each 64 values wide
image = cast((image+1)/64, 'uint8');

% Channel 1 is red, channel 2 is green, and channel 3 is blue
for n = 1:length(image(:,1,1))
    for k = 1:length(image(1,:,1))
        if (image(n, k, 1) > 1 && image(n, k, 3) > 1)
            image(n, k, 1) = 252;
            image(n, k, 2) = 228;
            image(n, k, 3) = 166;
        elseif (image(n, k, 1) > image(n, k, 3))
            image(n, k, 1) = 217;
            image(n, k, 2) = 26;
            image(n, k, 3) = 33;
        elseif (image(n, k, 3) >= image(n, k, 1) && image(n, k, 3) > 0)
            image(n, k, 1) = 112;
            image(n, k, 2) = 151;
            image(n, k, 3) = 158;
        else
            image(n, k, 1) = 0;
            image(n, k, 2) = 52;
            image(n, k, 3) = 76;
        end
    end
end

imwrite(image, 'guitar_out.png', 'png');

The results were pretty good for a few minutes of hacking:

I had a lot of trouble finding a “universal” set of conversion rules, instead mostly looking at the output of each image and tweaking the thresholds in each test and whether to use > or >= for the last check before falling back to the dark navy color. A more sophisticated approach to the conversion process would probably yield far better results and require less tweaking to work on each image, but I was surprised by how simple generating a reasonable approximation was.

A more versatile version of this code can be found at the Improved Poster Generator.

Note: I found three of these pictures on the Internet. They are not mine and I make no claim to them. The resulting transformed images (all four) may belong to me; if so, you are free to reproduce them, but I ask that you mention where you found them.

Posted in Computer Science.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.