How to get the inner and outer outlines of a boundary in an image?

7 vues (au cours des 30 derniers jours)
charuleelaa vanilavarasu
charuleelaa vanilavarasu le 17 Mar 2016
Commenté : Yushuo le 10 Juil 2022
I'm trying to get the inner and outer outlines of the objects in an image to perform ioopl matching according to a paper i'm trying to implement. I want to contract my object boundary inwards and also expand it outward. eg:
how do i do this?

Réponse acceptée

Image Analyst
Image Analyst le 17 Mar 2016
Assuming you have the initial green boundary, you can convert it into a binary image and then use imdilate or imerode to grow or shrink the boundary
mask = poly2mask(x, y, rows, columns);
bigMask = imdilate(mask, true(3));
bigBoundary = bwboundaries(bigMask);
smallMask = imerode(mask, true(3));
smallBoundary = bwboundaries(smallMask);
Change the 3 to some other, larger number if you want to grow or shrink by some different amount.
  8 commentaires
charuleelaa vanilavarasu
charuleelaa vanilavarasu le 18 Mar 2016
it doesn't seem to work. Im just getting a image with a blue boundary. i tried increasing the value 3. doesn't do the trick. If you could try it, that would be great thank you.
Yushuo
Yushuo le 10 Juil 2022
imerode worked

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 18 Mar 2016
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Read in color image.
rgbImage = imread('2.jpg');
% Display the image.
subplot(2, 2, 1);
imshow(rgbImage);
title('RGB Image', 'FontSize', fontSize);
grayImage=rgb2gray(rgbImage);
thresholdLevel=graythresh(grayImage);
% Display the image.
subplot(2, 2, 2);
imshow(grayImage);
title('Gray Scale Image', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
drawnow;
hold on
binaryImage = im2bw(grayImage,thresholdLevel);
% Invert it and extract the largest blob.
binaryImage = bwareafilt(~binaryImage, 1);
% Fill Holes.
binaryImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 2, 3);
imshow(binaryImage);
title('Binary Image', 'FontSize', fontSize);
% Display the image.
subplot(2, 2, 4);
imshow(rgbImage);
title('RGB Image with 3 outlines', 'FontSize', fontSize);
axis on;
hold on;
[B,~,~,rgbImage] = bwboundaries(binaryImage);
boundaries = bwboundaries(binaryImage);
visboundaries(boundaries, 'Color', 'b');
bigMask = imdilate(binaryImage, true(13));
bigBoundary = bwboundaries(bigMask);
% Display the boundary over the image.
visboundaries(bigBoundary);
smallMask = imerode(binaryImage, true(7));
smallBoundary = bwboundaries(smallMask);
% Display the boundary over the image.
visboundaries(smallBoundary, 'Color', 'm');
  3 commentaires
Image Analyst
Image Analyst le 18 Mar 2016
You have an old version. Go to the Mathworks site and download the latest version.
Ely Raz
Ely Raz le 30 Déc 2017
How can I crop the jet in the RGB image subplot based on the jet binary image subplot dimensions?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by