Image Manipulations using JES
This is a showcase of the various image manipulation functions I've written, or worked on with SCSI Logic, from the labs I've done so far in 205.
Rose Colored Glasses
This function reduces the green and blue values of each pixel in the picture in order to give it pink overtones, and then repaints the target photo.
Better Black and White
This function turns a photo into grayscale by multiplying the RGB values of each pixel by certain weights in order to get an average of each pixel. In turn, this value is the luminance of each pixel. These new values are then applied to the existing original pixels.
Negative
Turns a photo into its negative by subtracting the RGB value of each pixel from the maximum value allowed (255, since the RGB model is an 8-bit model). JES's wrap around overflow is on by default, which prevents potential errors due to integer under/overflow.
Mirror - Bottom to Top
Mirrors the bottom half of an image by copying all the pixels from the bottom half (entire width of image, half height), and then copies it to the top half.
Shrink
This function shrinks a source image by creating a blank target image with the desired dimensions, copies every other pixel in the original photo, and then copies it to the target photo. Essentially, it samples half of the pixels from the original photo.
Collage
To create a collage, this function takes six photos of the same size and copies them to the appropriate coordinate values on the image. Additionally, it applies a random image effect from the ones previously shown before it adds the image to it. It's fun to play around with it to see how many different types of collages result because of the random image effects. The most difficult part was getting the dimensions right for each image in the collage.
Red Eye Reduction
This red eye reduction function works by calculating the "distance" between a red pixel and the pixels in a designated region. If the difference between red values is too high, then the pixel is set to the color black. Adjusting the threshold values and finding the best one depends on the image and the targeted region.
Artify
After getting all the RGB pixel values in an image, these values are then set to either red, green or blue according to which range they fall in. This causes sharp, discrete regions of color instead of continuous regions, causing the pixelated, exaggerated colorizing effect seen below.
Green Screen (chroma key)
Similar to the red eye reduction function, this function looks for pixels with values that fall within certain shades of green. If the pixel is within this range, it replaces it with a pixel/color of choice.
Thanksgiving Card
This function superimposes three images on top of another, and uses the chroma key function to make it happen. Because JES does not work with alpha channels directly, and displays transparent backgrounds as black pixels, Ryan came up with the brilliant idea to use the chroma key function to replace black pixels with the pixels from the desired source image. In fact, the leaf border is the first image copied to the canvas, and then its corresponding black pixel regions are then chroma keyed with the actual image in the middle.
Advanced Technique - Line Drawing
This function takes an image, converts it to black and white, and then calculates and compares the luminance value of each pixel in the image, along with the pixels 1 pixel to the right and below. If the difference is larger than the luminance threshold, it sets the color of the pixel to black, otherwise it turns it white. Designing the function was relatively straightforward, but I had to write the getLuminance() helper function in order to avoid code deprecation and to keep clean design in mind. Initially, my threshold values were too high and the line drawn effect was quite muted - after playing around with several values, I settled on the current value seen below as the best balance between too much "black pixel" noise, and distinct, clean lines. The most difficult part of the algorithm was ensuring that the for loops did not go out of bounds of the photo. Additionally, I thought adding the print statements was good practice for debugging.
This is a showcase of the various image manipulation functions I've written, or worked on with SCSI Logic, from the labs I've done so far in 205.
Rose Colored Glasses
This function reduces the green and blue values of each pixel in the picture in order to give it pink overtones, and then repaints the target photo.
Better Black and White
This function turns a photo into grayscale by multiplying the RGB values of each pixel by certain weights in order to get an average of each pixel. In turn, this value is the luminance of each pixel. These new values are then applied to the existing original pixels.
Negative
Turns a photo into its negative by subtracting the RGB value of each pixel from the maximum value allowed (255, since the RGB model is an 8-bit model). JES's wrap around overflow is on by default, which prevents potential errors due to integer under/overflow.
Mirror - Bottom to Top
Mirrors the bottom half of an image by copying all the pixels from the bottom half (entire width of image, half height), and then copies it to the top half.
Shrink
This function shrinks a source image by creating a blank target image with the desired dimensions, copies every other pixel in the original photo, and then copies it to the target photo. Essentially, it samples half of the pixels from the original photo.
Collage
To create a collage, this function takes six photos of the same size and copies them to the appropriate coordinate values on the image. Additionally, it applies a random image effect from the ones previously shown before it adds the image to it. It's fun to play around with it to see how many different types of collages result because of the random image effects. The most difficult part was getting the dimensions right for each image in the collage.
Red Eye Reduction
This red eye reduction function works by calculating the "distance" between a red pixel and the pixels in a designated region. If the difference between red values is too high, then the pixel is set to the color black. Adjusting the threshold values and finding the best one depends on the image and the targeted region.
Artify
After getting all the RGB pixel values in an image, these values are then set to either red, green or blue according to which range they fall in. This causes sharp, discrete regions of color instead of continuous regions, causing the pixelated, exaggerated colorizing effect seen below.
Green Screen (chroma key)
Similar to the red eye reduction function, this function looks for pixels with values that fall within certain shades of green. If the pixel is within this range, it replaces it with a pixel/color of choice.
Thanksgiving Card
This function superimposes three images on top of another, and uses the chroma key function to make it happen. Because JES does not work with alpha channels directly, and displays transparent backgrounds as black pixels, Ryan came up with the brilliant idea to use the chroma key function to replace black pixels with the pixels from the desired source image. In fact, the leaf border is the first image copied to the canvas, and then its corresponding black pixel regions are then chroma keyed with the actual image in the middle.
Advanced Technique - Line Drawing
This function takes an image, converts it to black and white, and then calculates and compares the luminance value of each pixel in the image, along with the pixels 1 pixel to the right and below. If the difference is larger than the luminance threshold, it sets the color of the pixel to black, otherwise it turns it white. Designing the function was relatively straightforward, but I had to write the getLuminance() helper function in order to avoid code deprecation and to keep clean design in mind. Initially, my threshold values were too high and the line drawn effect was quite muted - after playing around with several values, I settled on the current value seen below as the best balance between too much "black pixel" noise, and distinct, clean lines. The most difficult part of the algorithm was ensuring that the for loops did not go out of bounds of the photo. Additionally, I thought adding the print statements was good practice for debugging.
Comments
Post a Comment