谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx

上传人:b****7 文档编号:22319533 上传时间:2023-02-03 格式:DOCX 页数:18 大小:18.16KB
下载 相关 举报
谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx_第1页
第1页 / 共18页
谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx_第2页
第2页 / 共18页
谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx_第3页
第3页 / 共18页
谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx_第4页
第4页 / 共18页
谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx

《谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx(18页珍藏版)》请在冰豆网上搜索。

谷速软件网matlab有偿编程matlab伯恩森本地图像阈值源码程序Word格式文档下载.docx

%----------

%TherearedifferentwayshowtoperformmeanfilteringinMATLAB.

%AneffectivewayforsmallneighborhoodsistouseIMFILTER:

%I=imread('

eight.tif'

);

%meanFilter=fspecial('

average'

[33]);

%J=imfilter(I,meanFilter);

%figure,imshow(I),figure,imshow(J)

%However,IMFILTERslowsdownwiththeincreasingsizeofthe

%neighborhoodwhileAVERAGEFILTERprocessingtimeremainsconstant.

%Andonceoneoftheneighborhooddimensionsisover21pixels,

%AVERAGEFILTERisfaster.Anyway,bothIMFILTERandAVERAGEFILTERgive

%thesameresults.

%Remarks

%-------

%TheoutputmatrixtypeisthesameasoftheinputmatrixA.

%Ifeitherdimesionoftheneighborhoodiseven,thedimensionis

%roundeddowntotheclosestoddvalue.

%Example

%J=averagefilter(I,[33]);

%SeealsoIMFILTER,FSPECIAL,PADARRAY.

%ContributedbyJanMotl(jan@motl.us)

%$Revision:

1.2$$Date:

2013/02/1316:

58:

01$

%Parameterchecking.

numvarargs=length(varargin);

ifnumvarargs>

2

