How to measure the distances in a binarized image

3 vues (au cours des 30 derniers jours)
Rohit Thokala
Rohit Thokala le 4 Jan 2022
Commenté : yanqi liu le 6 Jan 2022
I want to measure some distance on a binarized image and automate the process to all other images. imdistline command works for individual images on output window but, I want to measure this distance for almost 500 images. I am attaching original and binarized image of the same here for reference. In the binarized image I have mentioned the distances (i.e., X and Y) that I want to measure in the red arrows. Thanks in advance.
  1 commentaire
Matt Gaidica
Matt Gaidica le 4 Jan 2022
How stereotyped is the splash pattern? Could you provide a larger set of images? My instict would be to clean up the binary version, limit a blob analysis to 2 blobs, then measure their bounding boxes.

Connectez-vous pour commenter.

Réponse acceptée

yanqi liu
yanqi liu le 5 Jan 2022
yes,sir,may be upload 5 image to debug,such as
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/852995/original%20image.jpg');
im = rgb2gray(img);
bw = imbinarize(im,'adaptive','ForegroundPolarity','dark','Sensitivity',0.5);
bw2 = imopen(bw, strel('line', round(size(bw,2)*0.5), 0));
bw2 = imdilate(bw2, strel('square', 7));
bw(bw2) = 0;
bw = bwareafilt(imclearborder(bw), 1);
bwt = bw;
bw2 = imopen(bw, strel('line', round(size(bw,2)*0.05), 0));
bw2 = imdilate(bw2, strel('square', 5));
bw(~bw2) = 0;
bw = bwareafilt(bw, 2);
stats = regionprops(bw);
figure; imshow(bwt,[]);
hold on;
for i = 1 : length(stats)
rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
end
  4 commentaires
Rohit Thokala
Rohit Thokala le 5 Jan 2022
Modifié(e) : Rohit Thokala le 5 Jan 2022
ok thank you. above code is working properly for small spray clouds but not bigger clouds. I am attaching a figure for reference. Could you help something with this. thanks in advance
yanqi liu
yanqi liu le 6 Jan 2022
yes,sir,the image area segment may be confuse as one block
clc; clear all; close all;
img = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/853490/original_image.jpg');
im = rgb2gray(img);
bw = imbinarize(im,'adaptive','ForegroundPolarity','dark','Sensitivity',0.5);
bw2 = imopen(bw, strel('line', round(size(bw,2)*0.5), 0));
bw2 = imdilate(bw2, strel('square', 7));
bw(bw2) = 0;
bw = bwareafilt(imclearborder(bw), 1);
bwt = bw;
bw2 = imopen(bw, strel('line', round(size(bw,2)*0.05), 0));
bw2 = imdilate(bw2, strel('square', 5));
bw(~bw2) = 0;
bw = bwareafilt(bw, 2);
Warning: One or more ties for n-th place occurred when selecting objects. Some objects were not selected.
stats = regionprops(bw);
figure; imshow(bwt,[]);
hold on;
k = 0;
rects = [];
for i = 1 : length(stats)
if stats(i).Area < 1e4
continue;
end
k = k + 1;
rectangle('Position', stats(i).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
rects = [rects; stats(i).BoundingBox];
end
if size(rects, 1) < 2
wh = rects(1,:);
rect1 = [rects(1:2) wh(3)*0.5-10 wh(4)];
rect2 = [rects(1)+wh(3)*0.5+10 rects(2) wh(3)*0.5-10 wh(4)];
rectangle('Position', rect1, 'EdgeColor', 'y', 'LineWidth', 2);
rectangle('Position', rect2, 'EdgeColor', 'y', 'LineWidth', 2);
end

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by