myofibrometry / matlab / orientation / splitIntoSectors.m
splitIntoSectors.m
Raw
function [Sectors,sectorMask] = splitIntoSectors(helixAngles,count,penetrationMask)
    if nargin < 2
        count = 6;
        penetrationMask = zeros(512,512);
    end
    if nargin < 3
        penetrationMask = zeros(512,512);
    end
    offset = 0;
    Sectors = cell(1,count);
    sectorMask = zeros(size(penetrationMask));
    [boundaryPoints, penetrationLength] = size(helixAngles);
    for pt = 1:boundaryPoints
        helix_angle = helixAngles(pt,:);
        last = penetrationLength;
        start = 1;
        % remove leading zeros/maxvalue... due to extended mask
        while(((helix_angle(start) > 1.57) || isnan(helix_angle(start))) && (start < last))
            start = start +1;
        end
        helix_angle = padarray(helix_angle,[0,start-1],NaN,'post');
        last = last + start-1;
        helix_angle = helix_angle(start:last);
        %helix_angle(last-start+2:maxLength) = NaN;
        plt =  count - floor(mod((pt/boundaryPoints)*360 + offset , 360)*count/360);
        Sectors{plt} = [Sectors{plt};helix_angle];
        sectorMask(penetrationMask == pt) = plt;
    end
end