Looking for technique to split regions.

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 Commenti

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

Accedi per commentare.

 Risposta accettata

yanqi liu
yanqi liu il 20 Nov 2021
Modificato: yanqi liu il 23 Nov 2021
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 Commento

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

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by