版權(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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- (完整版)加油站安全生產(chǎn)規(guī)章制度和崗位操作規(guī)程
- 電動(dòng)汽車充電站消防安全培訓(xùn)制度
- 車輛檔案管理制度范文
- 高校跳水空中姿態(tài)的旋轉(zhuǎn)動(dòng)力學(xué)分析課題報(bào)告教學(xué)研究課題報(bào)告
- 2026年歷史文化遺產(chǎn)保護(hù)與傳承試題庫
- 2026年P(guān)ython編程基礎(chǔ)與進(jìn)階練習(xí)題集
- 2026年化學(xué)實(shí)驗(yàn)技能考核題庫深入化學(xué)理論與實(shí)踐
- 2026年食品行業(yè)區(qū)塊鏈溯源技術(shù)趨勢分析報(bào)告
- 安全專項(xiàng)施工方案(天津津武)
- 2026四川省引大濟(jì)岷水資源開發(fā)有限公司第一批次招聘27人備考題庫及參考答案詳解一套
- 養(yǎng)生會(huì)所店長的日常職責(zé)
- 2025年北京市中考數(shù)學(xué)試卷深度評析及2026年備考策略
- 2025垃圾發(fā)電企業(yè)安全生產(chǎn)標(biāo)準(zhǔn)化實(shí)施規(guī)范
- 檢驗(yàn)檢測機(jī)構(gòu)資質(zhì)認(rèn)定評審員培訓(xùn)教程(2023版)
- 2024年線上卸妝品類消費(fèi)趨勢洞察
- 2025年四川省南充市中考生物真題(解析版)
- 海爾洗衣機(jī)MS75188BZ31使用說明書
- 2025年內(nèi)蒙古自治區(qū)中考數(shù)學(xué)試卷真題(含答案解析)
- 2024-2025學(xué)年廣東省廣州市花都區(qū)高一上學(xué)期二校聯(lián)合期末考試數(shù)學(xué)試題(解析版)
- 弱電項(xiàng)目人員管理制度
- GA 1812.3-2024銀行系統(tǒng)反恐怖防范要求第3部分:印鈔造幣企業(yè)
評論
0/150
提交評論