基于基于遺傳算法的醫(yī)學(xué)圖像研究程序清單(終稿)_第1頁
基于基于遺傳算法的醫(yī)學(xué)圖像研究程序清單(終稿)_第2頁
基于基于遺傳算法的醫(yī)學(xué)圖像研究程序清單(終稿)_第3頁
基于基于遺傳算法的醫(yī)學(xué)圖像研究程序清單(終稿)_第4頁
基于基于遺傳算法的醫(yī)學(xué)圖像研究程序清單(終稿)_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

淮陰工學(xué)院大學(xué)生科技實(shí)踐計(jì)劃項(xiàng)目第1頁共36頁附錄附錄一灰度直方圖雙峰法分割源代碼clear,closeallB=imread('2.jpg');

%讀入原始jpg格式圖像figure(1);imshow(B),title('原始jpg格式圖像');I1=rgb2gray(B);

%將原圖像轉(zhuǎn)化為灰度圖象figure(2);imshow(I1),title('灰度格式圖像');[I1,map1]=gray2ind(I1,255);

%將灰度圖像轉(zhuǎn)化為索引圖像figure(3),imhist(I1)

%畫出灰度直方圖,以判斷域值

I1=double(I1);

%將unit8數(shù)組轉(zhuǎn)化為double型數(shù)組

Z=I1

%將double型數(shù)組I1轉(zhuǎn)存到Z中[m,n]=size(Z);fori=1:m

forj=1:n

ifZ(i,j)>240

%灰度值大于域值時(shí)是白色

Z(i,j)=256;

end

endendfigure(4)

%畫出分割后目標(biāo)圖像image(Z),title('分割后圖像');colormap(map1);圖像I圖像格式轉(zhuǎn)化及灰度直方圖雙峰法分割源代碼clear,closeallB=imread('she.jpg');

%讀入原始jpg格式圖像shefigure(1);imshow(B),title('原始jpg格式圖像');I1=rgb2gray(B);

%將原圖像轉(zhuǎn)化為灰度圖象figure(2);imshow(I1),title('灰度格式圖像');[I1,map1]=gray2ind(I1,255);

%將灰度圖像轉(zhuǎn)化為索引圖像figure(3),imhist(I1)

%畫出灰度直方圖,以判斷域值

I1=double(I1);

%將unit8數(shù)組轉(zhuǎn)化為double型數(shù)組

Z=I1

%將double型數(shù)組I1轉(zhuǎn)存到Z中[m,n]=size(Z);fori=1:m

forj=1:n

ifZ(i,j)>240

%灰度值大于域值時(shí)是白色

Z(i,j)=256;

end

endendfigure(4)

%畫出分割后目標(biāo)圖像image(Z),title('分割后圖像');colormap(map1);圖像II圖像格式轉(zhuǎn)化及灰度直方圖雙峰法分割源代碼clear,closeallB=imread('she.jpg');

%讀入原始jpg格式圖像月亮figure(1);imshow(B),title('原始jpg格式圖像');I1=rgb2gray(B);

%將原圖像轉(zhuǎn)化為灰度圖象figure(2);imshow(I1),title('灰度格式圖像');[I1,map1]=gray2ind(I1,255);

%將灰度圖像轉(zhuǎn)化為索引圖像figure(3),imhist(I1)

%畫出灰度直方圖,以判斷域值

I1=double(I1);

%將unit8數(shù)組轉(zhuǎn)化為double型數(shù)組

Z=I1

%將double型數(shù)組I1轉(zhuǎn)存到Z中[m,n]=size(Z);fori=1:m

forj=1:n

ifZ(i,j)>240

%灰度值大于域值時(shí)是白色

Z(i,j)=256;

end

endendfigure(4)

%畫出分割后目標(biāo)圖像image(Z),title('分割后圖像');colormap(map1);附錄二Crtbp函數(shù)源代碼:(由謝菲爾德大學(xué)AndrewChipperfield編寫)%CRTBP.m-Createaninitialpopulation%%Thisfunctioncreatesabinarypopulationofgivensizeandstructure.%%Syntax:[ChromLindBaseV]=crtbp(Nind,Lind,Base)%%InputParameters:%%

