Difference between revisions of "ForkLoop Images Assignment"
| Line 14: | Line 14: | ||
class [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html DefaultHsvImage] implements HsvImage | class [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html DefaultHsvImage] implements HsvImage | ||
| − | : [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html#%3Cinit%3E(edu.wustl.cse231s.color.HsvColor%5B%5D%5B%5D) < | + | : [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html#%3Cinit%3E(edu.wustl.cse231s.color.HsvColor%5B%5D%5B%5D) <nowiki>DefaultHsvImage(HsvColor[][] pixels)</nowiki>] |
| − | : [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html#%3Cinit%3E(java.util.List) < | + | : [https://www.cse.wustl.edu/~dennis.cosgrove/courses/cse231/current/apidocs/edu/wustl/cse231s/image/impl/DefaultHsvImage.html#%3Cinit%3E(java.util.List) <nowiki>DefaultHsvImage(List<HsvColor[]> pixels)</nowiki>] |
==PixelFiler== | ==PixelFiler== | ||
Revision as of 05:49, 3 February 2023
Contents
Motivation
We gain experience using a parallel fork loop. Image processing often presents the opportunity for a lot of parallelism. Here we will operate on a single image, making a parallel task for each row.
Background
Revisit the Image Batch Race Condition Exercise's Background section for information on pixels and images.
HsvColor
class HsvColor
HsvImage
interface HsvImage
interface ImmutableHsvImage extends HsvImage
class DefaultImmutableHsvImage implements ImmutableHsvImage
DefaultHsvImage
DefaultHsvImage implements HsvImage so instances of DefaultHsvImage can serve wherever you need an HsvImage. DefaultHsvImage provides all of the methods required to be an HsvImage and provides two noteworthy constructors outlined below:
class DefaultHsvImage implements HsvImage
PixelFiler
interface PixelFilter extends UnaryOperator<HsvColor>
Code To Investigate
Image Batch Race Condition Exercise
Image Batch Race Condition Code To Investigate
PixelFilters
Our Image Filter will apply a PixelFilter to every pixel in a specified image.
Some example pixel filters have been provided which use named classes, anonymous classes, and lambdas:
| class PixelFilters |
|---|
public class PixelFilters {
private static class HueSettingPixelFilter implements PixelFilter {
private final double hue;
public HueSettingPixelFilter(double hue) {
this.hue = hue;
}
@Override
public HsvColor apply(HsvColor src) {
double saturation = src.saturation();
double value = src.value();
return new HsvColor(hue, saturation, value);
}
}
public static PixelFilter hueSettingPixelFilterOf(double hue) {
// return new instance of named class HueSettingPixelFilter
return new HueSettingPixelFilter(hue);
}
public static PixelFilter hueAdjustingPixelFilterOf(double deltaHue) {
// return new instance of anonymous class
return new PixelFilter() {
@Override
public HsvColor apply(HsvColor src) {
double hue = src.hue();
double saturation = src.saturation();
double value = src.value();
return new HsvColor(hue + deltaHue, saturation, value);
}
};
}
public static PixelFilter saturationAdjustingPixelFilterOf(double deltaSaturation) {
// return anonymous function (also known as a lambda) with parameter type
return (HsvColor src) -> {
double hue = src.hue();
double saturation = src.saturation();
double value = src.value();
return new HsvColor(hue, saturation + deltaSaturation, value);
};
}
public static PixelFilter valueAdjustingPixelFilterOf(double deltaValue) {
// return anonymous function (also known as a lambda) without parameter type
return src -> {
double hue = src.hue();
double saturation = src.saturation();
double value = src.value();
return new HsvColor(hue, saturation, value + deltaValue);
};
}
}
|
Code To Implement
ParallelTaskPerRowImageFilter
| class: | ParallelTaskPerRowImageFilter.java | |
| methods: | apply | |
| package: | imagefilter.exercise | |
| source folder: | student/src/main/java |
apply
method: public HsvImage apply(HsvImage src, PixelFilter pixelFilter)
(parallel implementation required)
To complete this method we must return a new instance of the interface HsvImage. The provided class DefaultHsvImage implements HsvImage so should serve well.
Nicely, DefaultHsvImage provides both:
- a constructor which takes an List<HsvColor[]> and,
- another constructor which takes an HsvColor[][].
These two constructors match up well with the two different return types of the many incantations of join_fork_loop:
where R is the return type of the TaskFunction<T, R> passed to the join_fork_loop.
What should the return type from the this TaskFunction be?
Visualization
| class: | ImageFilterApp.java | VIZ |
| package: | imagefilter.viz | |
| source folder: | student/src/main/java |
Testing Your Solution
| class: | __ParallelTaskPerRowImageFilterTestSuite.java | |
| package: | imagefilter.exercise | |
| source folder: | testing/src/test/java |
Pledge, Acknowledgments, Citations
| file: | exercise-fork-loop-images-pledge-acknowledgments-citations.txt |
More info about the Honor Pledge