September 9, 2014
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 2×2 grid. Colors are remapped into 1 of 4 given colors, assigned by intensity thresholds in even intervals.
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
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.
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 2, trial 1|
|Part 2, trial 2|
|Part 2, trial 3|
|Output before & after “feather” implemented|
Discuss your method and results:
- For part one, the strength of my method is that it does not use excessive memory. Instead of having four different tiles exist at once, after a single tile and it’s color has been set it is copied to the correct location in the destination image, and then the thresholding happens again overwriting the existing resized tile instead of making yet another copy from the reference source image.
- My method is slightly limited as is, in that some changes to how the indexing and
- Future work, part 1: It could easily be improved to work with multiple or different definitions of numbers of tiles, though a more general method (function) would be needed to be used to run the loop of the thresholds. Similarly, it could be setup so that each tile has a reference color, and that automatic shades are chosen. For example if the input was an array of 4 colors where each entry of the array represented the base color of one tile, each tile could generate 4 brightnesses from its reference color and set those qx color variables automatically instead of manually, hard coded.
- Future work, part 2: Having completed this function, I notice that it also looks like it works similarly to a color fill (with feathering). Though not the original intention, it could be modified to compare the differences of each channel to an input reference color and then for close colors, replace that pixel color with a secondary color input. Essentially, this would be a color swapping or color changing program, for example, making a green shirt turn blue or something of that nature.
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: http://www.rapidtables.com/web/color/RGB_Color.htm
- “OpenCV Cheat sheet”: http://docs.opencv.org/opencv_cheatsheet.pdf
- API for openCV: http://docs.opencv.org/modules/core/doc/basic_structures.html#mat-copytoWork with classmates: I did not work with any other classmates for this project.