draw line segments in matlab


After spending some effort searching online, I found one solution:

r = 5;
x1 = linspace(pos.cx – r, pos.cx + r);
y1 = linspace(pos.cy, pos.cy);

x2 = linspace(pos.cx, pos.cx);
y2 = linspace(pos.cy – r, pos.cy + r);

index1 = sub2ind(size(im), round(y1), round(x1));
index2 = sub2ind(size(im), round(y2), round(x2));
im(index1) = 127; % set the valudes to 127 for display
im(index2) = 127; % set the valudes to 127 for display

The above code snippet is used to draw a cross on an image or matrix. Because of over sampling, the line drawn is without aliasing artifacts. For drawing lines on figures, there exists an easier solution, just use function ‘line’. For example:

line(rect(1,:), rect(2,:),’Color’,’r’,’LineWidth’,2);

3 thoughts on “draw line segments in matlab

  1. http://cort.as/3sjz

    I am really impressed with your writing talents and also
    with the structure to your weblog. Is this a paid theme
    or did you customize it yourself? Anyway stay up the nice high quality writing,
    it is rare to peer a nice blog like this one nowadays.
    .

    Reply
  2. www.felmedia.com

    I’ve written extensively about the menstrual cycle and problems during cycles
    in other publications and an in-depth discussion is beyond the scope of this article.
    You do, however, have control over just about everything else.
    I explained that for many years I read all I could
    on what different ailments require different vitamins and minerals to help relieve symptoms.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s