Skip to content

Contour Detection on Grey Scale Images

Vlad-Adrian Moglan edited this page Jun 22, 2016 · 5 revisions

Description

Contour detection is an operation that helps detecting important elements on a grey scale image.

Function Header

namespace cloud_object_segmentation
{
    namespace image_processing
    {
        /**
         * @brief detect_contour is a function that detects contours in a depth image
         * @param gs_img is the image to detect the contours of
         * @param hist_num_cls is the number of histogram classes
         * @return the contours in the depth image
         */
        image_greyscale detect_contours(cloud_object_segmentation::image_greyscale gs_img, int hist_num_cls);
    }
}

How-To

This sample shows how to detect contours on a .pgm image:

#include <cos/tools/image_processing.h>
#include <cos/io/image_io.h>

using namespace cloud_object_segmentation;

int main(int argc, char *argv[])
{
    // reading grey scale image from file, with the second parameter being the maximum grey value
    image_greyscale gs_img = io::import_greyscale_image("C:/Documents/Depth_Images/gs_img_sample.pgm", 255);

    // detecting contours and writing to file
    image_greyscale result_image = image_processing::detect_contours(gs_img, 255);
    io::export_greyscale_image("C:/Documents/Depth_Images/contour_detection_sample.pgm", 255);

    return 0;
}

Results

Before Contour Detection

After Contour Detection

Explanation

The algorithm consists only of applying the following operations on the grey scale image (in order): histogram calculation, histogram equalization and the Sobel Operator (gradient calculation).


Related Page:Depth Image Extraction From Point Cloud

Clone this wiki locally