No BSD License  

Highlights from
Connect two pixels

3.83333

3.8 | 12 ratings Rate this file 16 Downloads (last 30 days) File Size: 2.6 KB File ID: #4211

Connect two pixels

by

 

03 Dec 2003 (Updated )

Draw a line between two pixels with any grayscale in any image.

| Watch this File

File Information
Description

Connect two pixels in an image with the desired graylevel

Command line
------------
result = func_DrawLine(Img, X1, Y1, X2, Y2)
input: Img : the original image.
          (X1, Y1), (X2, Y2) : points to connect.
          nG : the gray level of the line.
output: result

Note
----
  Img can be anything
  (X1, Y1), (X2, Y2) should be NOT be OUT of the Img

  The computation cost of this program is around half as Cubas's [1]
  [1] As for Cubas's code, please refer
  http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=4177

Example
-------
result = func_DrawLine(zeros(5, 10), 2, 1, 5, 10, 1)
result =
     0 0 0 0 0 0 0 0 0 0
     1 1 1 0 0 0 0 0 0 0
     0 0 0 1 1 1 0 0 0 0
     0 0 0 0 0 0 1 1 1 0
     0 0 0 0 0 0 0 0 0 1

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
26 Jul 2013 Putra A  
28 Jun 2010 Omar

Thanks for sharing.
I would suggest adding a line thickness option.

23 Feb 2008 Jamie Schirf

Thanks for sharing. This was just what I needed for a task.

31 Jul 2007 Graham Cranston

input coordinates X and Y are implemented inverted. That is, the coordinates given as X0 and X1 are used as the starting and ending ROW in the matrix, and vice versa. A simple find replace fixed the problem.

22 Jun 2007 Rajesh Govind

I agree there exists jaggedness while it traces the line, but otherwise, I like the implementation :) Good work appreciated .. this saved my time as well ! Thanks a ton !

27 Apr 2007 cano lee

interesting, but could u disclose more technical details?

30 May 2006 Ed Zwaan

It doesn't draw a line straight between the pixels, it has some offset.

05 May 2006 Saeed Mozaffari

It works well

09 Aug 2005 kevino z

yeah, it seems that the line is always one pixel to the right and above the start/end points

21 Nov 2004 Yuan luo

good

07 Jun 2004 Afshan naz  
24 Apr 2004 chim wicket

very good, it save much time for me.

29 Mar 2004 user anonymous

Does n't work really well - the lines are broken and sometimes it doesn't connect the two pixels at all!!

03 Dec 2003 HY WANG  

Contact us