I am working with CT images and trying to remove the noise. Original image as follows:
I created a mask of the region I needed and my code is as follows:
def remove_noise(image):
segmentation = morphology.dilation(image, np.ones((1, 1, 1)))
labels, label_nb = ndimage.label(segmentation)
label_count = np.bincount(labels.ravel().astype(int))#
label_count[0] = 0
mask = labels == label_count.argmax()
mask = morphology.dilation(mask, np.ones((1, 1, 1)))
mask = ndimage.morphology.binary_fill_holes(mask)
mask = morphology.dilation(mask, np.ones((1, 1, 1)))
masked_image = mask * image
return masked_image
Mask is a binary array with 0 & 1 values only, but the original image has intensities ranging from -1024 to 3071 (I don't want to normalize original image here). When I do: masked_image = mask * original_image
this is what I get (looks like intensities have changed):
But, the image I need is as follows (without the lines under the CT scan):
What am I doing wrong here? Any help would be appreciated.