function [ filtered ] = bilateralFilter( im,maskSize,sigmaC,sigmaS )
%BILATERALFILTER Summary of this function goes here
%   Detailed explanation goes here
msh = floor(maskSize/2);
[U,V] = ndgrid(-msh:msh,-msh:msh);

closeness = (1./sqrt(2*pi*(sigmaC.^2))).*exp(-0.5.*(U.^2+V.^2)./(sigmaC.^2));
filtered=zeros(size(im));

%uncomment for debugging
%figure()
for y=msh+1:size(im,1)-msh
    for x=msh+1:size(im,2)-msh
        
        % Mask pixels will contain the subregion of the image which is
        % inside the filter mask around point (x,y)
        maskPixels=%???
        
        % IntensityDifferencec contains the difference of the maskPixels'
        % intensities and the intesity at point (x,y)
        intensityDifferences = %???
        
        % Weight the Differences by a Gaussian
        similarity = %???
        
        % Compute the combined weight for each pixel inside the mask
        weights= %???
        
        % Compute the new pixel intensity at the mask center
        filtered(y,x)= %???
        
        %uncomment for debugging
        %subplot(2,2,1); imagesc(maskPixels);
        %title('image region inside the mask')
        %subplot(2,2,2); imshow(intensityDifferences,[]);
        %title('similarity')
        %subplot(2,2,3); imshow(weights,[]);
        %title('final weights')
        %input('press Enter');
    end
end
        

end

