How to measure the distances in a binarized image
3 ビュー (過去 30 日間)
古いコメントを表示
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
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
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 件のコメント
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);
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 Center および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!