How to measure the distances in a binarized image

조회 수: 3 (최근 30일)
Rohit Thokala
Rohit Thokala 2022년 1월 4일
댓글: yanqi liu 2022년 1월 6일
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
Matt Gaidica
Matt Gaidica 2022년 1월 4일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

yanqi liu
yanqi liu 2022년 1월 5일
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
Rohit Thokala
Rohit Thokala 2022년 1월 5일
편집: Rohit Thokala 2022년 1월 5일
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 2022년 1월 6일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by