error('

myfuns:

somefun2Alt:

TooManyInputs'

...

'

requiresatmost2optionalinputs'

end

optargs={[33]0};

%setdefaultsforoptionalinputs

optargs(1:

numvarargs)=varargin;

[window,padding]=optargs{:

};

%usememorablevariablenames

m=window

(1);

n=window

(2);

if~mod(m,2)m=m-1;

end%checkforevenwindowsizes

if~mod(n,2)n=n-1;

end

if(ndims(image)~=2)%checkforcolorpictures

display('

Theinputimagemustbeatwodimensionalarray.'

Considerusingrgb2grayorsimilarfunction.'

return

%Initialization.

[rowscolumns]=size(image);

%sizeoftheimage

%Padtheimage.

imageP=padarray(image,[(m+1)/2(n+1)/2],padding,'

pre'

imagePP=padarray(imageP,[(m-1)/2(n-1)/2],padding,'

post'

%Alwaysusedoublebecauseuint8wouldbetoosmall.

imageD=double(imagePP);

%Matrix'

t'

isthesumofnumbersontheleftandabovethecurrentcell.

t=cumsum(cumsum(imageD),2);

%Calculatethemeanvaluesfromthelookuptable'

.

imageI=t(1+m:

rows+m,1+n:

columns+n)+t(1:

rows,1:

columns)...

-t(1+m:

rows+m,1:

columns)-t(1:

rows,1+n:

columns+n);

%Noweachpixelcontainssumofthewindow.Butwewanttheaveragevalue.

imageI=imageI/(m*n);

%Returnmatrixintheoriginaltypeclass.

image=cast(imageI,class(image));

%BERNSENlocalthresholding.

%BW=BERNSEN(IMAGE)performslocalthresholdingofatwo-dimensional

%arrayIMAGEwithBernsen'

sthresholding.Themethodusesa

%user-providedcontrastthreshold.Ifthelocalcontrast(max-min)is

%aboveorequaltothecontrastthreshold,thethresholdissetatthe

%localmidgreyvalue(themeanoftheminimumandmaximumgreyvaluesin

%thelocalwindow).Ifthelocalcontrastisbelowthecontrast

%thresholdtheneighbourhoodisconsideredtoconsistonlyofoneclass

%andthepixelissettoobjectorbackgrounddependingonthevalueof

%themidgrey.

%BW=BERNSEN(IMAGE,[MN],CONTRAST_THRESHOLD,PADDING)performslocal

%thresholdingwithoddvaluedM-by-Nneighbourhood(defaultis3-by-3).

%ThedefaultvalueforCONTRAST_THRESHOLDis15.Todealwithborder

%pixelstheimageispaddedwithoneofPADARRAYoptions(defaultis

).

%imshow(bernsen(imread('

)));

%SeealsoPADARRAY,RGB2GRAY.

1.0$$Date:

2013/03/0916:

functionoutput=bernsen(image,varargin)

%Initialization

%onlywant3optionalinputsatmost

3

PossibleBERNSENparametersare:

(image,[mn],contrast,padding)'

optargs={[33]15'

%setdefaults

[window,contrast_threshold,padding]=optargs{:

ifndims(image)~=2

Theinputimagemustbeatwo-dimensionalarray.'

ifsum(mod(window,2))~=2

Sorry,onlyoddvaluedwindowdimensionsaresupported'

%Converttodouble

image=double(image);

%Meanvalue

mean=averagefilter(image,window,padding);

%Localcontrast

local_contrast=maxfilt2(image,window)-minfilt2(image,window);

%Initializetheoutput

output=zeros(size(image));

%Whenevercontrastinthewindowislowassumehomogenousarea

mask=local_contrast<

contrast_threshold;

output(mask&

image>

=128)=1;

%Otherwisecomparetothemeanvalue

output(~mask)=(image(~mask)>

=mean(~mask));

functionY=maxfilt2(X,varargin)

%MAXFILT2Two-dimensionalmaxfilter

%Y=MAXFILT2(X,[MN])performstwo-dimensionalmaximum

%filteringontheimageXusinganM-by-Nwindow.Theresult

%YcontainsthemaximunvalueintheM-by-Nneighborhoodaround

%eachpixelintheoriginalimage.

%ThisfunctionusesthevanHerkalgorithmformaxfilters.

%Y=MAXFILT2(X,M)isthesameasY=MAXFILT2(X,[MM])

%Y=MAXFILT2(X)usesa3-by-3neighborhood.

%Y=MAXFILT2(...,'

shape'

)returnsasubsectionofthe2D

%filteringspecifiedby'

:

full'

-Returnsthefullfilteringresult,

same'

-(default)Returnsthecentralfilterareathatisthe

%samesizeasX,

valid'

-Returnsonlytheareawherenofilterelementsareoutside

%theimage.

%Seealso:

MINFILT2,VANHERK

[S,shape]=parse_inputs(varargin{:

});

%filtering

Y=vanherk(X,S

(1),'

max'

shape);

Y=vanherk(Y,S

(2),'

'

col'

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function[S,shape]=parse_inputs(varargin)

shape='

;

flag=[00];

%sizeshape

fori=1:

nargin

t=varargin{i};

ifstrcmp(t,'

)&

flag

(2)==0

shape='

flag

(2)=1;

elseifstrcmp(t,'

elseifflag

(1)==0

S=t;

flag

(1)=1;

else

error(['

Toomany/Unkownparameter:

t])

ifflag

(1)==0

S=[33];

iflength(S)==1;

S

(2)=S

(1);

iflength(S)~=2

Wrongwindowsizeparameter.'

functionY=minfilt2(X,varargin)

%MINFILT2Two-dimensionalminfilter

%Y=MINFILT2(X,[MN])performstwo-dimensionalminimum

%YcontainstheminimunvalueintheM-by-Nneighborhoodaround

%ThisfunctionusesthevanHerkalgorithmforminfilters.

%Y=MINFILT2(X,M)isthesameasY=MINFILT2(X,[MM])

%Y=MINFILT2(X)usesa3-by-3neighborhood.

%Y=MINFILT2(...,'

MAXFILT2,VANHERK

min'

functionY=vanherk(X,N,TYPE,varargin)

%VANHERKFastmax/min1Dfilter

%Y=VANHERK(X,N,TYPE)performsthe1Dmax/minfilteringoftherow

%vectorXusingaN-lengthfilter.

%ThefilteringtypeisdefinedbyTYPE='

or'

.Thisfunction

%usesthevanHerkalgorithmformin/maxfiltersthatdemandsonly3

%min/maxcalculationsperelement,independentlyofthefiltersize.

%IfXisa2Dmatrix,eachrowwillbefilteredseparately.

%Y=VANHERK(...,'

)performsthefilteringonthecolumnsofX.

)returnsthesubsetofthefilteringspecified

%by'

%Xcanbeuint8ordouble.IfXisuint8theprocessingisquitefaster,so

%dont'

tuseXasdouble,unle

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 临床医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1