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 Kommentare

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

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

yanqi liu
yanqi liu am 20 Nov. 2021
Bearbeitet: yanqi liu am 23 Nov. 2021

0 Stimmen

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by