function map = convert2uint8(map,RANGE)
% convert2uint8 - convert feature maps (a cell array) into uint8 format.
%	Uint8 format is usually sufficient to store S1/M1 maps, and saves a lot of space.

if iscell(map)
    for i = 1:numel(map)
        map{i} = max(RANGE(1),map{i});
        map{i} = min(RANGE(2),map{i});
        map{i} = uint8(floor( (map{i} - RANGE(1)) / (RANGE(2)-RANGE(1)) * 256));
    end
else
    map = max(RANGE(1),map);
    map = min(RANGE(2),map);
    map = uint8(floor( (map - RANGE(1)) / (RANGE(2)-RANGE(1)) * 256));
end


