The figure on the right shows a region I got from bwboundaries. The one on the left is zoomed in.
Basically, I want to separate the branched out regions from the main branch, and create about 5 separate boundaries. Is there a technique to achieve this?
Original BW
I'm basically trying to separate those horizontal stripes from the rest.

댓글 수: 3

Matt J
Matt J 2021년 11월 19일
Please provide the BW image that this comes from, so that we can more easily demonstrate a solution.
Added.
Matt J
Matt J 2021년 11월 19일
It would be easier for us if you would attach a .mat file containing the BW variable.

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

 채택된 답변

yanqi liu
yanqi liu 2021년 11월 20일
편집: yanqi liu 2021년 11월 23일

0 개 추천

clc; clear all; close all;
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/806794/image.png');
bw = im2bw(img);
bw = ~bw;
bw = bw(:,round(size(bw,2)/2):end);
bw = bwareafilt(bw, 2);
bt = bwareafilt(bw, 1);
bw(bt) = 0;
bw = logical(bw);
bw = imclose(bw, strel('disk', 2));
figure; imshow(bw);
% make segment location
be = imopen(bw, strel('line', 7, 90));
bw1 = bw;
bw1(be) = 0;
bw1 = logical(bw1);
bw1 = bwareafilt(bw1, 4);
figure; imshow(bw1);
bw1 = imdilate(bw1, strel('disk', 2));
% do segment
figure; imshow(bw);
bw2 = bw;
[L,num] = bwlabel(bw1);
stats = regionprops(L);
hold on;
for i = 1 : num
recti = round(stats(i).BoundingBox);
ri = recti(2)+recti(4)/2;
plot([1 size(bw, 2)], [ri ri], 'r-', 'LineWidth', 2);
bw2(recti(2):recti(2)+recti(4),:) = 0;
end
bw2 = logical(bw2);
[L2,~] = bwlabel(bw2);
figure; imshow(label2rgb(L2));

댓글 수: 1

Brilliant! Thanks a lot!
Strel was the key I was looking for.

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

추가 답변 (0개)

질문:

2021년 11월 19일

편집:

2021년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by