ImageSegmentation Lung
ImageSegmentation Lung
Basic Idea: Change image to an image, where catchment basins are the objects you want to
segment/identify.
plt.axis('off') plt.imshow(img)
<matplotlib.image.AxesImage at 0x7fa70299f3c8>
1
Step 1 : Calculating binarization (pixel value is either 0 or 1)
plt.axis('off')
plt.imshow(thresh, cmap = 'gray')
<matplotlib.image.AxesImage at 0x7fa7029744e0>
2
# noise removal
<matplotlib.image.AxesImage at 0x7fa7028c1978>
3
fig = plt.figure(figsize = (20, 10)) # to change figsize plt.subplot(131)
plt.imshow(sure_bg, cmap = 'gray') plt.title('Sure background, dilated')
# plt.subplots_adjust(wspace = 3)
# fine tuning
# f.subplots_adjust(wspace=3)
4
1. First image above - is dilated image, which increases the object region to background. Whatever
black, is surely background.
2. Second image above - we use distance transform (For connected coins) and then threshold it, to
get the sure coins. (white is sure foreground here).
3. Third image above - we subtract the results in first and second figures to get unknown area. The
white area is unknown area.
Let’s represent sure background and sure foreground with positive integers and unknown area with
0. We use cv2.connectedDots() for this which sets background area to 0, we’ll add one after this to make
sure it does not remain 0 (as we want unknown area to be 0)
markers + 1 markers[unknown==255] = 0
<matplotlib.image.AxesImage at 0x7fa702bb5e10>
5
markers = cv2.watershed(img, markers) img[markers == -1] = [0, 255,0]
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7fa702bc13c8>