How to get the inner and outer outlines of a boundary in an image?
    조회 수: 7 (최근 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에서 Matrix Indexing에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!