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:
How can I find a slope of a line in a image with Mathlab

Subject: How can I find a slope of a line in a image with Mathlab

From: kerry william

Date: 15 Sep, 2009 04:48:01

Message: 1 of 6

I am new to Mathlab and I am also new to image process. I want to explorer the power of Mathlab by working on small project alone but it is not a easy job.

I would like to calculate the area of an object in an image in mathlab but it seems impossible to me to do as my skill/experience is limited (I have an image process using Matlab but it does not help at all) so I decide to learn simple thing first.

Now I would like to learn how to calculate the slope of a line in an but I have no clue. Can some one give me a hint or a sample code?
http://i32.tinypic.com/303eis8.jpg

Subject: How can I find a slope of a line in a image with Mathlab

From: kerry william

Date: 15 Sep, 2009 04:57:01

Message: 2 of 6

I mean that I have an image processing book but it does not help me to do the job I want. The book covers a lot of concepts in image processing but I am unclear about the applications of these concepts.

Subject: How can I find a slope of a line in a image with Mathlab

From: Ken Campbell

Date: 15 Sep, 2009 05:14:01

Message: 3 of 6

"kerry william" <kerry2000620007@yahoo.com> wrote in message <h8n6qt$nks$1@fred.mathworks.com>...
> I mean that I have an image processing book but it does not help me to do the job I want. The book covers a lot of concepts in image processing but I am unclear about the applications of these concepts.

Other people will have better ways (if they answer) but a simple way of doing this might be:

1) Read in the image (doc imread) as a matrix.
2) Turn the matrix to 2D (if the image is RGB or similar)
3) Find the pixels that are black (they will have different values in the matrix than the ones that are white).
4) Find the left-most black pixel (coordinates x1,y1) and the right-most black pixel (x2,y2).
5) Gradient is delta(y)/delta(x).

That's a method that is logical and easy to follow. It's far from the best way, but I think you could learn to program that in MATLAB if you wanted.

Ken

Subject: How can I find a slope of a line in a image with Mathlab

From: ImageAnalyst

Date: 16 Sep, 2009 02:44:27

Message: 4 of 6

On Sep 15, 12:57 am, "kerry william" <kerry2000620...@yahoo.com>
wrote:
> I mean that I have an image processing book but it does not help me to do the job I want.  The book covers a lot of concepts in image processing but I am unclear about the applications of these concepts.

-------------------------------------------------------------------------------------
Kerry:

If you somehow extract ALL the coordinates of the line and want the
best fit line, just pass in the coordinates into polyfit() and it will
give you the slope directly as one of its outputs.

A helpful tutorial might be
http://www.mathworks.com/matlabcentral/fileexchange/25157

Subject: How can I find a slope of a line in a image with Mathlab

From: Toan Cao

Date: 2 Mar, 2010 03:01:06

Message: 5 of 6

hi, everyone!
i am also new user in image processing with Matlab.
I met a problem when i studied programming in my work.
I have a set of points of a curve in image. I would like to compute the slope of tangents at every point of the curve ( The function of curve is unknown).
So, who can help me to do that ?. Thank you very much !!!
I'm sorry if my question is foolish.

Subject: How can I find a slope of a line in a image with Mathlab

From: Walter Roberson

Date: 2 Mar, 2010 03:34:52

Message: 6 of 6

Toan Cao wrote:
> hi, everyone!
> i am also new user in image processing with Matlab.
> I met a problem when i studied programming in my work.
> I have a set of points of a curve in image. I would like to compute the
> slope of tangents at every point of the curve ( The function of curve is
> unknown).
> So, who can help me to do that ?. Thank you very much !!!
> I'm sorry if my question is foolish.

In the below diagram, let O represent an open (unfilled) pixel, and let
X represent a filled pixel, and let the bottom left pixel be for the
coordinates (0,0); as usual, let X increase to the right and Y increase
upwards.

OOXXX
XXOOO

Now, what is the slope of the tangent of each of the lit pixels?

Answer: you can't tell. The diagram is correct for both the slope 1 in 3
and the slope 1 in 4, if one makes the assumption that in determining
which pixel to light, one does standard rounding of the coordinates --
that, in particular, 0.5 is rounded to 1.

[0, 1/3, 2/3, 3/3, 4/3] rounds to [0, 0, 1, 1, 1]
[0, 1/4, 2/4, 3/4, 4/4] rounds to [0, 0, 1, 1, 1]

Now if you cannot accurately determine the slope of the pixels for this
representation of a simple line, then how can you hope to determine the
slope of a curve? Indeed, how do you know that this isn't the diagram
for a simple curve? Or even the diagram for an S curve?

If you only have discrete pixels and do not have the original function,
it is not theoretically possible to determine _with certainty_ the
tangents of the points.

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