Basic image processing

CS 585 HW 1
Patrick Crawford
Worked alone
September 9, 2014

Problem Definition

Part 1:

The first task required making a program that creates the Warhol effect on an image. This effect creates an image of the same size as the original, but where the original frame is shrunk and tiled in a 2x2 grid. Colors are remapped into 1 of 4 given colors, assigned by intensity thresholds in even intervals.

Part 2:

The second task was to create another effect. I chose to create a "feathered background threshold" filter. Any pixel below the threshold will be recolored to the input color, but pixels around the edge of the threshold are feathered or "eased" between the source image color and the replacement color. In other words, only darker colors are replaced but with a smooth transition, how smooth being defined by an input.

These tasks are useful because they outlines the fundamentals of working with images and manipulation of colors and matrixes, which forms the base of more complex processing.

The difficulties are learning how to work with matrix objects and the processing of scaling images, moving one matrix into another, and being able to operate on different color schemes (BGR and B/W).

Method and Implementation

Part 1:

I started by making a single reference resized image from the source, halved in both dimensions. This is kept untouched or modified so resizing only happens once. For each quadrant of the image, a deep copy of that reference is made. Then, I set the q1, q2, q3, and q4 colors (q for quarter of the color range) for the first tile. Thereafter, two loops go through the entire single tile image and check the thresholds of for each range and assign the according color. Afterwards the completed tile is copied to the destination matrix, and the process is repeated for the other tile locations and other sets of hard-coded colors.

Part 2:

The program starts by taking the input image and initializing the output destination image as a copy of the source image, since many of the pixels should remain the same and unmodified (those above the threshold, or lighter than the input intensity). Then, the function loops through and checks if any given pixel falls into one fo three categories: above the threshold + half of the feather amount(no change), below the threshold - half of feather amount (change to input color), or within the threshold feather range (weighted mix of original color and input color)


The functions used were the ones given (in name, that is). I only brought in the conversion function that turned a 3-color channel image into a gray-scale image. I considered making a second function that would do the repeat loop for applying the color for each tile of the image instead of copying the code for the loop multiple times, but I decided the overhead and cumbersome need to transfer so many variables by reference didn't make sense for the context.

void myWarhol(Mat& src, Mat& dst):
The only input is the src image, a color 3-channel image. The out put dst is the output matrix

void myModification(Mat& src, Mat& dst, int thres, int feather, Vec3b bg):
src and dst are the input/output, 3-channel color images respectively. thres is the threshold, between 0 and 255, feather is the feather amount, any size functions, and bg is the background color, 3-channels.


I approached the assignment by breaking down and testing what I saw to be the primary things needing to be done. I first looking into being able to scale (and show and save) an image to a general sized, then I moved into determining how to set a color as opposed to just copying an existing color. For that I did tests where I just filled the entire image with one color on the resized, individual tile. The final step was essentially figuring out how to use copyTo to merge the images all into one, and with the correct colorspace. Though I didn't quite understand the syntax at first, once I got a basic example of how to place the tile somewhere within the output image (initialized to zero) it was fairly straightforward to map the four different tiles in the correct location.


List your experimental results. Provide examples of input images and output images. If relevant, you may provide images showing any intermediate steps


Trial Source Image Result Image
Part 1
Part 2, trial 1
Part 2, trial 2
Part 2, trial 3
Output before & after "feather" implemented


Discuss your method and results:


Based on your discussion, what are your conclusions? What is your main message?

I had some difficulty getting started and used to working with the different color spaces. The basic operations of changing matrix sizes and copying some values from one place to another I see to be the powerhouse of image processing and a very useful thing to know how to leverage.

Credits and Bibliography

  • Easy RGB color picker:
  • "OpenCV Cheat sheet":
  • API for openCV:

    Work with classmates: I did not work with any other classmates for this project.