Example of original picture and after edge detection How do you calculate the difference between two colors? The difference between two colors (red1,green1,blue1) and (red2,green2,blue2) is the square root of ((red2 - red1)2 +(green2 - green1)2 +(blue2 - blue1)2). Exercise: 1. Write the method in the class to use this calculation to return the colorDistance Pixel difference between the current pixel color and a passed pixel. public double colorDistance(Pixel other) 2. Write the method in the class to use to look for an edge in a picture as edgeDetection Picture described above. It should compare the color at the current pixel with the pixel in the next column to the right and the pixel in the next row below. If the colors differ by more than some specified amount, this indicates that an edge has been detected and the current pixel color should be set to black. Otherwise, the current pixel is not part of an edge and its color should be set to white. public void edgeDetection(int edgeDist) You can test this with the method in testEdgeDetection PictureTester. Quick Reference DigitalPicture Interface Pixel[][] getPixels2D() // SimplePicture implemented in void explore() // SimplePicture implemented in boolean write(String fileName) // SimplePicture implemented in SimplePicture Digital Picture) Class (implements public SimplePicture() public SimplePicture(int width, int height) public SimplePicture(SimplePicture copyPicture) public SimplePicture(String fileName) public Pixel[][] getPixels2D() public void explore() public boolean write(String fileName) Picture SimplePicture) Class (extends public Picture() public Picture(int height, int width) public Picture(Picture copyPicture) public Picture(String fileName) public Pixel[][] getPixels2D() // from SimplePicture public void explore() // from SimplePicture
Example of original picture and after edge detection How do you calculate the difference between two colors? The difference between two colors (red1,green1,blue1) and (red2,green2,blue2) is the square root of ((red2 - red1)2 +(green2 - green1)2 +(blue2 - blue1)2). Exercise: 1. Write the colorDistance method in the Pixel class to use this calculation to return the difference between the current pixel color and a passed pixel. public double colorDistance(Pixel other) 2. Write the edgeDetection method in the Picture class to use to look for an edge in a picture as described above. It should compare the color at the current pixel with the pixel in the next column to the right and the pixel in the next row below. If the colors differ by more than some specified amount, this indicates that an edge has been detected and the current pixel color should be set to black. Otherwise, the current pixel is not part of an edge and its color should be set to white. public void edgeDetection(int edgeDist) You can test this with the testEdgeDetection method in PictureTester. Quick Reference DigitalPicture Interface Pixel[][] getPixels2D() // implemented in SimplePicture void explore() // implemented in SimplePicture boolean write(String fileName) // implemented in SimplePicture SimplePicture Class (implements Digital Picture) public SimplePicture() public SimplePicture(int width, int height) public SimplePicture(SimplePicture copyPicture) public SimplePicture(String fileName) public Pixel[][] getPixels2D() public void explore() public boolean write(String fileName) Picture Class (extends SimplePicture) public Picture() public Picture(int height, int width) public Picture(Picture copyPicture) public Picture(String fileName) public Pixel[][] getPixels2D() // from SimplePicture public void explore() // from SimplePicture
Picture%20Lab%20Student%20Guide%20-%20Haas.docx