private synchronized void performWork() { if( filter1 == null || filter2 == null ) return; GThresholdImageOps.threshold(imageInput, imageBinary, selectThresh.getThreshold(), selectThresh.isDown()); filter1.process(imageBinary,imageOutput1); filter2.process(imageOutput1,imageOutput2); List<Contour> found = BinaryImageOps.contour(imageOutput2, connectRule, imageLabeled); if( colors == null || colors.length <= found.size() ) colors = BinaryImageOps.selectRandomColors(found.size(),rand); SwingUtilities.invokeLater(new Runnable() { public void run() { if (work == null || work.getWidth() != imageInput.width || work.getHeight() != imageInput.height) { work = new BufferedImage(imageInput.width, imageInput.height, BufferedImage.TYPE_INT_BGR); } renderVisualizeImage(); gui.setImage(work); gui.setPreferredSize(new Dimension(imageInput.width, imageInput.height)); processedImage = true; gui.repaint(); } }); }
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(); }
List<Contour> blobContours = BinaryImageOps.contour(binary, ConnectRule.FOUR, blobs);
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; }
@Override public void process(GrayU8 input) { // Select a reasonable threshold double mean = GThresholdImageOps.computeOtsu(input,0,255); // create a binary image by thresholding ThresholdImageOps.threshold(input, binary, (int)mean, down); // reduce noise with some filtering BinaryImageOps.removePointNoise(binary, filtered1); // draw binary image for output if( showBinary ) { VisualizeImageData.binaryToBitmap(filtered1, false, bitmap, bitmapTmp); } else { ConvertBitmap.boofToBitmap(input,bitmap,bitmapTmp); } // draw the ellipses findContours.process(filtered1,contourOutput); List<Contour> contours = BinaryImageOps.contour(filtered1, ConnectRule.EIGHT,null); resetShapes(); for (Contour contour : contours) { List<Point2D_I32> points = contour.external; if (points.size() < 20) continue; fitShape(points); } finalizeShapes(); visualizationPending = true; } }