How to adjust 'measured distance' on a binary image

조회 수: 1 (최근 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개)

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