开发者

gradient() function not working with images

I have a quick question. I'm trying to compute an images 2D gradient using the gradient() function in MATLAB, but its not working. Specifically, here's my code (The image I'm using is grayscale):

im = imread('C:\yosemite1.bmp'); g = FindImageGradients(im);

I get the following error:

??? Error using ==> rdivide Integ开发者_JAVA技巧ers can only be combined with integers of the same class, or scalar doubles.

Error in ==> gradient at 75 g(2:n-1,:) = (f(3:n,:)-f(1:n-2,:))./h(:,ones(p,1));

Any clues on how to solve this ?


Your image data is probably being read as integers in the range [0,255] (for 8 bit per color channel), so the type of im is uint8 or other int type. Try converting it to single or double:

g = FindImageGradients(single(im));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