# How to find derivative of an image along a radial direction with an arbitrary center of rotation?

I want to find the derivative of an image along a radial direction. For instance, in the image below I want to find the gradient at a point $P$ of the image, along the direction of the circumference of the circle.

Just like we do image intensity derivatives $\frac{dI}{dx}$ or $\frac{dI}{dy}$, all I want to do is to find $\frac{dI}{dr}$ where $r$ is a variable that stores the rotation angle of the image with a particular center.

From what I know we need to follow chain rule of partial differentiation. $$\frac{dI}{dr} = \frac{dI}{dx} \cdot \frac{dx}{dr}$$

We know $\frac{dI}{dx}$ but how to find $\frac{dx}{dr}$?

Essentially, you want to compute the derivative of your image in polar coordinates. Have a look here in particular equation (15):

Your image is given in cartesian coordinates: $I(x,y)$ where $x,y$ are column and row. You want to know the expression

$$\frac{dI(r,\phi)}{d\phi}$$

where $I(r,\phi)$ is the image in polar coordinates. $r,\phi$ relate to $x,y$ by the expressions

\begin{align} x &= r\cos(\phi)\\y &= r\sin(\phi) \end{align}

Now, using the chain rule we get

$$\frac{dI}{d\phi}=\frac{dI}{dx}\frac{dx}{d\phi}+\frac{dI}{dy}\frac{dy}{d\phi}=-\frac{dI}{dx}(r\sin\phi)+\frac{dI}{dy}(r\cos\phi)$$

where $\frac{dI}{dx}$ and $\frac{dI}{dy}$ are the gradients in cartesian coordinates.