Matlab中的census,图像处理中的census变换

%*************************************************************************

%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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值