def get_masks(im):
'''
Step 1: Convert into a binary image.
'''
print('step1')
binary = im < 604
# plt.imshow(binary,cmap=plt.cm.gray)
# plt.show()
'''
Step 2: Remove the blobs connected to the border of the image.
'''
print('step2')
cleared = clear_border(binary)
# plt.imshow(cleared,cmap=plt.cm.gray)
# plt.show()
'''
Step 3: Label the image.
'''
print('step3')
label_image = label(cleared)
# plt.imshow(label_image,cmap=plt.cm.gray)
# plt.show()
'''
Step 4: Keep the labels with 2 largest areas.
'''
print('step4')
areas = [r.area for r in regionprops(label_image)]
areas.sort()
if len(areas) > 2:
for region in regionprops(label_image):
if region.area < 10 and region.area > 3:
print(region.centroid,region.area)
# print(region.area)
centroid = region.centroid
plot_im(im,centroid)
# label_image[int(centroid[0]),int(centroid[1])] = 1000
# for coordinates in region.coords:
# label_image[coordinates[0], coordinates[1]] = 0
# binary = label_image > 999
# plt.imshow(binary,cmap=plt.cm.gray)
# plt.show()
'''
Step 5: Erosion operation with a disk of radius 2. This operation is
seperate the lung nodules attached to the blood vessels.
'''
# print('step5')
# selem = disk(2)
# binary = binary_erosion(binary, selem)
# plt.imshow(binary,cmap=plt.cm.gray)
# plt.show()
评论列表
文章目录