how to select region with longest length on segmented image ?
Show older comments
I have segmented the image like the following:
and within the boundaries I want to select the boundary with the longest length from the boundaries extracted from the image like the image below:
help me please.
and within the boundaries I want to select the boundary with the longest length from the boundaries extracted from the image like the image below:
help me please.% Initialization Steps.
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 = 15;
markerSize = 4;
%[filename, pathname] = uigetfile({'*.*'},'File Selector');
%if ~isequal(filename,0)
%fullname = strcat(pathname,filename);
I=imread('MH2.jpeg');
%else
% msgbox('Ban chua chon anh?')
%end
Id = size(I);
if length(Id) == 3
B0 = rgb2gray(I);
else
B0 = I;
end
B0 = imadjust(B0);
k1 = fspecial('gaussian', [5 5], 2.5);
Ic = imfilter(B0,k1);
figure(1),subplot(3,3,1), imshow(I);
title('anh goc');
figure(1), subplot(3,3,2), imshow(B0);
title('anh tang tuong phan');
figure(1), subplot(3,3,3), imshow(Ic);
title('anh loc gaussian');
%loc trung vi
I_m = medfilt2(B0,[3 3]);
figure(1),subplot(3,3,4), imshow(Ic);
title('anh loc trung vi');
%anh nhi phan
thresholdValue = 60;
bw = Ic > thresholdValue;
bw = bwareafilt(bw, 1);
figure(1),subplot(3,3,5), imshow(bw);
title('anh nhi phan');
%dong hinh thai
se = strel("disk",10);
C1 = imclose(bw, se);
figure(1),subplot(3,3,6), imshow(C1);
title('dong hinh thai');
%khai thac ranh gioi
[B,L,N] = bwboundaries(C1);
figure(2);
%subplot(3,3,7);
imshow(C1); hold on;
title('khai thac ranh gioi');
for k=1:length(B)
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',1.5);
else
plot(boundary(:,2), boundary(:,1), 'r','LineWidth',1.5);
end
end
%
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






