%*************************************************************************
%Title:Function-CensusTransformofagivenImage
%Author:SiddhantAhuja
%Created:May2008
%CopyrightSiddhantAhuja,2008
%Inputs:Image(var:inputImage),Windowsizeassumingsquarewindow(var:
%windowSize)of3x3or5x5only.
%Outputs:CensusTranformedImage(var:censusTransformedImage),
%Timetaken(var:timeTaken)
%ExampleUsageofFunction:[a,b]=funcCensusOneImage('Img.png',3)
%*************************************************************************
function[censusTransformedImage,timeTaken]=funcCensusOneImage(inputImage,windowSize)
%Grabtheimageinformation(metadata)usingthefunctionimfinfo
try
imageInfo=imfinfo(inputImage);
% Since Census Transform is applied on a grayscale image, determine if the
% input image is already in grayscale or color
if(getfield(imageInfo,'ColorType')=='truecolor')
% Read an image using imread function, convert from RGB color space to
% grayscale using rgb2gray function and assign it to variable inputImage
inputImage=rgb2gray(imread(inputImage));
elseif(getfield(imageInfo,'ColorType')=='grayscale')
% If the image is already in grayscale, then just read it.
inputImage=imread(inputImage);
else
error('The Color Type of Input Image is not acceptable. Acceptable color types are truecolor or grayscale.');
end
end
catch
inputImage=inputImage;
end
%Findthesize(columnsandrows)oftheimageandassigntherowsto
%variablenr,andcolumnstovariablenc
[nr,nc]=size(inputImage);
%Checkthesizeofwindowtoseeifitisanoddnumber.
if(mod(windowSize,2)==0)
error('The window size must be an odd number.');
end
if(windowSize==3)
bits=uint8(0);
%Createanimageofsizenrandnc,fillitwithzerosandassign
%ittovariablecensusTransformedImageoftypeuint8
censusTransformedImage=uint8(zeros(nr,nc));
elseif(windowSize==5)
bits=uint32(0);
%Createanimageofsizenrandnc,fillitwithzerosandassign
%ittovariable