How to adjust 'measured distance' on a binary image
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Rohit Thokala
el 5 de En. de 2022
Comentada: Rohit Thokala
el 13 de En. de 2022
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
0 comentarios
Respuesta aceptada
Image Analyst
el 7 de En. de 2022
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);
Más respuestas (1)
yanqi liu
el 7 de En. de 2022
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 )
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!