function [cKernel] = ExtractKernel(KernelFunction,KWidth)
%---------------------
% Last Modification 05-12-2013
% Detail: To Make it applicable to negative edge
%--------------------

if mean(KernelFunction)<0
    KernelFunction=-KernelFunction;
end    

[cMax I]=max(KernelFunction);

if and(I-((KWidth-1)/2)>0,I+((KWidth-1)/2)<max(size(KernelFunction))) 
% to check whether the kernel is well centered.     
TempKernel=KernelFunction(uint8(I-((KWidth-1)/2)):uint8(I+((KWidth-1)/2))); %% chop
cKernel=TempKernel/cMax; % Normalized
else
cKernel=zeros(1,KWidth);
end

end