How to Find Interior and Exterior Skeleton of Binary Images Using MATLAB?


In a binary image, the interior and exterior skeletons are used to represent the essential structure of the objects and shaped within the image. In this article, I am going explain the process of finding the interior and exterior skeleton of binary image using MATLAB.

Before discussing the process of finding the interior and exterior skeletons of a binary image. let us first get an overview of these two types of skeletons.

What is the Interior Skeleton of Binary Image?

In a binary image, the "interior skeleton" represents the centerline of the foreground objects. It is basically a thin representation of the objects or shapes in the binary image.

  • We can obtain the interior skeleton of a binary image by repeatedly removing the pixels from the binary shapes and objects to obtain their one-pixel-wide representation.

  • Finding the interior skeleton of a binary image is crucial in various image processing tasks like object recognition, shape analysis, feature extraction, and more.

What is the Exterior Skeleton of Binary Image?

In a binary image, the skeleton of the background is termed as the "exterior skeleton". In other words, the exterior skeleton of a binary image is nothing but the skeleton of regions between objects or shapes within the binary image.

  • We can find the exterior skeleton of a binary image simply by taking the complement of the binary image and then finding the interior skeleton of the complemented binary image.

  • The exterior skeleton represents the information about connectivity between different shapes or objects within the binary image.

This is all about basics of the interior and exterior skeletons of a binary image. Both of these skeletons are very useful in various image processing tasks such as pattern recognition, shape analysis, structural analysis, and more.

Let us now discuss the process of finding the interior and exterior skeleton of a binary image using MATLAB.

Find the Interior Skeleton of a Binary Image in MATLAB

In MATLAB, we follow the steps given below to find the interior skeleton of a binary image.

  • Step (1) − Read the binary image. For this, we use the “imread” function.

binary_img = imread(ImagePath);
  • Step (2) − Find the interior skeleton of the input binary image. For this, we perform morphological operation by using the “bwmorph” function with “skel” option to find the skeleton of the image.

interior_skeleton = bwmorph(binary_img, 'skel', Inf);
  • Step (3) − Display the result.

Example

Let us now take an example in MATLAB to understand the implementation of these steps.

% MATLAB code to find interior skeleton of binary image
% Read the input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425236.jpg');

% Convert the input image to grayscale if required
gray_img = rgb2gray(img);

% Create the binary image
binary_img = imbinarize(gray_img);

% Find the interior skeleton of binary image
interior_skeleton = bwmorph(binary_img, 'skel', Inf);

% Display the binary image and its interior skeleton
figure;
subplot(1, 2, 1)
imshow(binary_img)
title('Binary Image');

subplot(1, 2, 2)
imshow(interior_skeleton)
title('Interior Skeleton');

Output

When you run this code, it will produce the following output

Explanation

In this example, we have determined the interior skeleton of the input binary image. This code has two extra steps at the beginning. Where, we read the input image which is an RGB image. Hence, it requires to be converted into grayscale scale image first and then create a its binary image.

The interior skeleton of this binary image is shown in the output image with title “interior skeleton”. For better results, you can try this code with different image. If you input image is already a binary image, then skip the steps involved in conversion to grayscale and creation of binary image.

Let us now discuss the process of finding the exterior skeleton of a binary image using MATLAB.

Find the Exterior Skeleton of a Binary Image in MATLAB

In MATLAB, the following steps are to be followed to find the exterior skeleton of a binary image.

  • Step (1) − Read the binary imageby using the the “imread” function.

Syntax

binary_img = imread(ImagePath);
  • Step (2) − Complement this input binary image.

  • Step (3) − Find the interior skeleton of the complemented binary image using the “bwmorph” function. The output will be the exterior skeleton of the binary image.

Syntax

exterior_skeleton = bwmorph(comp_bin_img, 'skel', Inf);
  • Step (4) − Display the result.

Example

Let us see an example in MATLAB to understand the implementation of the steps to find the exterior skeleton of a binary image.

% MATLAB code to find exterior skeleton of binary image
% Read the input image
img = imread('https://www.tutorialspoint.com/assets/questions/media/14304-1687425236.jpg');

% Convert the input image to grayscale if required
gray_img = rgb2gray(img);

% Create the binary image
binary_img = imbinarize(gray_img);

% Complement the binary image
comp_bin_img = ~binary_img;
% Perform morphological operation to find exterior skeleton
exterior_skeleton = bwmorph(comp_bin_img, 'skel', Inf);

% Display the binary image and its exterior skeleton
figure;
subplot(1, 2, 1)
imshow(binary_img)
title('Binary Image');

subplot(1, 2, 2)
imshow(exterior_skeleton)
title('Exterior Skeleton');

Output

When you run this code, it will produce the following output

Explanation

In this example, we have obtained the exterior skeleton of the input image. Here, the steps are same as the interior skeleton. The only difference is that we first calculate the complement of the binary image to swap the back and white pixels. Then, we find the interior skeleton of the complemented image which is basically the exterior skeleton.

Conclusion

In conclusion, the interior and exterior skeletons of a binary image are two different representations that show the structure of objects and shapes within the image.

The interior skeleton represents the centerline of the foreground objects, whereas the exterior skeleton highlights the skeleton of the background of the image.

In this tutorial, I explained the step-by-step process of finding the interior and exterior skeletons of a binary image in MATLAB. I have also included example programs for better understand of the implementation of the steps.

Updated on: 05-Oct-2023

46 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements