Compute gradient vector field of an image

后端 未结 1 870
野趣味
野趣味 2020-12-29 08:58

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

相关标签:
1条回答
  • 2020-12-29 09:08

    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:

    Gradient vectors of a circle in an image

    Better quality image is at http://i.stack.imgur.com/fQbwI.jpg

    0 讨论(0)
提交回复
热议问题