I want to read in an image - a picture of a circle, and compute the gradient vector field of that image (ie vectors pointing out uniformly and at normal to the circle). My l
You have made a mistake in the code (other than that, it works fine). You should replace the following:
u = dx;
v = dy;
not
u = x;
v = y;
It works with this image like a charm!
EDIT: If you want to super-impose the vectors on the image, then do the following:
clear all;
im = imread('littlecircle.png');
[nr,nc]=size(im);
[dx,dy] = gradient(double(im));
[x y] = meshgrid(1:nc,1:nr);
u = dx;
v = dy;
imshow(im);
hold on
quiver(x,y,u,v)
Notice that i do not convert the im to double, since it would not appear correctly with imshow (needs uint8). Depending on your image dimensions, you might want to zoom in in order to see the grad vectors.
You can see a zoomed in area of the vectors superimposed on the image, below:
Better quality image is at http://i.stack.imgur.com/fQbwI.jpg