How to find the inner distance between the 2 white lines
2 ビュー (過去 30 日間)
古いコメントを表示
Hi,someone can give me a hand to make a script related to the problem?
Practically ,I want to get the distance column by column from the lowest white border of the upper part to the highest white border of the lower part.
I thank you in advance.
1 件のコメント
Image Analyst
2021 年 1 月 17 日
There are several ways to solve this. Do you want a vector of gaps (one gap width for every column), OR the average height (which actually doesn't need you to determine the gap on a column-by-column basis believe it or not).
But make it easy for us to help you, not hard. Attach the actual image either in a PNG file or a .mat file. We don't want the screenshot with tick labels, tick marks, surrounding gray background, etc. If you give all all that junk, it makes it hard for us because we need to take several steps to get rid of them and get down to the actual image.
採用された回答
Matt Gaidica
2021 年 1 月 17 日
編集済み: Matt Gaidica
2021 年 1 月 17 日
The only thing you don't state is what to do in the case around x=400 where white pixels do not demarcate the "top". One way to make the algorithm below work is to modify the array so that there is always white on top and bottom, as I do with C.
B = imbinarize(im2gray(imread('borderProblem.png')));
% force white on top and bottom
C = [ones(1,size(B,2));B;ones(1,size(B,2))];
maxDist = zeros(1,size(B,2));
for iCol = 1:size(B,2)
d = diff(C(:,iCol));
edgeIdxs = find(d ~= 0);
maxDist(iCol) = max(diff(edgeIdxs));
end
close all
figure;
subplot(211);
imshow(C);
subplot(212);
plot(maxDist,'k');
xlim(size(maxDist));
ylim([1,size(B,1)]);
xlabel('col');
ylabel('dist');
19 件のコメント
Matt Gaidica
2021 年 1 月 26 日
n = 10;
for i=1:N
if mod(i-1,n);
all_maxDist = [];
end
% do calculation here
% ...
if mod(i-1,n);
h = plot(mean(all_maxDist));
% save h
close(h);
end
end
Or just compile the array as I had it and create a loop afterwards:
n = 10;
for ii=1:n:N
h = plot(mean(all_maxDist(ii:ii+n-1)));
% save h
close(h);
end
その他の回答 (1 件)
Matt Gaidica
2021 年 1 月 27 日
I'm not sure this is entirely correct, but you had things improperly placed.
6 件のコメント
Matt Gaidica
2021 年 1 月 29 日
If you compile all of it in your main loop using all_maxDist then you just create a new figure for that variable. I would seek out some of the MATLAB tutorials on matrices and loops, this is fundamental stuff. I'm going to unsubscribe here, I think you need to start a new thread based on very specific problems you're having.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!