How do i create a matrix of border angles?
2 views (last 30 days)
Show older comments
Hello, My input is a matrix of a black-white border image (created with the function border()) i want to create a matrix corresponding to that matrix, that hold the rotation angle values of the border in each pixels (and NaN in the pixels that are not part of the border). for example- if my image is a vertical line, then i get in the line's pixels values of zero, and the rest of the matrix will be NaN. Thanks!
3 Comments
Answers (2)
Matt J
on 8 Sep 2013
Edited: Matt J
on 8 Sep 2013
Something like this, maybe
[gx,gy] = gradient(YourImage);
AngleMap = atan2(gx,gy)*180/pi; %in degrees, not radians
AngleMap(~(gx|gy))=nan;
Image Analyst
on 9 Sep 2013
Why not just use imgradient() in the Image Processing Toolbox. It gives you both gradient magnitude and gradient direction, like this example from the help shows:
% Read image and compute gradient magnitude
% and gradient direction using Prewitt's gradient operator.
I = imread('coins.png');
[Gmag, Gdir] = imgradient(I,'prewitt');
figure
imshowpair(Gmag, Gdir, 'montage');
title('Gradient Magnitude, Gmag (left), and Gradient Direction, Gdir (right), using Prewitt method')
axis off;
2 Comments
Image Analyst
on 10 Sep 2013
You can use conv2() with kernels oriented in the vertical and horizontal direction: [-1,1] and [-1;1].
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!