背景:我利用 SVM 分析图像并找到感兴趣的像素。过滤掉不感兴趣的像素(下面的完整代码)后,将生成的二进制掩码存储起来以供稍后显示。同时,我使用ndimage.label
二进制掩码生成找到的补丁列表,并跟踪找到的补丁数量(特征数量)
问题/问题:我正在使用的图像是超高分辨率的,这意味着有“噪声”像素组(小于 100)被计算为ndimage.label
. 这意味着由于所有这些噪声组和单个像素,可能只有 10 个补丁的图像计数为 1000+。给定原始的二进制掩码和标记的数组,有没有办法修改二进制掩码,以便只包含一定大小的补丁?
#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