function [Ismall] = chopSphImage(I,azRange,altRange,type)
% FUNCTION TO CROP A RANGE OF AZIMUTH AND ALTITUDE FROM A FULL 360 BY 180 SPHERICAL PANAROMA

%INPUTS:
%   I - input image (color or BW)
%   azRange - azimuth range
%   altRange - altitude range
%   type - 'c' for color or 'b' for BW

%OUTPUT:
%   Ismall - chopped image

azRange = azRange.*pi./180;
altRange = altRange.*pi./180;

[H,W,~] = size(I);
scale_az = W/2/pi;
scale_alt = H/pi;

W1 = round((pi-azRange(1))*scale_az);
W2 = round((pi-azRange(2))*scale_az);
H1 = round((pi/2 - altRange(1))*scale_alt);
H2 = round((pi/2 - altRange(2))*scale_alt);

if type == 'c'
    Ismall = I(H1:H2,W1:W2,:);
else
    Ismall = I(H1:H2,W1:W2);
end