How to plot diagonal lines starting at the last line's end point?

1 view (last 30 days)
Hello, I want to plot these red lines between each blue line, like the one all the way at the bottom but all the way up (like the red diagonals connecting the blue lines in the second picture). Any help appreciated!
img = double(mat2gray(imread('071318.bmp')));
mask_size=[5 5];
sigma=4;
Gaussian_filter = fspecial('gaussian',mask_size,sigma);
A=conv2(img, Gaussian_filter, 'same');
Gx = [-1, 0, 1; -2, 0, 2; -1, 0, 1];
Gy = [1, 2, 1; 0, 0, 0; -1, -2, -1];
SobelX = conv2(A, Gx, 'same');
SobelY = conv2(A, Gy, 'same');
gradient_direction = (atan2(SobelY, SobelX))*180/pi;
gradient_magnitude = sqrt((SobelX.^2) + (SobelY.^2));
Threshold_High = min(min(gradient_magnitude))+max(max(gradient_magnitude))*.09;
Threshold_Low = Threshold_High/2;
rows=size(A,1);
columns=size(A,2);
for i=1:rows
for j=1:columns
if (gradient_direction(i,j)<0)
gradient_direction(i,j)=360+gradient_direction(i,j);
end
end
end
edge_direction=zeros(rows,columns);
for i = 1 : rows
for j = 1 : columns
if ((gradient_direction(i,j)>=0)&&(gradient_direction(i,j)<22.5)||(gradient_direction(i,j)>=157.5)&&(gradient_direction(i,j)<202.5)||(gradient_direction(i,j)>=337.5)&&(gradient_direction(i,j)<=360))
edge_direction(i,j)=0;
elseif((gradient_direction(i,j)>=22.5)&&(gradient_direction(i,j)<67.5)||(gradient_direction(i,j)>=202.5)&&(gradient_direction(i,j)< 247.5))
edge_direction(i,j)=45;
elseif((gradient_direction(i,j)>=67.5&&gradient_direction(i,j)<112.5)||(gradient_direction(i,j)>=247.5&&gradient_direction(i,j)<292.5))
edge_direction(i,j)=90;
elseif((gradient_direction(i,j)>=112.5&&gradient_direction(i,j)<157.5)||(gradient_direction(i,j)>=292.5&&gradient_direction(i,j)<337.5))
edge_direction(i,j)=135;
end
end
end
edge1 = zeros (rows, columns);
for i=2:rows-1
for j=2:columns-1
if (edge_direction(i,j)==0)
edge1(i,j)=(gradient_magnitude(i,j)==max([gradient_magnitude(i,j),gradient_magnitude(i,j+1),gradient_magnitude(i,j-1)]));
elseif (edge_direction(i,j)==45)
edge1(i,j)=(gradient_magnitude(i,j)==max([gradient_magnitude(i,j),gradient_magnitude(i+1,j-1),gradient_magnitude(i-1,j+1)]));
elseif (edge_direction(i,j)==90)
edge1(i,j)=(gradient_magnitude(i,j)==max([gradient_magnitude(i,j),gradient_magnitude(i+1,j),gradient_magnitude(i-1,j)]));
elseif (edge_direction(i,j)==135)
edge1(i,j)=(gradient_magnitude(i,j)==max([gradient_magnitude(i,j),gradient_magnitude(i+1,j+1),gradient_magnitude(i-1,j-1)]));
end
end
end
edge2 = edge1.*gradient_magnitude;
Threshold_Low = Threshold_Low * max(max(edge2));
Threshold_High = Threshold_High * max(max(edge2));
edge_binary = zeros (rows, columns);
for i = 1 : rows
for j = 1 : columns
if (edge2(i, j) < Threshold_Low)
edge_binary(i, j) = 0;
elseif (edge2(i, j) > Threshold_High)
edge_binary(i, j) = 1;
elseif(edge2(i+1,j)>Threshold_High||edge2(i-1,j)>Threshold_High||edge2(i,j+1)>Threshold_High||edge2(i,j-1)>Threshold_High||edge2(i-1,j-1)>Threshold_High||edge2(i-1,j+1)>Threshold_High||edge2(i+1,j+1)>Threshold_High||edge2(i+1,j-1)>Threshold_High)
edge_binary(i,j)=1;
end
end
end
edge = (edge_binary.*255);
edge(1600:2054,:)=[];
edge(:,1:300)=[];
edge=flipud(edge);
[y,x]= find(edge==255);
T= table(x,y,'VariableNames',{'x','y'}); %table of (x,y) points of bubble edge
x0=mean(x(y==min(T.y)));
T(T.x>x0,:)=[];
hold on
axis equal
title('Captive Bubble Air-Liquid Interface')
xlabel('x')
ylabel('y')
e=contour(edge,'k');
y_axis=xline(x0);
for n=0:50:max(y) %delta y small
m=min(y); %starting y value of R lines at lowest bubble edge point
x1=x(y==m+n);
delete=x1>x0;
x1(delete)=[];
x1=mean(x1);
plot([x0 x1],[m+n m+n],'b'); %R line
R=x0-x1;
for o=m:100:max(y) %delta y big
plot([x0 x1],[m m+n],'r');
end
end
  6 Comments
darova
darova on 30 Jul 2019
I have older version of MATLAB and the script doesn't want to run. Cant please you attach a screenshot or something?
Cameron Calder
Cameron Calder on 30 Jul 2019
A screenshot of the picture? It's a bmp file, the script won't run with a jpeg.

Sign in to comment.

Accepted Answer

darova
darova on 30 Jul 2019
Here is what i achieved
img3.png
Am i succeeded?

More Answers (0)

Community Treasure Hunt

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

Start Hunting!