spore234
spore234

Reputation: 3640

medical image segmentation with cv2

I am using the MIAS data set of breast cancer mammography pictures. The data is available here: http://peipa.essex.ac.uk/pix/mias/

for example, an image looks like this:

import cv2
import numpy as np

img = cv2.imread("mdb168.pgm",0)

import matplotlib.pyplot as plt

plt.imshow(img, cmap="gray")

enter image description here

I want to remove all artifacts and unnecessary parts of the image.

To do this,I first binarize the image

ret,thresh1 = cv2.threshold(img,0,255,cv2.THRESH_BINARY)
plt.imshow(thresh1, cmap="gray")

enter image description here

use opening

kernel = np.ones((20,20),np.uint8)
opening = cv2.morphologyEx(thresh1, cv2.MORPH_OPEN, kernel)
plt.imshow(opening, cmap="gray")

enter image description here

then erosion

kernel = np.ones((120,120),np.uint8)
erosion = cv2.erode(opening,kernel,iterations = 1)
plt.imshow(erosion, cmap="gray")

enter image description here

then merge this mask with the original image

merged = cv2.bitwise_and(img, img , mask=erosion)
plt.imshow(merged, cmap="gray")

enter image description here

I am now trying to remove the pectoral muscle in the upper left area. In this publication: https://www.ncbi.nlm.nih.gov/pubmed/26742491 they use the exact same data set and do this with `seeded region growing'. However, there is no code provided and I could not find this in opencv.

I could achieve a similar result by doing dilate/erosion etc again, but I'm looking for a more generalizable solution. Also, some of these images do not show a muscle and this should be detected as well.

Upvotes: 3

Views: 4446

Answers (1)

FiReTiTi
FiReTiTi

Reputation: 5878

I would use the following approach:

  1. (optional) I would replace the opening and the erosion with an opening by reconstruction <=> erosion followed by a geodesic dilation. It will preserve the original shape, and then you will keep a bigger ROI.
  2. Convolution filter (gaussian or simple average) to smooth the image
  3. Big white top-hat in order to detect the bright zone.
  4. Then you subtract the top-hat result to the original image.

Upvotes: 1

Related Questions