Created
May 15, 2011 20:25
-
-
Save cagerton/973499 to your computer and use it in GitHub Desktop.
Edge detection in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.image.BufferedImage; | |
import java.awt.image.WritableRaster; | |
PImage input, output; | |
void setup() { | |
int width=400; | |
int height=300; | |
size(width,height); | |
output = createImage(width,height,RGB); | |
input = loadImage("car.jpg"); | |
loadPixels(); | |
// extract the BufferedImage | |
BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | |
bimage.getGraphics().drawImage(input.getImage(), 0, 0, null); | |
// run edge detection | |
CannyEdgeDetector detector = new CannyEdgeDetector(); | |
detector.setLowThreshold(0.5f); | |
detector.setHighThreshold(6f); | |
detector.setSourceImage(bimage); | |
detector.process(); | |
BufferedImage edges = detector.getEdgesImage(); | |
// build the PImage from edges | |
WritableRaster raster = edges.getRaster(); | |
raster.getDataElements(0, 0, width, height, output.pixels); | |
output.save("/tmp/edges.png"); | |
noLoop(); // Makes draw() only run once | |
} | |
void draw() { | |
image(output, 0, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment