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:
value of first and second derivative for image

Subject: value of first and second derivative for image

From: mira

Date: 7 Apr, 2010 16:02:11

Message: 1 of 10

hey everybody,

I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image. Is there any way to do that.
Any help is appreciated and thanks a lot.

mira

Subject: value of first and second derivative for image

From: Roger Stafford

Date: 7 Apr, 2010 17:49:25

Message: 2 of 10

"mira " <files@mathworks.com> wrote in message <hpiaa3$q5l$1@fred.mathworks.com>...
> hey everybody,
>
> I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image. Is there any way to do that.
> Any help is appreciated and thanks a lot.
>
> mira

  In a two-dimensional situation, which would be the case for images, there are three different second partial derivatives involved: 1) the second derivative with respect to x, 2) the second derivative with respect to y, and 3) the cross second derivative with respect first to x and then to y (or visa versa.) Which of these are you interested in? For example, if you have the function

 f(x,y) = 3*x^2 - 7*x*y + 4*y^2

these three second derivatives would be 6, 8, and -7, respectively.

  You can use the 'gradient' function to find the two first derivatives of a quantity numerically. Then you can apply this function to each of these two results to get all four second derivatives. (The two cross derivatives should be substantially equal.)

  By the way, what quantity are you taking the derivatives of, the image intensity?

Roger Stafford

Subject: value of first and second derivative for image

From: Matt J

Date: 7 Apr, 2010 18:30:45

Message: 3 of 10

"mira " <files@mathworks.com> wrote in message <hpiaa3$q5l$1@fred.mathworks.com>...
> hey everybody,
>
> I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image.
==============

This is contradictory. You claim that the diff() function both does and doesn't do what you want in the same sentence.

Subject: value of first and second derivative for image

From: mira

Date: 7 Apr, 2010 18:42:26

Message: 4 of 10

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <hpigj5$3u8$1@fred.mathworks.com>...
> "mira " <files@mathworks.com> wrote in message <hpiaa3$q5l$1@fred.mathworks.com>...
> > hey everybody,
> >
> > I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image. Is there any way to do that.
> > Any help is appreciated and thanks a lot.
> >
> > mira
>
> In a two-dimensional situation, which would be the case for images, there are three different second partial derivatives involved: 1) the second derivative with respect to x, 2) the second derivative with respect to y, and 3) the cross second derivative with respect first to x and then to y (or visa versa.) Which of these are you interested in? For example, if you have the function
>
> f(x,y) = 3*x^2 - 7*x*y + 4*y^2
>
> these three second derivatives would be 6, 8, and -7, respectively.
>
> You can use the 'gradient' function to find the two first derivatives of a quantity numerically. Then you can apply this function to each of these two results to get all four second derivatives. (The two cross derivatives should be substantially equal.)
>
> By the way, what quantity are you taking the derivatives of, the image intensity?
>
> Roger Stafford


thank you Roger for your reply

I didn't really know that there are many types of derivatives the one I need is the first derivative to get frequency of gray scale changes in the binary image ( original image was .png and I made it binary using im2bw ) and from that I need the second derivative.

I need the results in numbers because they will be input for a neural network classifier.

Could you please tell me exactly how to get derivative for my image ( I knew it in calculas but not in images).

thanks in advance, regards,
mira

Subject: value of first and second derivative for image

From: ImageAnalyst

Date: 7 Apr, 2010 18:52:16

Message: 5 of 10

You can do it with the conv2() function - just pass in the correct
kernel, for example
-1 -1 -1
-1 8 -1
-1 -1 -1

Subject: value of first and second derivative for image

From: mira

Date: 7 Apr, 2010 20:19:10

Message: 6 of 10

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hpij0l$bvb$1@fred.mathworks.com>...
> "mira " <files@mathworks.com> wrote in message <hpiaa3$q5l$1@fred.mathworks.com>...
> > hey everybody,
> >
> > I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image.
> ==============
>
> This is contradictory. You claim that the diff() function both does and doesn't do what you want in the same sentence.

Matt J I did say that it gives the first and second derivative and it works fine , but I don't want the result as image I want it to be a numerical value that is the problem

Subject: value of first and second derivative for image

From: Matt J

Date: 7 Apr, 2010 21:10:05

Message: 7 of 10

"mira " <files@mathworks.com> wrote in message <hpipbu$lq5$1@fred.mathworks.com>...

> > > I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image.
> > ==============
> >
> > This is contradictory. You claim that the diff() function both does and doesn't do what you want in the same sentence.
>
> Matt J I did say that it gives the first and second derivative and it works fine , but I don't want the result as image I want it to be a numerical value that is the problem
=================

Then you need to explain your semantics better, in particular, why you think the derivative can produce only a single value when in general the derivative of any function is another function, and not a scalar.

The output of differentiation operation is a scalar in specific circumstances, like if you are taking a derivative at one specifc point, but you need to say if that's the situation that applies here.

Subject: value of first and second derivative for image

From: Roger Stafford

Date: 7 Apr, 2010 21:14:05

Message: 8 of 10

"mira " <files@mathworks.com> wrote in message <hpipbu$lq5$1@fred.mathworks.com>...
> "Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <hpij0l$bvb$1@fred.mathworks.com>...
> > "mira " <files@mathworks.com> wrote in message <hpiaa3$q5l$1@fred.mathworks.com>...
> > > hey everybody,
> > >
> > > I have a problem finding the first and second derivative of an image, I think the the diff() method does that, but I don't want to apply it to the image what I want is to find the value ( numerical one ) of the 1'st & 2'nd derivative for the image.
> > ==============
> >
> > This is contradictory. You claim that the diff() function both does and doesn't do what you want in the same sentence.
>
> Matt J I did say that it gives the first and second derivative and it works fine , but I don't want the result as image I want it to be a numerical value that is the problem

  Mira, when you said "frequency" in "... first derivative to get frequency of gray scale changes ..." that was the first clue I had that you could be talking about derivatives with respect to time, not space. If that is what you mean, then yes, there would only be one second derivative with respect to time for each pixel of an image changing in time. Is that what you meant?

  As to the "numerical" you speak of, the 'diff' function in matlab can find symbolic derivatives or differences in numerical arrays depending on what kind of argument it is given. (It is unfortunate in my opinion that Mathworks used the same name for both functions.) The numerical differences with 'diff' are probably not a good way of computing numerical derivatives. You should use the 'gradient' function instead because it allows you to set in the values of interval steps in the independent variable to ensure reliable derivatives.

  You still appear to be contradicting yourself when you say that "it works fine" but you want it "to be a numerical value". The only way I see out of this contradiction is that you were speaking of a symbolic derivative of the kind that 'diff' can produce on symbolic expressions. However, I find it difficult to imagine that you actually possess symbolic expressions for each image pixel value as functions of time. If you don't have such symbolic expressions, what can you possibly mean by "it works fine"? What works fine? Can you straighten out that apparent contradiction for us, please?

  A lot of time is being wasted in this thread through unclear statements.

Roger Stafford

Subject: value of first and second derivative for image

From: Walter Roberson

Date: 7 Apr, 2010 21:33:47

Message: 9 of 10

Roger Stafford wrote:

> You still appear to be contradicting yourself when you say that "it
> works fine" but you want it "to be a numerical value". The only way I
> see out of this contradiction is that you were speaking of a symbolic
> derivative of the kind that 'diff' can produce on symbolic expressions.


Either that or mira had not yet understood that as far as Matlab is concerned,
"image" and "array" are the same thing --- that once an image has been read in
from a file, it becomes a Matlab array and can be operated on mathematically;
and that, likewise, any Matlab array within certain constraints can be
displayed as an image.

Subject: value of first and second derivative for image

From: ImageAnalyst

Date: 8 Apr, 2010 01:09:18

Message: 10 of 10

On Apr 7, 2:52 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> You can do it with the conv2() function - just pass in the correct
> kernel, for example
> -1 -1 -1
> -1  8 -1
> -1 -1 -1

------------------------------------------------------------------------------
mira:
If you want to see how you can do it with convolution or imfilter,
just check out
http://www.ph.tn.tudelft.nl/Courses/FIP/noframes/fip-Derivati.html
for examples.

Tags for this Thread

No tags are associated with 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