Azzera filtri
Azzera filtri

How to measure the distances in a binarized image

3 visualizzazioni (ultimi 30 giorni)
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 Commento
Matt Gaidica
Matt Gaidica il 4 Gen 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.

Accedi per commentare.

Risposta accettata

yanqi liu
yanqi liu il 5 Gen 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 Commenti
Rohit Thokala
Rohit Thokala il 5 Gen 2022
Modificato: Rohit Thokala il 5 Gen 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 il 6 Gen 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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by