public void process( final GrayU8 input ) { // threshold the input image inputToBinary.process(input,binary); // reduce noise with some filtering BinaryImageOps.erode8(binary, 1, filtered); BinaryImageOps.dilate8(filtered, 1, binary); // Find the contour around the shapes contours = BinaryImageOps.contour(binary, ConnectRule.EIGHT,null); processImage = true; viewUpdated(); }
binary = BinaryImageOps.dilate8(binary,1, null);
public BufferedImage findRoad(BufferedImage src) { // convert into a usable format ImageFloat32 input = ConvertBufferedImage.convertFromSingle(src, null, ImageFloat32.class); ImageUInt8 binary = new ImageUInt8(input.width, input.height); ImageSInt32 blobs = new ImageSInt32(input.width, input.height); // the mean pixel value is often a reasonable threshold when creating a binary image double mean = ImageStatistics.mean(input); // create a binary image ThresholdImageOps.threshold(input, binary, (float) mean, true); // remove small blobs through erosion and dilation // The null in the input indicates that it should internally declare the work image it needs // this is less efficient, but easier to code. for (int i = 0; i < 1; i++) { binary = BinaryImageOps.erode8(binary,1, null); } for (int i = 0; i < 2; i++) { binary = BinaryImageOps.dilate8(binary,1, null); } // Detect blobs inside the binary image and assign labels to them List<Contour> blobContours = BinaryImageOps.contour(binary, ConnectRule.FOUR, blobs); int numBlobs = filterBlobsNotTouchingEdges(blobs, blobContours.size()); // Render the binary image for output and display it in a window BufferedImage dst = VisualizeBinaryData.renderLabeled(blobs, numBlobs, null); return dst; }
BinaryImageOps.dilate8(binary, 1, afterOps); break;