How do i create a matrix of border angles?
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
Image Analyst
on 8 Sep 2013
There is no function border() in base MATLAB or the Image Processing Toolbox. Is your border the border of the image - straight lines at the outer edges - or are they boundaries of objects in an image, like you'd get from the edge() function?
Neta
on 9 Sep 2013
Neta
on 10 Sep 2013
Answers (2)
Something like this, maybe
[gx,gy] = gradient(YourImage);
AngleMap = atan2(gx,gy)*180/pi; %in degrees, not radians
AngleMap(~(gx|gy))=nan;
5 Comments
Image Analyst
on 8 Sep 2013
There is a "d" version of atan2 - atan2d - like there is for all the other trig functions. They take or return degrees instead of radians.
Image Analyst
on 8 Sep 2013
I know people here in answer have asked about it using R2010b, at least sind() link - surprised that they didn't add tangent when they were adding the others.
Neta
on 8 Sep 2013
Here's another variation which works better,
gx=diff(YourImage,1,2); gx(:,end+1)=0;
gy=diff(YourImage,1,1); gy( end+1,:)=0;
AngleMap = atan2d(gx,gy)+90;
AngleMap(~YourImage)=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
Neta
on 10 Sep 2013
Image Analyst
on 10 Sep 2013
You can use conv2() with kernels oriented in the vertical and horizontal direction: [-1,1] and [-1;1].
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!