Race Condition Image Batch Assignment
Contents
Motivation
Race conditions can lead to difficult bugs to find and fix. We gain experience finding them and fixing them.
Background
Pixels
The word pixel stands for Picture Element. A pixel is a small part of a picture. Pixels are the little dots that make up computer screens. When you see a low-resolution picture that is grainy, the grains you’re seeing are the pixels.
Color Models
There are many different representations of Color. These representations are called color models.
Subtractive Color Models
Some color models are subtractive. These models are useful for printing. They are subtractive because they model the subtraction of light as each color absorbs light (before what remains to bounce off into your eyes). The most common of these models is CMYK which represents Cyan, Magenta, Yellow, blacK. If you have ever changed the ink in a color printer, you have encountered CMYK cartridges. Truth be told, you don’t need the black. Essentially all of the visible spectrum of light would be absorbed printing layers of cyan, magenta, and yellow. A lot of black tends to be printed, so it is more cost effective to add to add black into the model.
Additive Color Models
Some color models are additive. These models are useful for display devices. They are additive because they model the addition of light which is thrown at your eyes.
RGB
The most common of these models is RGB which repesents Red, Green, Blue. If you have ever plugged an old device into a TV with a component video cable, that is what the separate cables are carrying: analog signal for red, green, and blue.
HSV
We will use the HSV color model which represents Hue, Saturation, Value.
This model benefits from often being easier for humans to think about and will enable us to create some compelling image filters with minimal effort. Evidence for it being easier for humans to think about can be found in most defaults for color pickers, including the one which can be found by searching on Google for color picker.
Play around with the color picker for a while and watch the hue, saturation, and value change as you interact with it. Try to isolate the saturation by dragging left to right in the rectangle component of the color picker. Isolate changes to the value by dragging up and down. Control the hue with the slider below.
Hue
Hue is cyclical. Red is usually at 0.0 and the hue changes as you go around the ring… returning back to red at 1.0.
Saturation
Full saturation is a completely “vivid” form of the color. No saturation is “dull” gray. The "saturation" dimension is sometimes labeled chroma (as it is in this image).
Value
This component is somewhat uninspiringly named: “value”. It is often called brightness or lightness, but that can be somewhat confusing since one might expect full brightness to always equate to white, which it does not.
Code To Investigate
HsvColor
public class HsvColor { private final double hue; private final double saturation; private final double value; public HsvColor(double hue, double saturation, double value) { this.hue = hue; this.saturation = saturation; this.value = value; } public double hue() { return hue; } public double saturation() { return saturation; } public double value() { return value; } }
HsvImage
SequentialImageFilter
DesaturateAllPixelFilter
DesaturateNonSkinTonePixelFilter
Code To Debug
ImageBatch
class: | ImageBatch.java | |
methods: | applyToAll | |
package: | racecondition.image.exercise | |
source folder: | student/src/main/java |
method: HsvImage[] applyToAll(HsvImage[] images, ImageFilter imageFilter, PixelFilter pixelFilter)
(parallel implementation required)
Client
class: | ImageBatchApp.java | VIZ |
package: | racecondition.image.viz | |
source folder: | student/src//java |
Testing Your Solution
Correctness
class: | _ImageBatchTestSuite.java | |
package: | racecondition.image.exercise | |
source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
file: | race-condition-image-batch-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge