Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
numerically labeling line segments in an image

Subject: numerically labeling line segments in an image

From: Kate

Date: 1 Sep, 2010 03:17:02

Message: 1 of 2


Hello guys,

would like some help. In my code below I draw 2 line segments. I have an index called 'EE' in the code so it knows that there are 2 line to be drawn (i.e. first column of EE) and also the lines' starting and end points (i.e. second and third colums respectively of EE).


I want to label these 2 lines with labels "1" and "2" respectively.

The following link has an example image of the type of line labeling I would like to do:

http://img576.imageshack.us/i/labelines.png/

%=========================================
clc;
clear all;
close all;

RR= [4 5;
         8 8;
         9 9;
         5 8]
x2 = RR(:,1);
y2 = RR(:,2);


EE = [1 1 2;
         2 3 4]

line_number = EE(:,1)
pt1_of_a_line = EE (:,2)
pt2_of_a_line= EE (:,3)
number_of_lines = length(line_number);

 for i = 1:number_of_lines
    first_pt_of_line2(i) = pt1_of_a_line(i)
    second_pt_of_line2(i) = pt2_of_a_line(i)
    
    
    X_coord_pt12(i)= x2(first_pt_of_line2(i))
    Y_coord_pt12(i)= y2(first_pt_of_line2(i))
    X_coord_pt22(i)= x2(second_pt_of_line2(i))
    Y_coord_pt22(i)= y2(second_pt_of_line2(i))
    
    Xpt12 = X_coord_pt12'
    Ypt12 = Y_coord_pt12'
    Xpt22 = X_coord_pt22'
    Ypt22 = Y_coord_pt22'
   twolines(i)=line([ Xpt12(i) Xpt22(i)], [Ypt12(i) Ypt22(i)] ,'Color', 'r','LineStyle',' - ','Linewidth' ,2 )

end
%=========================================

Thanks
kate

Subject: numerically labeling line segments in an image

From: Neil

Date: 1 Sep, 2010 06:47:22

Message: 2 of 2

"Kate " <chino_tones@hotmail.com> wrote in message <i5kgje$ud$1@fred.mathworks.com>...
>
> Hello guys,
>
> would like some help. In my code below I draw 2 line segments. I have an index called 'EE' in the code so it knows that there are 2 line to be drawn (i.e. first column of EE) and also the lines' starting and end points (i.e. second and third colums respectively of EE).
>
>
> I want to label these 2 lines with labels "1" and "2" respectively.
>
> The following link has an example image of the type of line labeling I would like to do:
>
> http://img576.imageshack.us/i/labelines.png/
>
> %=========================================
> clc;
> clear all;
> close all;
>
> RR= [4 5;
> 8 8;
> 9 9;
> 5 8]
> x2 = RR(:,1);
> y2 = RR(:,2);
>
>
> EE = [1 1 2;
> 2 3 4]
>
> line_number = EE(:,1)
> pt1_of_a_line = EE (:,2)
> pt2_of_a_line= EE (:,3)
> number_of_lines = length(line_number);
>
> for i = 1:number_of_lines
> first_pt_of_line2(i) = pt1_of_a_line(i)
> second_pt_of_line2(i) = pt2_of_a_line(i)
>
>
> X_coord_pt12(i)= x2(first_pt_of_line2(i))
> Y_coord_pt12(i)= y2(first_pt_of_line2(i))
> X_coord_pt22(i)= x2(second_pt_of_line2(i))
> Y_coord_pt22(i)= y2(second_pt_of_line2(i))
>
> Xpt12 = X_coord_pt12'
> Ypt12 = Y_coord_pt12'
> Xpt22 = X_coord_pt22'
> Ypt22 = Y_coord_pt22'
> twolines(i)=line([ Xpt12(i) Xpt22(i)], [Ypt12(i) Ypt22(i)] ,'Color', 'r','LineStyle',' - ','Linewidth' ,2 )
>
> end
> %=========================================
>
> Thanks
> kate

Try add:
text(Xpt12(i),Ypt12(i),num2str(i),'FontSize',10)
in your for loop. It is not perfect. You might want to play with the offset.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us