How to draw a line perpendicular to the medial axis in each point and save the intensity values?

1 回表示 (過去 30 日間)
Hamed Lamei Ramnadi
Hamed Lamei Ramnadi 2014 年 10 月 23 日
回答済み: Radek 2014 年 10 月 28 日
Thats what I wrote to get the medial axis (skeleton). im=imread('gray.tif'); skelImg = bwmorph(im, 'skel', inf); figure; imshow(skelImg); hold on;
  2 件のコメント
Adam
Adam 2014 年 10 月 23 日
Please try to make the 'question' part as short and to the point as possible. The 'body' of the question is where you can put all the "Hi..." stuff. The question is there as a headline to direct people who have the knowledge to help to a thread and those who don't to by-pass it.

サインインしてコメントする。

回答 (2 件)

Bruno Pop-Stefanov
Bruno Pop-Stefanov 2014 年 10 月 24 日
Take a look at the file overlayLines.m that I have attached. This function draws red lines over an RGB image. You can certainly modify it for a one-channel image. Also, if you examine the loop you'll see how to find the pixel values that the line crosses.
Example:
I = imread('autumn.tif');
x = [10,200;50,60];
y = [140,160;20,200];
J = overlayLines(I,x,y);
imshow(J)
  1 件のコメント
Hamed Lamei Ramnadi
Hamed Lamei Ramnadi 2014 年 10 月 28 日
Hi Bruno Thank you for your respond but it did not work out actually. Perhaps you did not get my point. I can draw lines by giving x and y. I need a code to draw these lines PERPENDICULAR to the medial axis in each point.
Cheers

サインインしてコメントする。


Radek
Radek 2014 年 10 月 28 日
Hi, i have solved same issue. my propasal is this (not the best and quickest solution ever but it works):
1. Calculate angle of the line
if true
% code
Xdiff=X-Gpoint2X-GpointX;
Ydiff=Gpoint2Y-GpointY;
angle=tan(Ydiff/Xdiff);
end
Where Gpoint and Gpoint2 are two points on the line and GpointX is point G X coord
2. do
if true
angle=angle*(-1);
% code
end
to make PERPENDICULAR line
3. use
if true
function [Line LineIndexes]=ComputeLineCoords(angle,GpointX,GpointY, shift,L)
X=size(L,2)
StepElevation=tan(angle)*1
Line(1:X)=round(StepElevation*(1:X)- GpointX*StepElevation +GpointY+shift);
OutOfboundsFromS=min(find(Line(1:X)<1))-1;
OutOfboundsFromE=min(find(Line(1:X)>size(L,2)))+1;
if (OutOfboundsFromS==1)
LineIndexes=[OutOfboundsFromS];
else
if (OutOfboundsFromE==size(L,2))
LineIndexes=[OutOfboundsFromE];
else
LineIndexes=[1];
end
end
OutOfboundsToS=max(find(Line(1:X)>size(L,2)));
OutOfboundsToE=min(find(Line(1:X)<1))-1;
if (Line(OutOfboundsToE)<=1)
LineIndexes=[LineIndexes OutOfboundsToE];
else
if (OutOfboundsToS>=X)
LineIndexes=[LineIndexes OutOfboundsToS];
else
LineIndexes=[LineIndexes X];
end
end
end
To get indexes of pixels in which the line is going (Line) and its bounding box in LineIndexes .
intputs are angle GpointX - Since i wrote it for XY you have to use Y coord of the point where the line should be placed GpointY - Since i wrote it for XY you have to use X coord of the point where the line should be placed shift - 0 should be fine but you hav eto experiment with it a little L - image to get sizes
you might play around a little with the dimensions but this worked for me

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by