How to do Edge Detection
This how-to demonstrates how to do edge detection using Java and Marvin. First, use static import for MarvinPluginCollection class to have access to its static methods directly on your class. import static marvin.MarvinPluginCollection.*; There are different algorithms for edge detection, some provided by Marvin. First, the input image is loaded and another image object is created for the output: MarvinImage image = MarvinImageIO.loadImage("./res/mickey_britto.jpg"); MarvinImage imageOut = new MarvinImage(image.getWidth(), image.getHeight()); input image: Approaches:Prewitt:prewitt(image, imageOut); MarvinImageIO.saveImage(imageOut, "./res/mickey_britto_prewitt.jpg"); Sobel: imageOut.clear(0xFF000000); sobel(image, imageOut); MarvinImageIO.saveImage(imageOut, "./res/mickey_britto_sobel.jpg"); Roberts: imageOut.clear(0xFF000000); roberts(image, imageOut); MarvinImageIO.saveImage(imageOut, "./res/mickey_britto_roberts.jpg"); Black lines:
thresholding(...) and invertColors(...) can used to obtain just the edges in a single color: thresholding(imageOut, 40); invertColors(imageOut); MarvinImageIO.saveImage(imageOut, "./res/mickey_britto_black_lines.jpg"); Was this how-to helpful? Share it:
Do not you know how to setup Marvin? Read how to develop your First Application. |
||