gradients of image

2 ビュー (過去 30 日間)
priya
priya 2011 年 11 月 22 日
dx = 0.000283018867925 meters;
dy = 0.000089285714286 meters;
I am trying to find gradients of image of size 1000X1333. One pixel in x-direction represents dx and one pixel in y-direction represents dy. I applied two methods to find the gradients.. one is convolution method and the other is calling MATLAB gradient method. I was expecting the results to be identical but they are not. Would any one point out where I am going wrong. Below are the codes for convolution and gradient methods.
convolution method:
fx = conv2(image1,0.5*[-1 1; -1 1], 'same');
fy = conv2(image1,0.5*[-1 -1; 1 1], 'same');
fx = fx./dx;
fy = fy./dy;
MATLAB defined gradients:
[fx,fy] = gradient(image1,dx,dy);

回答 (2 件)

Jan
Jan 2011 年 11 月 22 日
Try the functions on simpler test data:
image1 = 1:10;
conv2(image1, 0.5 * [-1 1; -1 1], 'same')
% >> -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, 5
gradient(image1)
% >> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
gradient uses the central difference for the interior points:
image1 = rand(1, 10);
gradient(image1)
conv(image1, 0.5 * [1, 0, -1], 'same')
Now the interior points are equal, but the edges differ. This can be expanded to the 2D case also.
  2 件のコメント
priya
priya 2011 年 11 月 28 日
Thanx for the reply. Do you know any links to understand conv2 by example. I looked into matlab documentation but I couldn't understand anything.
Srinibas Bhuyan
Srinibas Bhuyan 2012 年 11 月 28 日
did you try with any one of prewitt/sobel operator?

サインインしてコメントする。


Matt J
Matt J 2012 年 11 月 28 日
編集済み: Matt J 2012 年 11 月 28 日
Also, if you want non-central differences, as in your original code, you need to flip the kernels, since this is convolution and not correlation:
fx = conv2(image1,0.5*[1 , -1], 'same');
fy = conv2(image1,0.5*[1 ; -1], 'same');

カテゴリ

Help Center および File ExchangeSignal Processing Toolbox についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by