376 views (last 30 days)

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.

Matt Gaidica
on 17 Jan 2021

Edited: Matt Gaidica
on 17 Jan 2021

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');

Matt Gaidica
on 26 Jan 2021

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

Matt Gaidica
on 27 Jan 2021

I'm not sure this is entirely correct, but you had things improperly placed.

Matt Gaidica
on 29 Jan 2021

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

Start Hunting!
## 1 Comment

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/719195-how-to-find-the-inner-distance-between-the-2-white-lines#comment_1268180

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/719195-how-to-find-the-inner-distance-between-the-2-white-lines#comment_1268180

Sign in to comment.