/** * Adds a point to the contour list */ private void add( int x , int y ) { labeled.data[indexLabel] = label; if( storagePoints.sizeOfTail() < maxContourSize ) { storagePoints.addPointToTail(x - 1, y - 1); } }
@Override public void loadContour(int contourID, FastQueue<Point2D_I32> storage) { alg.getExternalContours().getSet(contourID,storage); }
/** * Step 2: If the pixel below is unmarked and white then it must be an internal contour * Same behavior it the pixel in question has been labeled or not already */ private void handleStep2(GrayS32 labeled, int label) { // if the blob is not labeled and in this state it cannot be against the left side of the image if( label == 0 ) label = labeled.data[indexOut-1]; ContourPacked c = contours.get(label-1); c.internalIndexes.add( packedPoints.size() ); packedPoints.grow(); tracer.setMaxContourSize(saveInternalContours?maxContourSize:0); tracer.trace(label,x,y,false); // See if the inner contour exceeded the maximum or minimum size. If so free its points if( packedPoints.sizeOfTail() >= maxContourSize || packedPoints.sizeOfTail() < minContourSize ) { packedPoints.removeTail(); packedPoints.grow(); } }
storagePoints.reset(); ImageMiscOps.fillBorder(binary, 0, 1); int N = storagePoints.sizeOfTail(); if( N < minContourLength || N >= maxContourLength) storagePoints.removeTail(); } else { storagePoints.removeTail(); storagePoints.removeTail(); } else {
storagePoints.grow(); if( rule == ConnectRule.EIGHT ) dir = external ? 7 : 6; storagePoints.addPointToTail(x - adjustX, y - adjustY); binary.data[indexBinary] = -2; if( storagePoints.sizeOfTail() <= maxContourLength ) storagePoints.addPointToTail(x - adjustX, y - adjustY);
@Override public void writeContour(int contourID, List<Point2D_I32> storage) { alg.getExternalContours().writeOverSet(contourID,storage); }
@Override public void process(GrayU8 binary) { if(copyForPadding) { work.reshape(binary.width + 2, binary.height + 2); ImageMiscOps.copy(0, 0, 1, 1, binary.width, binary.height, binary, work); alg.process(work,1,1); } else { alg.process(binary,adjustX,adjustY); } // create the contours list contours.reset(); PackedSetsPoint2D_I32 points = alg.getExternalContours(); for( int i = 0; i < points.size(); i++ ) { ContourPacked p = contours.grow(); p.externalIndex = i; p.id = i; } }
packedPoints.reset(); contours.reset(); tracer.setInputs(binary,labeled, packedPoints);
@Override public void writeContour(int contourID, List<Point2D_I32> list) { finder.getPackedPoints().writeOverSet(contourID,list); }
/** * Step 1: If the pixel is unlabeled and the pixel above is not one, then it * must be an external contour of a newly encountered blob. */ private void handleStep1() { ContourPacked c = contours.grow(); c.reset(); c.id = contours.size(); tracer.setMaxContourSize(maxContourSize); // save the set index for this contour and declare memory for it c.externalIndex = packedPoints.size(); packedPoints.grow(); c.internalIndexes.reset(); tracer.trace(contours.size(),x,y,true); // Keep track that this was a contour, but free up all the points used in defining it if( packedPoints.sizeOfTail() >= maxContourSize || packedPoints.sizeOfTail() < minContourSize ) { packedPoints.removeTail(); packedPoints.grow(); } }
@Override public void loadContour(int contourID, FastQueue<Point2D_I32> storage) { finder.getPackedPoints().getSet(contourID,storage); }
public List<Point2D_I32> getSet(int which) { FastQueue<Point2D_I32> tmp = new FastQueue<>(Point2D_I32.class,true); getSet(which,tmp); List<Point2D_I32> output = new ArrayList<>(); output.addAll( tmp.toList() ); return output; }