function out = equalScaling(in,scale)
%***********************************************************************
% This function scales the input image to scale¡Áscale without distorting. The
% main idea is to scale the bigger one of height and width to (scale-1), and the
% left one  will be scaled with the same ratio. Finally, the scaled image
% will be put in the center of the matrix with a size of scale¡Áscale.
%
% input:
%         in: the input image (1 channel)
%         scale: the target dimension
% output:
%         out: the output image with a size of scale¡Áscale (3 channel)
%**************************************************************************
%
% Createded by Kaichang CHENG in Oct. 28, 2019.
%
%====================================================================
out=double(in(1,1)).*ones(scale,scale);
[h,w]=size(in);
if (h>w)
    in0=imresize(in,(scale-2)/h);
    [h0,w0]=size(in0);
    h_start=2;
    h_end=2+h0-1;
    w_start=round(abs(scale-w0)/2)+1;
    w_end=w_start+w0-1;
else
    in0=imresize(in,(scale-2)/w);
    [h0,w0]=size(in0);
    w_start=2;
    w_end=1+w0;
    h_start=round(abs(scale-h0)/2)+1;
    h_end=h_start+h0-1;
end
out(h_start:h_end,w_start:w_end)=in0;

out = cat(3, uint8(out),uint8(out),uint8(out));
end

