How to get the inner and outer outlines of a boundary in an image?
21 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
采纳的回答
Image Analyst
2016-3-17
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 个评论
更多回答(1 个)
Image Analyst
2016-3-18
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 个评论
Image Analyst
2016-3-18
You have an old version. Go to the Mathworks site and download the latest version.
Ely Raz
2017-12-30
How can I crop the jet in the RGB image subplot based on the jet binary image subplot dimensions?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!