Row-wise labelling with bwlabel() and regionprops
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I am trying to label a collage row-wise with bwlabel() and regionprops and then crop indivudial images from that collage.
Currently I have tried using either extrema or centroids. Extrema has worked out significantly better for me.
For extrema my code is as follows:
for n = 1:binary_images
binary_Images=fullfile(image_folder_binary, filenames_bin(n).name) ; % its will specify images names with full path and extension
our_images_binary = imread(binary_Images); % read images
% Do a "hole fill" to get rid of any background pixels or "holes" inside the blobs.
our_images_binary = imfill(our_images_binary, 'holes');
L = bwlabel(our_images_binary,8)
props = regionprops(L, our_images_binary, 'all');
extrema = vertcat(props.Extrema);
left_most_top = extrema(1:8:end, :);
[sortedEX, sort_Order] = sortrows(fliplr(left_most_top));
% Re-sort props
props = props(sort_Order);
numberOfBlobs(n) = length(props);
blobMeasurements{n} = props;
end
and for centroid:
for n = 1:binary_images
binary_Images=fullfile(image_folder_binary, filenames_bin(n).name) ; % its will specify images names with full path and extension
our_images_binary = imread(binary_Images); % read images
% Do a "hole fill" to get rid of any background pixels or "holes" inside the blobs.
our_images_binary = imfill(our_images_binary, 'holes');
L = bwlabel(our_images_binary,8)
props = regionprops(L, our_images_binary, 'all');
xyCentroids = vertcat(props.Centroid);
y = xyCentroids(:, 2); % Get all the y values (row centroids of blobs)
[sortedY, sortOrder] = sort(y, 'ascend'); % Do the sort.
% Re-sort props in order of increasing y.
props = props(sortOrder);
numberOfBlobs(n) = length(props);
blobMeasurements{n} = props;
end
I've also attached the binary image and the labelled image using the extrema, any suggestion on how to label this image row-wise?
0 comentarios
Respuestas (1)
yanqi liu
el 1 de Feb. de 2021
clc; clear all; close all;
im = imread('binary image.png');
bw = im2bw(im);
sz = size(im);
bwt = imclose(bw, strel('line', round(sz(2)*0.2), 0));
[L, num] = bwlabel(bwt);
stats = regionprops(L);
rects = cat(1, stats.BoundingBox);
[~, ind] = sort(rects(:, 2));
figure; imshow(im, []);
for i = 1 : num
bwi = bwt;
bwi(L~=ind(i)) = 0;
bwi = logical(bwi.*bw);
statsi = regionprops(bwi);
ceni = cat(1, statsi.Centroid);
ceni = sortrows(ceni, 1);
hold on;
for j = 1 : size(ceni,1)
text(ceni(j,1), ceni(j,2), sprintf('%d-%d', i, j),'Color','r')
end
end
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!