Context: I utilize an SVM to analyze an image and find pixels of interest. After filtering out pixels of low interest (full code below), the resulting binary mask is stored to be displayed later. At the same time, I use ndimage.label
to go through the binary mask and produce a list of found patches as well as keep track of how many patches were found (number of features)
Problem/Question: The images I am working with are super high res, meaning that there are "noise" groups of pixels (smaller than 100) that are counted by ndimage.label
. This means an image that might have only 10 patches is counting 1000+ because of all these noise groups and individual pixels. Given the original binary mask and a labeled array, is there a way to modify the binary mask such that only patches of a certain size are included?
#SVM analyzes image
scoreMap = self.svmMachine.predict(inData)
scoreMap = scoreMap.reshape(origDims)
#An array with a score for each pixel is produced
self.allPixelScoreMaps[self.imageKeys[i]]['PxlScores'] = scoreMap
#print(scoreMap)
topPrct = np.percentile(scoreMap, 95)
#A binary mask is then created from the pixels of high interest
binaryMap = (scoreMap > topPrct).astype(np.int)
#The mask is then stored to be displayed later
self.allPixelScoreMaps[self.imageKeys[i]]['BinScores'] = binaryMap
labeled_array, num_features = ndimage.label(binaryMap, structure = self.labelCal)
self.allPixelScoreMaps[self.imageKeys[i]]['LabelMap'] = labeled_array
self.allPixelScoreMaps[self.imageKeys[i]]['NumFeatures'] = num_features