function [imo,hs,major_ori] = FAN_info(im)
% FAN_info - produce orientation & length info on segments
% On input:
%     im (MxNx3 array): RGB image
% On output:
%     imo (MxNx2 array): plane 1: orientation
%                        plane 2: longest segment in scan
%     hs (1x180 vector): smoothed orientation histogram
%     major_ori (px1 vector): orientation of major modes (degrees)
% Call:
%     im = imread('Picture.png');
%     [imo,hs,ori] = FAN_ino(im);
% Author:
%     T. Henderson
%     UU
%     Fall 2021
%

[M,N,P] = size(im);
imo = zeros(M,N,2);

img = rgb2gray(im);
G = fspecial('gaussian',5);
imG = imfilter(img,G);
ims = mat2gray(double(img)-double(imG));
imst = ims<0.3;

wb = waitbar(0,'FAN');
for r = 9:M-8
    waitbar(r/M);
    for c = 7:N-6
        [r,c];
        if imst(r,c)>0
            scan = MNDAS_range_scan(imst,r,c);
            scan2 = scan(1:180) + scan(181:360);
            ori = find(max(scan2)==scan2);
            imo(r,c,1) = ori(1) - 1;
            imo(r,c,2) = scan2(ori(1));
        end
    end
end
close(wb);

[rows,cols] = find(imo(:,:,2)>10);
vals = zeros(length(rows),1);
 for p = 1:length(rows)
    vals(p) = imo(rows(p),cols(p),1);
end
h = hist(vals,180);
hs = imfilter(h,ones(1,7)/7);
for k = 1:10
    hs = imfilter(hs,ones(1,7)/7);
end
lm = CS4640_local_max_1D(hs);
major_ori = find(lm);

tch = 0;
