function dsimage = downsample(image, ratio, method)

switch method
    case 'rect'
        filt = ones(ratio, ratio) / ratio^2;
    otherwise
        error('downsample:invalid_argument', ...
            'Invalid downsampling method: ''%s''', method);
end

% apply filter to chroma components, do not apply to luma
dsimage = conv2(image, filt, 'same');

% decimate
dsimage = dsimage(1:ratio:end, 1:ratio:end);

end
