Question
Operation 1: Contour. Contour Detection To perform contour detection, we will need to examine the color distance between a pixel and its neighbouring pixels. Note
Operation 1: Contour. Contour Detection
To perform contour detection, we will need to examine the color distance between a pixel and its neighbouring pixels. Note that depending on the position of a pixel in an image, it might have 3, 5, or 8 neighbouring pixels. For example, the red pixel in Figure 1 (page 1) has 3 neighbours: green, white, and a black pixel. The green pixel has 5 neighbours: red, blue, white, and 2 black. The white pixel has 8 neighbours.
The color distance between two pixels is defined as the square root of the sum of the squares of the differences between the R, G, and B components of the pixels. For pixel p, let p.red, p.green, and p.blue denote the red, green, and blue components of its color. Then, for pixels p1 and p2,
Color distance(p1,p2) =
2 (p1.red p2.red)2 + (p1.green p2.green)2 + (p1.blue p2.blue)2 (Note that this is the same definition for Euclidean distance between 2 points in the 3-dimensional
space.)
To perform contour detection for an image you will consider each entry of the 2-dimensional array storing the colors of the pixels of the image, and if for some pixel p the color distance between p and any of its neighbours is more than 65 you will change the color of the pixel to black (i.e. Color(0,0,0)); otherwise you will change the color of the pixel to white (i.e. Color(255,255,255)).
Note that the above threshold value 65 is arbitrary, but this is the value that we will use to test your implementation of this operation. Look at class InverseOperation.java to get an idea of what this class should look like. You must implement this operation in a Java class called ContourOperation.
An example input and output images for this operation is given belowStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started