No BSD License  

Highlights from
Connect two pixels

3.72727

3.7 | 11 ratings Rate this file 8 Downloads (last 30 days) File Size: 2.6 KB File ID: #4211

Connect two pixels

by Kanchi

 

03 Dec 2003 (Updated 03 Dec 2003)

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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
03 Dec 2003 HY WANG  
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!!

24 Apr 2004 chim wicket

very good, it save much time for me.

07 Jun 2004 Afshan naz  
21 Nov 2004 Yuan luo

good

09 Aug 2005 kevino z

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

05 May 2006 Saeed Mozaffari

It works well

30 May 2006 Ed Zwaan

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

27 Apr 2007 cano lee

interesting, but could u disclose more technical details?

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 !

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.

23 Feb 2008 Jamie Schirf

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

28 Jun 2010 Omar

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
gui Kanchi 22 Oct 2008 07:10:07
display Kanchi 22 Oct 2008 07:10:07
annotation Kanchi 22 Oct 2008 07:10:07
line image draw Kanchi 22 Oct 2008 07:10:07

Contact us at files@mathworks.com