6.4. Highlighting Extremes
What if we want to highlight the lightest and darkest areas of a picture? Would we highlight areas that are less than some amount from white and less than the same amount from black? Is there any color that is close to both white and black? No, we would want to replace the color at all pixels that have a distance from white or a distance from black less than some amount. We used '&&' to mean 'and' in the last program. In this program we will use '||' to mean 'or'.
Program 41. Highlight Extremes
You can use this as follows and see the result in Figure 6.12:
> String fileName = Picture.getMediaPath("butterfly1.jpg"); > Picture picture = new Picture(fileName); > picture.explore(); > picture.highlightLightAndDark(50.0,java.awt.Color.yellow); > picture.explore();
Figure 6.12. Original picture (left) and light or dark areas highlighted (right).