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!