pythonpython-2.7opencvscikit-imagex-ray

Canny Operation on Image


I want in the image below to (by using Python):

1.) Find the contours of the bones (only the sides will do)

2.) Recognize and draw all the contours.

It could look something like this:

A better contour is even good. I am not entirely sure as to how I could tackle this,

The gradient of the image is:


Solution

  • A initial way of approaching this would be using canny edge detection using the right threshold values and then find the contours.

    import cv2
    
    # Load the image
    img = cv2.imread("/home/tribta/Desktop/feet.png")
    
    # Find the contours
    imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(img,60,200)
    im2, contours, hierarchy = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    
    hierarchy = hierarchy[0] # get the actual inner list of hierarchy descriptions
    
    # For each contour, find the bounding rectangle and draw it
    cv2.drawContours(img, contours, -1, (0,255,0), 3)
    
    # Finally show the image
    cv2.imshow('img',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    Then you could add some biomedical processing criteria to distinguish the different contours and verify if it is really a bone.