How to Identify Objects with Image Contouring

Image contouring is a computer vision technique that lets you identify the location of objects in images. Contouring works by identifying the pixels at the edge of an object in an image.

In this guide, we are going to walk through how to apply image contouring  to create a workflow that applies the requisite preprocessing steps then runs image contouring. You can then deploy the workflow to your own hardware, and run inference with frames from your camera feeds.

Here is an interactive Workflow you can try that uses image contouring:


We will use Roboflow Workflows, a web-based computer vision application builder, to create the image contouring application and finish with a Workflow that looks like the one above.

Without further ado, let’s get started!

Identify Objects with Image Contouring

Image contouring is a method of finding the location of objects in images. It has been employed extensively in computer vision tasks.

Roboflow typically recommends using object detection models such as those implemented with the YOLO architecture for precise object detection. Object detection models powered by deep learning can be trained to identify objects in different conditions, a task with which image contouring techniques struggle.

With that said, if you have an image with clearly visible contours, you may not need a deep learning model for your problem.

Below, we are going to walk through all the steps to identify objects with image contouring.

Step #1: Create a Workflow

To get started, first create a free Roboflow account. Then, navigate to the Roboflow dashboard and click the Workflows tab in the left sidebar. This will take you to the Workflows homepage, from which you can create a workflow.

Click “Create Workflow” to create a Workflow.

A window will appear in which you can choose from several templates. For this guide, select “Custom Workflow”:

Click “Create Workflow” to create your Workflow.

You will be taken into the Workflows editor in which you can configure your Workflow:

With a blank Workflow ready, we can start using the image contouring Workflow functionality.

Step #2: Add Preprocessing Blocks

Before we contour an image, there are a few preprocessing steps we need to apply.

We are going to apply the following steps so we can achieve optimal performance:

  1. Greyscale.
  2. Blur.
  3. Thresholding.

Thresholding takes a pixel and turns it into either black and white depending on whether it exceeds a certain threshold. The default threshold, 127, means that any pixel whose value (already grayed out) is under 127 will be turned to black (0), and any above 127 will be turned to white (255). The thresholded image can then be used for contouring.

In the Workflows editor, add the Greyscale, Image Blur, and Image Threshold blocks.

Your Workflow should look like this:

When you add each block, set the Image value to reference the previous image. For example, Image Convert Grayscale should reference the Image Blur image:

When you configure the Image Threshold block, we recommend the threshold value 127:

Then, click "Optional Properties" and set the threshold type to binary_inv:

This will invert the colours from the thresholding operation. This should make the background of the image black and objects of interest white.

Once you have configured these blocks, you are ready to add the image contouring block.

Step #3: Add an Image Contours Block

Click “Add Block” in the Workflows editor and add the Image Contours block:

Connect the block to use the image from the thresholding block: 

The Image Contours block can return several values:

  1. An image showing the contours;
  2. The number of contours identified;
  3. The contour hierarchy.

Configure the Response block to return the values you need. Let’s return the image from the Image Contour block so we can see the response from our system:

Finally, update your Response to include the thresholded image from the image_threshold block, the image from the image_contours block, and the number_contours value from the image_contours block:

With our Workflow configured, we are now ready to test the system.

Step #4: Test the Workflow

Your final Workflow should look like this:

There are five steps:

  1. Accept an input image.
  2. Convert image to grayscale.
  3. Apply a blur.
  4. Threshold the image.
  5. Calculate contours.

The Workflow then returns a response with the image contours.

To test the Workflow, click “Run Preview”. Then, upload an image to which you want to apply contouring:

Click “Run Preview” to test the Workflow.

Let's run our Workflow on an image from Tetris as an example of how this system thrives on objects that are clearly differentiable from background and other objects in an image:

On the right side, you will see a JSON response with the output from your Workflow.

Here is an example response from our Workflow:

Our Workflow successfully identified there were six contours. This means that there were six objects in the image. The faint pink outlines in the output value show the identified contours.

Conclusion

Image contouring allows you to identify the contours of an image. This can be used to identify the location of unique objects in an image.

In this guide, we walked through how to apply image contouring with Roboflow Workflows. We used Workflows to preprocess an image with grayscale, blurring, and thresholding. We then used Workflows to calculate image contours.

To learn more about what is possible with Roboflow Workflows, refer to the Workflows Template Gallery.