How to adjust 'measured distance' on a binary image

3 ビュー (過去 30 日間)
Rohit Thokala
Rohit Thokala 2022 年 1 月 5 日
コメント済み: Rohit Thokala 2022 年 1 月 13 日
I have code for radius and height measurements for spray images. This code is overestimating the spray cloud height (i.e., rectangle height). I want to measure spray cloud height with out imcoming spray influence. I am attaching my code and reference image here. the height I want to measure is shown in the below picture with arrows. Thanks in advance

採用された回答

Image Analyst
Image Analyst 2022 年 1 月 7 日
You can sum the white pixels horizontally and then threshold it at some percentage of the max width
verticalProfile = sum(mask, 2);
maxWidth = max(verticalProfile);
percentage = 0.5; % Adjust to take more or less of the blob.
topLine = find(verticalProfile > percentage * maxWidth, 1, 'first')
bottomLine = find(verticalProfile > percentage * maxWidth, 1, 'last')
% Draw lines there
yline(topLine, 'Color', 'r', 'LineWidth', 2);
yline(bottomLine, 'Color', 'r', 'LineWidth', 2);
  1 件のコメント
Rohit Thokala
Rohit Thokala 2022 年 1 月 13 日
Hello sir (@Image Analyst), Can I draw a inclined line instead of straight line? Here is the link for my question. Thanks in advance

サインインしてコメントする。

その他の回答 (1 件)

yanqi liu
yanqi liu 2022 年 1 月 7 日
clc; clear all; close all;
B = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/853535/binary_image.jpg');
B = im2bw(B);
figure; subplot(3,1,1)
imshow(B,'Border','tight')
title('Step 1')
B2 = bwareafilt(B,1); % select the largest component with bwareafilt
subplot(3,1,2)
imshow(B2),
title('Step 2')
widthIndex = any(B2);
horizontalPixelWidth = find(widthIndex,1,'last')-find(widthIndex,1,'first');
B3 = imerode(B2,strel('line',10,0));
% use sum for every row
cs = sum(B3, 2);
mcs = max(cs);
inds = find(cs>mcs*0.3);
subplot(3,1,3)
imshow(B3)
title('Step 3')
set(gcf,'Visible',true)
verticalPixelHeight = find(any(B2,2),1,'last') - inds(1);
figure; imshow(B)
title('Result')
hold on
rectangle('Position', ...
[find(widthIndex,1,'first'), inds(1),...
horizontalPixelWidth,verticalPixelHeight],...
'EdgeColor','r','LineWidth',2 )

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by