Search code examples
pythonimageopencvoutline

detect outline of a object and handle the values within the outline


Currently, I'm working with some images and would like to calculate, for example, gray value, area of the pixel, etc. To do that I need to first detect the object from the image.

I tried:

img = cv2.imread(file_path, cv2.IMREAD_GRAYSCALE)
edged = cv2.Canny(img, lower, upper)

But it detects all the edges of the object. I only like to detect the outline of the object (like the picture below, red line).enter image description here

Is there any way to detect the outline of an object?


Solution

  • I suggest using the GRIP software to implement an imaging processing pipeline to do this (which I have already done for you). Processing Pipeline

    My image processing is as follows:
    Original image:
    Original_Cat

    1. Perform median filter blur (to smooth out edges of cat's fur) Blurred_Cat

    2. Perform HSV Threshold on image (to create a mask that removes the white around the cat) HSV_Thresh_Cat

    3. Apply the mask from step 2 to get the pixel values from the original cat image Masked_Cat

    Now using the image from that mask, you can calculate your grey values and pixel areas

    Here is the link to download the GRIP software

    Here is a link to all my files (including the auto-generated Python image processing pipeline)