필터 지우기
필터 지우기

How can i detect the boundary using bwtraceboundary function ??

조회 수: 6 (최근 30일)
Surendra Ratnu
Surendra Ratnu 2023년 5월 1일
답변: Image Analyst 2023년 5월 5일
I want to detect the seperate two boundaries (inner and outer boundary) in our case.. I want to seperately detect inner and outer boundary and calculate the distance between them along the boundaries. In the image.png, I shown the exmple how will i want to do seperate the boundary (red and green colour boundary) which i want to seperate into inner and outer boundary. please give me a solution so i can automatically select the starting point and store the boundary data into two matrix.
Thank you for help

답변 (2개)

Antoni Garcia-Herreros
Antoni Garcia-Herreros 2023년 5월 2일
Hello Surendra,
You can take a look at this thread.
But the general idea would be to:
  1. Crop ROI
  2. Segment your image
  3. Obtain the boundaries and calculate thickness
clear all
close all
I=imread('Original_image (2).png');
%% Crop region
Icrop=I(1:720,400:600);
%% Segment
BW=~imbinarize(Icrop);
se = strel('disk',5);
BWc=imclose(BW,se);
skelImage = bwskel(BWc, 'MinBranchLength', 10); % First guess. Strangely bwskel() doesn't seem to have any short spurs, no matter what MinBranchLength is.
imshow(imoverlay(BWc, skelImage, 'r'));
title('Binary image with skel')
%% Obtain distances
edtImage = bwdist(~BWc); %Distance of to nearest 0 value
radii = edtImage(skelImage); % Extract the distances only along the skeleton
% These are the half widths. Multiply by 2 to get the full widths.
averageWidth = 2 * mean(radii)
averageWidth = single 11.9689
%% Find the boundaries
E=edge(BWc); % Find the edges
CC = bwconncomp(E); % Isolate the different components
[rowOut1,colOut1]=ind2sub(size(E),CC.PixelIdxList{1,1});
Pout1=[rowOut1,colOut1]; % Pixels forming Outer boundary 1
[rowIn,colIn]=ind2sub(size(E),CC.PixelIdxList{1,2});
Pin=[rowIn,colIn]; % Pixels forming Inner boundary 1
[rowOut2,colOut2]=ind2sub(size(E),CC.PixelIdxList{1,3});
Pout2=[rowOut2,colOut2]; % Pixels forming Outer boundary 2
figure(2)
imshow(BWc)
hold on
plot(Pin(:,2),Pin(:,1),'.','MarkerSize',2)
plot(Pout1(:,2),Pout1(:,1),'.','MarkerSize',2)
plot(Pout2(:,2),Pout2(:,1),'.','MarkerSize',2)
title('Boundaries')
Hope this helps
  댓글 수: 3
Image Analyst
Image Analyst 2023년 5월 5일
Then why did you accept the answer? It's not how I would have done it. I don't know whether to give you my solution or not -- maybe you've already solved it yourself since it's rather easy if you use bwboundaries instead of bwtraceboundary. Let me know if you need my solution.
Surendra Ratnu
Surendra Ratnu 2023년 5월 5일
Hi Image Analyst.... I used bwboundaries instead of bwtraceboundary but in bwbouries it dectect all boundaries but i need to trace inner and outer boundary seperately and need the co-ordinate of the inner and outer boundary seperately. Please give me the your solution it will be great help for me. Can you just eloborate on " how to seperate the inner and outer boundary seperately using bwboundries ??".
Thank you for your answer.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2023년 5월 5일
Look at the documentation for bwboundaries. If you get all the output variables, you'll know which are exterior or interior/nested boundaries.

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by