/** * 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; }
/** * 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); }