Why should I rotate an image before applying canny filter?

11 views (last 30 days)
soyoung shin on 2 Nov 2016
Answered: Kushagr Gupta on 7 Nov 2016
1) I am using a code below to detect a terrain slope from images. By the way, why should I rotate the image before applying 'canny' filter? Is it okay to skip the 'imrotate'?
2) I took some pictures outside(asphalt road) and I used this code below. Then, I can see a green line on the image. However, I should open the plot window to know the gradient of the green line. Is there any possible way to display the gradient information on the figure window? or can I collect the gradient information in simple way?
3) And I only need a gradient line in the center of the image. How I only have a center line?
rotI = imrotate(I, 0 ,'crop'); % <<<<< why I need to rotate?????
BW = edge(rotI,'canny');
[H,T,R] = hough(BW);
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
axis on, axis normal, hold on;
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = T(P(:,2));
y = R(P(:,1));
plot(x,y,'s','color','white');
% Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',5,'MinLength',7);
figure, imshow(rotI), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
Thank you for your time!! Any comment will be very happy for me!

Kushagr Gupta on 7 Nov 2016