Displaying the gradient of an image

Hello,

I'm playing with some image processing algorithm (HOG descriptor) and I'm a bit lost. I am a newbie in image processing (especially in python).

I have computed the vertical and horizontal gradients of an image (convolution with [-1, 0, 1] on the 0 and 1 axis respectively). After that I computed the gradient' magnitude (sqrt(horizontal_gradient**2 + vertical_gradient**2)) and orientation (arctan2(vertical_gradient, horizontal_gradient)).

Now I would like to display the original image with the gradient vector. The quiver() function allows to plot vector fields and it's pretty easy to convert the gradient' magnitude and orientation into U and V (U =grad_mag*cos(grad_orientation), V = grad_mag*sin(grad_orientation)) but I cannot figure out how to display the image and the gradient with the right orientation.

Can anyone help?

Thanks in advance,
Mathieu

Hello,

I finally found the solution. It's as simple as:
figure();
imshow(img);
pylab.quiver(U, V, units='x');

Mathieu

Hi,

You can also use Numpy.gradient to compute the gradient , if e.g. your dx and dy aren’t the same.

Cheers,

Thom

···

Thomas Lecocq
Geologist
Ph.D.Student (Seismology)
Royal Observatory of Belgium


Date: Tue, 29 Jun 2010 16:28:11 +0200
From: mathieu.dubois@…2154…
To: matplotlib-users@…1543…rge.net
Subject: Re: [Matplotlib-users] Displaying the gradient of an image

Hello,

I finally found the solution. It’s as simple as:
figure();
imshow(img);
pylab.quiver(U, V, units=‘x’);

Mathieu


This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options