BinaryImageOps.dilate4(binary,1,afterOps); break; BinaryImageOps.dilate8(binary, 1, afterOps); break; BinaryImageOps.erode4(binary, 1, afterOps); break; BinaryImageOps.erode8(binary, 1, afterOps); break; BinaryImageOps.edge4(binary, afterOps); break; BinaryImageOps.edge8(binary, afterOps); break; BinaryImageOps.removePointNoise(binary, afterOps); break; BinaryImageOps.thin(binary,50,afterOps); break;
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(); }
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(); } }); }
@Override protected void detectorProcess(ImageGray input, GrayU8 binary) { // System.out.println("processing image "+count++); binaryToContour.process(binary,labeled); contours = BinaryImageOps.convertContours(binaryToContour); int minContourPixels = minimumContourSize.computeI(Math.min(input.width,input.height)); polylines.clear(); GrowQueue_I32 indices = new GrowQueue_I32(); for (int i = 0; i < contours.size(); i++) { List<Point2D_I32> contour = contours.get(i).external; if( contour.size() < minContourPixels ) continue; if( contourToPolyline.process(contour,indices) ) { List<Point2D_I32> l = new ArrayList<>(); for (int j = 0; j < indices.size; j++) { l.add( contour.get( indices.get(j))); } polylines.add(l); } } }
public boolean process(T gray) { binary.reshape(gray.width, gray.height); eroded.reshape(gray.width, gray.height); inputToBinary.process(gray,binary); // erode to make the squares separated BinaryImageOps.erode8(binary, 1, eroded); return findSeeds.process(gray, eroded); }
@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; } }
public ImageBinaryLabeledPanel(GrayS32 labelImage, int maxValues , long randSeed ) { this(); this.labelImage = labelImage; img = new BufferedImage(labelImage.getWidth(), labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); setPreferredSize(new Dimension(labelImage.getWidth(), labelImage.getHeight())); setMinimumSize(getPreferredSize()); setMaximumSize(getPreferredSize()); Random rand = new Random(randSeed); colors = BinaryImageOps.selectRandomColors(maxValues,rand); VisualizeBinaryData.renderLabeled(labelImage, colors, img); }
/** * Set the value of any blob which does not touches the top or bottom image border to zero. Then * relabel the binary image. */ private int filterBlobsNotTouchingEdges(ImageSInt32 labeled, int numLabels) { int value[] = new int[numLabels + 1]; for (int i = 0; i < value.length; i++) { value[i] = 0; } for (int x = 0; x < labeled.width; x++) { int top = labeled.startIndex + x; int bottom = labeled.startIndex + labeled.stride * (labeled.height - 1) + x; value[labeled.data[top]] = labeled.data[top]; value[labeled.data[bottom]] = labeled.data[bottom]; } int count = 1; for (int i = 0; i < value.length; i++) { if (value[i] != 0) { value[i] = count++; } } // relabel the image to remove blobs with holes inside BinaryImageOps.relabel(labeled, value); return count - 1; }
@Override protected List<Contour> getContours() { BinaryContourFinder contour = alg.getDetectorSquare().getDetector().getContourFinder(); List<Contour> contours = BinaryImageOps.convertContours(contour); return contours; }
public ImageBinaryLabeledPanel(GrayS32 labelImage, int maxValues , long randSeed ) { this(); this.labelImage = labelImage; img = new BufferedImage(labelImage.getWidth(), labelImage.getHeight(),BufferedImage.TYPE_INT_RGB); setPreferredSize(new Dimension(labelImage.getWidth(), labelImage.getHeight())); setMinimumSize(getPreferredSize()); setMaximumSize(getPreferredSize()); Random rand = new Random(randSeed); colors = BinaryImageOps.selectRandomColors(maxValues,rand); VisualizeBinaryData.renderLabeled(labelImage, colors, img); }
/** * Merges regions together and updates the provided data structures for said changes. * * @param pixelToRegion (Input/Output) Image used to convert pixel location in region ID. Modified. * @param regionMemberCount (Input/Output) List containing how many pixels belong to each region. Modified. */ public void performMerge( GrayS32 pixelToRegion , GrowQueue_I32 regionMemberCount ) { // update member counts flowIntoRootNode(regionMemberCount); // re-assign the number of the root node and trim excessive nodes from the lists setToRootNodeNewID(regionMemberCount); // change the labels in the pixelToRegion image BinaryImageOps.relabel(pixelToRegion, mergeList.data); }
/** * Finds the external contours only in the image * @param input Input binary image. Not modified. * @param rule Connectivity rule. Can be 4 or 8. 8 is more commonly used. * @return List of found contours for each blob. */ public static List<Contour> contourExternal(GrayU8 input, ConnectRule rule ) { BinaryContourFinder alg = FactoryBinaryContourFinder.linearExternal(); alg.setConnectRule(rule); alg.process(input); return convertContours(alg); }
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 protected List<Contour> getContours() { BinaryLabelContourFinder contour = detector.getDetector().getEllipseDetector().getEllipseDetector().getContourFinder(); return BinaryImageOps.convertContours(contour); }
@Override protected List<Contour> getContours() { BinaryLabelContourFinder contour = detector.getDetector().getEllipseDetector().getEllipseDetector().getContourFinder(); return BinaryImageOps.convertContours(contour); }
@Override protected List<Contour> getContours() { BinaryContourFinder contour = alg.getFindSeeds().getDetectorSquare().getDetector().getContourFinder(); return BinaryImageOps.convertContours(contour); }
List<Contour> contours = BinaryImageOps.convertContours(contour); g2.setStroke(new BasicStroke(1)); VisualizeBinaryData.render(contours, null,Color.CYAN, scale, g2);
alg.process(input,output); return convertContours(alg);
private void doProcess() { if( input == null ) return; final BufferedImage temp; if( activeAlg == 0 ) { if( previousBlur != barCanny.getBlurRadius() ) { previousBlur = barCanny.getBlurRadius(); canny = FactoryEdgeDetectors.canny(previousBlur,true, true, imageType, derivType); } double thresh = barCanny.getThreshold()/100.0; canny.process(workImage,(float)thresh*0.1f,(float)thresh,null); List<EdgeContour> contours = canny.getContours(); temp = VisualizeBinaryData.renderContours(contours,null,workImage.width,workImage.height,null); } else { // create a binary image by thresholding GThresholdImageOps.threshold(workImage, binary, barBinary.getThreshold(), barBinary.isDown()); contour.process(binary,labeled); List<Contour> contours = BinaryImageOps.convertContours(contour); temp = VisualizeBinaryData.renderContours(contours,null,0xFF1010, workImage.width,workImage.height,null); } SwingUtilities.invokeLater(new Runnable() { public void run() { panel.setImage(temp); panel.repaint(); }}); }