How to constrain imdistline to vertical drag constraint

I wonder if anyone can help, as i am new to MATLAB. I have a axis (pixelAxis) that contains an ultrasound image and I am using imdistline to meaure between two poins on the scale bar that is included in the image. I have set the line to be vertical when it appears but i can't seem to make constrain the drag to vertical only.
handles.distLine = imdistline (handles.pixelAxis, [850 850], [150 400]);
I have read the imdistline entry in the manual, but i'm not sure how to implement it.
Many Thnaks
Richard

 採用された回答

Richard Simpson
Richard Simpson 2012 年 5 月 16 日

0 投票

Hi Walter
Thanks for the code,
However the cose you posted seems to constrain to horizontal drag only and not vertical.
I want to be able to move the points in the vertical direction only. I tried to amend your code, but as i don't quite understand how it works, I didn't manage it, although i di try.
Thanks
Richard

2 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 16 日
You are right, sorry, that would be horizontal constraint instead of vertical.
fcn = @(pos) [min(pos(:,1)) pos(1,2); min(pos(:,1)) pos(2,2)];
Richard Simpson
Richard Simpson 2012 年 5 月 16 日
That's it! Great thanks.

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

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 14 日

0 投票

Follow example 1 of the imdistline documentation... including using the undocumented property.
Adapting it according to what you posted:
handles.distLine = imdistline (handles.pixelAxis, [850 850], [150 400]);
api = iptgetapi(handles.distLine);
fcn = @(pos) [pos(1,1) min(pos(:,2)); pos(2,1) min(pos(:,2))];
api.setDragConstraintFcn(fcn);
Here, I do the vertical constraint by forcing both y to be the same, arbitrarily choosing the lower of the two y as being the "right" vertical offset to constrain to.

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by