Nind

-Eitherascalarcontainingthenumberofindividuals%

inthenewpopulationorarowvectoroflengthtwo%

containingthenumberofindividualsandtheirlength.%%

Lind

-Ascalarcontainingthelengthoftheindividual%

chromosomes.%%

Base

-Ascalarcontainingthebaseofthechromosome%

elementsorarowvectorcontainingthebase(s)%

ofthelociofthechromosomes.%%OutputParameter[來源:論文s:%%

Chrom

-Amatrixcontainingtherandomvaluedchromosomes%

rowwise.%%

Lind-

Ascalarcontainingthelengthofthechromosome.%%

BaseV

-Arowvectorcontainingthebaseofthe%

chromosomeloci.%Author:AndrewChipperfield%Date:

19-Jan-94function[Chrom,Lind,BaseV]=crtbp(Nind,Lind,Base)nargs=nargin;%Checkparameterconsistencyifnargs>=1,[mN,nN]=size(Nind);endifnargs>=2,[mL,nL]=size(Lind);endifnargs==3,[mB,nB]=size(Base);endifnN==2

if(nargs==1)

Lind=Nind(2);Nind=Nind(1);BaseV=crtbase(Lind);

elseif(nargs==2&nL==1)

BaseV=crtbase(Nind(2),Lind);Lind=Nind(2);Nind=Nind(1);

elseif(nargs==2&nL>1)

ifLind~=length(Lind),error('LindandBasedisagree');end

BaseV=Lind;Lind=Nind(2);Nind=Nind(1);

endelseifnN==1

ifnargs==2

ifnL==1,BaseV=crtbase(Lind);

else,BaseV=Lind;Lind=nL;end

elseifnargs==3

ifnB==1,BaseV=crtbase(Lind,Base);

elseifnB~=Lind,error('LindandBasedisagree');

elseBaseV=Base;end

endelse

error('Inputparametersinconsistent');end%Createastructureofrandomchromosomesinrowwiseorder,dimensions%NindbyLind.Thebaseofeachchromosomeslociisgivenbythevalue%ofthecorrespondingelementoftherowvectorbase.Chrom=floor(rand(Nind,Lind).*BaseV(ones(Nind,1),:));%Endoffile附錄三Bs2rv函數(shù)源代碼:

(由謝菲爾德大學(xué)AndrewChipperfield編寫)%BS2RV.m-Binarystringtorealvector%%Thisfunctiondecodesbinarychromosomesintovectorsofreals.The%chromosomesareseenastheconcatenationofbinarystringsofgiven%length,anddecodedintorealnumbersinaspecifiedintervalusing%eitherstandardbinaryorGraydecoding.%%Syntax:

Phen=bs2rv(Chrom,FieldD)%%Inputparameters:%%

Chrom

-Matrixcontainingthechromosomesofthecurrent%

population.Eachlinecorrespondstoone%

individual'sconcatenatedbinarystring%

representation.LeftmostbitsareMSband%

rightmostareLSb.%%

FieldD

-Matrixdescribingthelengthandhowtodecode%

eachsubstringinthechromosome.Ithasthe%

followingstructure:%%

[len;

(num)%

lb;

(num)%

ub;

(num)%

code;

(0=binary

|1=gray)%

scale;

(0=arithmetic|1=logarithmic)%

lbin;

(0=excluded

|1=included)%

ubin];

(0=excluded

|1=included)%%

where%

len

-rowvectorcontainingthelengthof%

eachsubstringinChrom.sum(len)%

shouldequaltheindividuallength.%

lb,%

ub

-Lowerandupperboundsforeach%

variable.%

code

-binaryrowvectorindicatinghoweach%

substringistobedecoded.%

scale-binaryrowvectorindicatingwhereto%

usearithmeticand/orlogarithmic%

scaling.%

lbin,%

ubin

-binaryrowvectorsindicatingwhether%

ornottoincludeeachboundinthe%

representationrange%%Outputparameter:%%

Phen

-Realmatrixcontainingthepopulationphenotypes.%%Author:CarlosFonseca,

Updated:AndrewChipperfield%Date:08/06/93,

Date:26-Jan-94functionPhen=bs2rv(Chrom,FieldD)%Identifythepopulationsize(Nind)%

andthechromosomelength(Lind)[Nind,Lind]=size(Chrom);%Identifythenumberofdecisionvariables(Nvar)[seven,Nvar]=size(FieldD);ifseven~=7

error('FieldDmusthave7rows.');end%Getsubstringpropertieslen=FieldD(1,:);lb=FieldD(2,:);ub=FieldD(3,:);code=~(~FieldD(4,:));scale=~(~FieldD(5,:));lin=~(~FieldD(6,:));uin=~(~FieldD(7,:));%Checksubstringpropertiesforconsistencyifsum(len)~=Lind,

error('DatainFieldDmustagreewithchromosomelength');endif~all(lb(scale).*ub(scale)>0)

error('Log-scaledvariablesmustnotinclude0intheirrange');end%DecodechromosomesPhen=zeros(Nind,Nvar);lf=cumsum(len);li=cumsum([1len]);Prec=.5.^len;logsgn=sign(lb[來源:論文(scale));lb(scale)=log(abs(lb(scale)));ub(scale)=log(abs(ub(scale)));delta=ub-lb;Prec=.5.^len;num=(~lin).*Prec;den=(lin+uin-1).*Prec;fori=1:Nvar,

idx=li(i):lf(i);

ifcode(i)%Graydecoding

Chrom(:,idx)=rem(cumsum(Chrom(:,idx)')',2);

end

Phen(:,i)=Chrom(:,idx)*[(.5).^(1:len(i))'];

Phen(:,i)=lb(i)+delta(i)*(Phen(:,i)+num(i))./(1-den(i));endexpand=ones(Nind,1);ifany(scale)

Phen(:,scale)=logsgn(expand,:).*exp(Phen(:,scale));end附錄四適應(yīng)度函數(shù)target源代碼:functionf=target(T,M)

%適應(yīng)度函數(shù),T為待處理圖像,M為域值序列[U,V]=size(T);W=,,length(M);f=zeros(W,1);fork=1:W

I=0;s1=0;J=0;s2=0;

%統(tǒng)計(jì)目標(biāo)圖像和背景圖像的像素?cái)?shù)及像素之和

fori=1:U

forj=1:V

ifT(i,j)<=M(k)

s1=s1+T(i,j);I=I+1;

end

ifT(i,j)>M(k)

s2=s2+T(i,j);J=J+1;

end

end

end

ifI==0,

p1=0;

elsep1=s1/I;end

ifJ==0,

p2=0;

elsep2=s2/J;end

f(k)=I*J*(p1-p2)*(p1-p2)/(256*256);end附錄五選擇函數(shù)Select源代碼:(由謝菲爾德大學(xué)HartmutPohlheim編寫)%SELECT.M

(universalSELECTion)%%Thisfunctionperformsuniversalselection.Thefunctionhandles%multiplepopulationsandcallsthelowlevelselectionfunction%fortheactualselectionprocess.%%Syntax:

SelCh=select(SEL_F,Chrom,FitnV,GGAP,SUBPOP)%%Inputparameters:%

SEL_F

-Nameoftheselectionfunction%

Chrom

-Matrixcontainingtheindividuals(parents)ofthecurrent%

population.Eachrowcorrespondstooneindividual.%

FitnV

-Columnvectorcontainingthefitnessvaluesofthe%

individualsinthepopulation.%

GGAP

-(optional)Rateofindividualstobeselected%

ifomitted1.0isassumed%

SUBPOP

-(optional)Numberofsubpopulations%

ifomitted1subpopulationisassumed%%Outputparameters:%

SelCh

-Matrixcontainingtheselectedindividuals.%Author:

HartmutPohlheim%History:

10.03.94

filecreatedfunctionSelCh=select(SEL_F,Chrom,FitnV,GGAP,SUBPOP);%Checkparameterconsistency

ifnargin<3,error('Notenoughinputparameter');end

%Identifythepopulationsize(Nind)

[NindCh,Nvar]=size(Chrom);

[NindF,VarF]=size(FitnV);

ifNindCh~=NindF,error('ChromandFitnVdisagree');end

ifVarF~=1,error('FitnVmustbeacolumnvector');end

ifnargin<5,SUBPOP=1;end

ifnargin>4,

ifisempty(SUBPOP),SUBPOP=1;

elseifisnan(SUBPOP),SUBPOP=1;

elseiflength(SUBPOP)~=1,error('SUBPOPmustbeascalar');end

end

if(NindCh/SUBPOP)~=fix(NindCh/SUBPOP),error('ChromandSUBPOPdisagree');end

Nind=NindCh/SUBPOP;

%Computenumberofindividualspersubpopulation

ifnargin<4,GGAP=1;end

ifnargin>3,

ifisempty(GGAP),GGAP=1;

elseifisnan(GGAP),GGAP=1;

elseiflength(GGAP)~=1,error('GGAPmustbeascalar');

elseif(GGAP<0),error('GGAPmustbeascalarbiggerthan0');end

end%Computenumberofnewindividuals(toselect)

NSel=max(floor(Nind*GGAP+.5),2);%Selectindividualsfrompopulation

SelCh=[];

forirun=1:SUBPOP,

FitnVSub=FitnV((irun-1)*Nind+1:irun*Nind);

ChrIx=feval(SEL_F,FitnVSub,NSel)+(irun-1)*Nind;

SelCh=[SelCh;Chrom(ChrIx,:)];

end

%Endoffunction附錄六交叉函數(shù)recombin的源代碼:(由謝菲爾德大學(xué)HartmutPohlheim編寫)%RECOMBIN.M

(RECOMBINationhigh-levelfunction)%%Thisfunctionperformsrecombinationbetweenpairsofindividuals%andreturnsthenewindividualsaftermating.Thefunctionhandles%multiplepopulationsandcallsthelow-levelrecombinationfunction%fortheactualrecombinationprocess.%%Syntax:

NewChrom=recombin(REC_F,OldChrom,RecOpt,SUBPOP)%%Inputparameters:%

REC_F

-Stringcontainingthenameoftherecombinationor%

crossoverfunction%

Chrom

-Matrixcontainingthechromosomesoftheold%

population.Eachlinecorrespondstooneindividual%

RecOpt

-(optional)Scalarcontainingtheprobabilityof%

recombination/crossoveroccurringbetweenpairs%

ofindividuals.%

ifomittedorNaN,1isassumed%

SUBPOP

-(optional)Numberofsubpopulations%

ifomittedorNaN,1subpopulationisassumed%%Outputparameter:%

NewChrom

-Matrixcontainingthechromosomesofthepopulation%

afterrecombinationinthesameformatasOldChrom.%

Author:

HartmutPohlheim%

History:

18.03.94

filecreatedfunctionNewChrom=recombin(REC_F,Chrom,RecOpt,SUBPOP);%Checkparameterconsistency

ifnargin<2,error('Notenoughinputparameter');end

%Identifythepopulationsize(Nind)

[Nind,Nvar]=size(Chrom);

ifnargin<4,SUBPOP=1;end

ifnargin>3,

ifisempty(SUBPOP),SUBPOP=1;

elseifisnan(SUBPOP),SUBPOP=1;

elseiflength(SUBPOP)~=1,error('SUBPOPmustbeascalar');end

end

if(Nind/SUBPOP)~=fix(Nind/SUBPOP),error('ChromandSUBPOPdisagree');end

Nind=Nind/SUBPOP;

%Computenumberofindividualspersubpopulation

ifnargin<3,RecOpt=0.7;end

ifnargin>2,

ifisempty(RecOpt),RecOpt=0.7;

elseifisnan(RecOpt),RecOpt=0.7;

elseiflength(RecOpt)~=1,error('RecOptmustbeascalar');

elseif(RecOpt<0|RecOpt>1),error('RecOptmustbeascalarin[0,1]');end

end%Selectindividualsofonesubpopulationandcalllowlevelfunction

NewChrom=[];

forirun=1:SUBPOP,

ChromSub=Chrom((irun-1)*Nind+1:irun*Nind,:);

NewChromSub=feval(REC_F,ChromSub,RecOpt);

NewChrom=[NewChrom;NewChromSub];

end%Endoffunction附錄七變異函數(shù)mut源代碼:(由謝菲爾德大學(xué)AndrewChipperfield編寫)%MUT.m%%Thisfunctiontakestherepresentationofthecurrentpopulation,%mutateseachelementwithgivenprobabilityandreturnstheresulting%population.%%Syntax:

NewChrom=mut(OldChrom,Pm,BaseV)%%Inputparameters:%%

OldChrom-Amatrixcontainingthechromosomesofthe%

currentpopulation.Eachrowcorrespondsto%

anindividualsstringrepresentation.%%

Pm

-Mutationprobability(scalar).Defaultvalue%

ofPm=0.7/Lind,whereLindisthechromosome%

lengthisassumedifomitted.%%

BaseV

-Optionalrowvectorofthesamelengthasthe%

chromosomestructuredefiningthebaseofthe%

individualelementsofthechromosome.Binary%

representationisassumedifomitted.%%Outputparameter:%%

NewChrom-AMatrixcontainingamutatedversionof%

OldChrom.%%Author:AndrewChipperfield%Date:25-Jan-94functionNewChrom=mut(OldChrom,Pm,BaseV)%getpopulationsize(Nind)andchromosomelength(Lind)[Nind,Lind]=size(OldChrom);%checkinputparametersifnargin<2,Pm=0.7/Lind;endifisnan(Pm),Pm=0.7/Lind;endif(nargin<3),BaseV=crtbase(Lind);

endif(isnan(BaseV)),BaseV=crtbase(Lind);

endif(isempty(BaseV)),BaseV=crtbase(Lind);

endif(nargin==3)&(Lind~=length(BaseV))

error('OldChromandBaseVareincompatible'),end%createmutationmaskmatrixBaseM=BaseV(ones(Nind,1),:);%performmutationonchromosomestructureNewChrom=rem(OldChrom+(rand(Nind,Lind)<Pm).*ceil(rand(Nind,Lind).*(BaseM-1)),BaseM);附錄八基于遺傳算法的最大類間方差法對JPG格式圖像分割的程序源代碼:clear,closeallB=imread('she.jpg');

%讀入原始jpg格式圖像figure(1);imshow(B),title('原始jpg格式圖像');I1=rgb2gray(B);

%將原圖像轉(zhuǎn)化為灰度圖象figure(2);imshow(I1),title('灰度格式圖像');BW1=edge(I1,'sobel');BW2=edge(I1,'canny');figure(6),imshow(BW1),title('邊緣檢測1');

%邊緣檢測figure(5),imshow(BW2),title('邊緣檢測2');[I1,map1]=gray2ind(I1,255);

%將灰度圖像轉(zhuǎn)化為索引圖像I1=double(I1);

%將unit8數(shù)組轉(zhuǎn)化為double型數(shù)組

Z=I1

%將double型數(shù)組I1轉(zhuǎn)存到Z中figure(3)

%畫出未進(jìn)行分割的原始圖像image(Z),title('未進(jìn)行分割的原始圖像');colormap(map1);

NIND=40;

%個(gè)體數(shù)目(Numberofindividuals)MAXGEN=50;

%最大遺傳代數(shù)(Maximumnumberofgenerations)PRECI=8;

%變量的二進(jìn)制位數(shù)(Precisionofvariables)GGAP=0.9;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論