OpenCV Segmentation of Largest contour | opencv segmentation contour
Hi,Thismightbeabittoo"general"question,buthowdoIperformGRAYSCALEimagesegmentationandkeepthelargestcontour?Iamtryingtoremovebackgroundnoise(i.e.labels)frombreastmammograms,butIamnotsuccessful.Hereistheoriginalimage:First,IappliedAGCWDalgorithm(basedonpaper"EfficientContrastEnhancementUsingAdaptiveGammaCorrectionWithWeightingDistribution")inordertogetbettercontrastoftheimagepixels,likeso:Afterwards,Itriedexecutingfollowingsteps:ImagesegmentationusingOpenCVsKMeansclusteringalgorithm:enhanced_im...
Hi,
This might be a bit too "general" question, but how do I perform GRAYSCALE image segmentation and keep the largest contour? I am trying to remove background noise (i.e. labels) from breast mammograms, but I am not successful. Here is the original image:
First, I applied AGCWD algorithm (based on paper "Efficient Contrast Enhancement Using Adaptive Gamma Correction With Weighting Distribution") in order to get better contrast of the image pixels, like so:
Afterwards, I tried executing following steps: Image segmentation using OpenCVs KMeans clustering algorithm:
enhanced_image_cpy = enhanced_image.copy() reshaped_image = np.float32(enhanced_image_cpy.reshape(-1, 1)) number_of_clusters = 10 stop_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.1) ret, labels, clusters = cv2.kmeans(reshaped_image, number_of_clusters, None, stop_criteria, 10, cv2.KMEANS_RANDOM_CENTERS) clusters = np.uint8(clusters)Canny Edge Detection: