Calculating mean angles of edge detection

7 ビュー (過去 30 日間)
Anna Marshall
Anna Marshall 2020 年 4 月 19 日
コメント済み: Anna Marshall 2020 年 4 月 30 日
Hello,
I'm a new user of Matlab and am looking to calculate the mean and median angles of an image after performing an edge detection. I am using the following edge detection script adapted from the MathWorks edge detection example code and am looking to take it a step further in order to calculate the mean and median angles of the edge detection for each image I input. I eventually am looking to change the code from a specific image to a moving window. Additionally, I'm curious whether it is possible to calculate the number of horizontal, vertical, and diagonal edges from the edge detection output?
Thank you!
clear
RGB=imread('DJI_0022.jpg'); %inputs image
I=rgb2gray(RGB); %convers to grayscale
figure
imshow(I)
%%
%https://www.mathworks.com/help/images/ref/edge.html
%two different types of edge detection
BW1 = edge(I,'Canny');
BW2 = edge(I,'Prewitt');
figure
imshowpair(BW1,BW2,'montage')
%%
%https://www.mathworks.com/matlabcentral/answers/8591-edge-direction
%vertical
BWv = imopen(BW1,[1 1 1]');
%horizontal:
BWh = imopen(BW1,[1 1 1]);
%top left to lower right
BWd = imopen(BW1,[1 0 0; 0 1 0; 0 0 1]);
%%
%plot results
figure
subplot(3,1,1)
imshow(BWv);
title('vertical')
subplot(3,1,2)
imshow(BWh);
title('horizontal')
subplot(3,1,3)
imshow(BWd);
title('diagonal')
  3 件のコメント
darova
darova 2020 年 4 月 20 日
  • I'm curious whether it is possible to calculate the number of horizontal, vertical, and diagonal edges from the edge detection output?
Yes. THe answer is yes. Use bwlabel
[L,n] = bwlabel(BWh,4); % '4' is connection
Little explanation:
I'd use 4 connected object for horizontal and vertical lines. And 8 connected object for diagonals
See more here: bwlabel
Anna Marshall
Anna Marshall 2020 年 4 月 21 日
Thanks so much! I tried it out and bwlabel works great. Any ideas on how to calculate mean angles for each direction (horizontal, vertical, and diagonal)?

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

採用された回答

darova
darova 2020 年 4 月 21 日
Try regionprops with orientation property
Example
BWd1 = 1.0*BWd;
data = regionprops(BWd,'orientation','pixelidxlist'); % get orientation and pixels list of each region
for i = 1:numel(data)
idx = data(i).PixelIdxList; % pixel indices of current region
ori = data(i).Orientation; % orintation of region
BWd1(idx) = ori; % assign angle value
end
imagesc(BWd1)
colorbar
  15 件のコメント
darova
darova 2020 年 4 月 30 日
Try wrapTo360
Anna Marshall
Anna Marshall 2020 年 4 月 30 日
Thanks! I'll give that a try

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 4 月 21 日
If you have the Computer Vision Toolbox, try extractHOGFeatures() to get the histogram of oriented gradients.
  1 件のコメント
Anna Marshall
Anna Marshall 2020 年 4 月 21 日
The extractHOGFeatures() tool is neat just from working throught the examples. Is there a way to clip the tool to a specific area of the image or train it so that it is only extratcting the HOG features for the area of interest. For example, in the image attached, I am interested in looking at the logs but not the vegetation and trees. Thank you!

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

Community Treasure Hunt

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

Start Hunting!

Translated by