/** * 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); } }
/** * 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(); } }
/** * 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(); } }
if( storagePoints.sizeOfTail() <= maxContourLength ) storagePoints.addPointToTail(x - adjustX, y - adjustY);
int N = storagePoints.sizeOfTail(); if( N < minContourLength || N >= maxContourLength) storagePoints.removeTail();