计算图像的梯度矢量场 [英] Compute gradient vector field of an image

查看:1216
本文介绍了计算图像的梯度矢量场的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像中读取 - 圆形图片,并计算该图像的渐变矢量场(即向量均匀指向并垂直于圆圈的向量)。我的逻辑让我失望了,但我有:

 全部清除; 
im = im2double(imread('littlecircle.png'));
im = double(im);
[nr,nc] = size(im);
[dx,dy] = gradient(im);
[x y] = meshgrid(1:nc,1:nr);
u = x;
v = y;
箭袋(x,y,u,v)

如果我只想做上面,我得到一个矢量场,但它只是一个空网格的梯度(即只是一个渐变的矢量场y = x)。我真正想要的是使用

  [dx,dy] = gradient(im); 

检测图像中圆圈的边缘,然后计算由于在图像中的圆圈。很明显,指定u = x和v = y只会给我一条直线的矢量场 - 所以基本上,我想把图像的渐变嵌入到矢量u和v中。我该怎么做?





解决方案

你在代码中犯了一个错误(除此之外,它工作正常)。您应该替换以下内容:

  u = dx; 
v = dy;

  u = x; 
v = y;

适用于


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 logic is failing me a bit, but I have:

clear all;
im = im2double(imread('littlecircle.png'));
im = double(im);
[nr,nc]=size(im);
[dx,dy] = gradient(im);
[x y] = meshgrid(1:nc,1:nr);
u = x;
v = y;
quiver(x,y,u,v)

if I were to simply do the above, I get a vector field, but it is simply the gradient of an empty mesh (ie just a vector field of the gradient y=x). What I actually want is to use

[dx,dy] = gradient(im);

to detect the edges of the circle in the image, and then compute the gradient vector field due to the circle in the image. obviously, assigning u=x and v=y will only give me the vector field of a straight line - so bascially, I want to embed the gradient of the image into the vectors u and v. How do I do this?

解决方案

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

这篇关于计算图像的梯度矢量场的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