天天看點

基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)

💥💥💥💞💞💞歡迎來到本部落格❤️❤️❤️💥💥💥

🏆部落客優勢:🌞🌞🌞部落格内容盡量做到思維缜密,邏輯清晰,為了友善讀者。

⛳️座右銘:行百裡者,半于九十。

目錄

​​💥1 概述​​

​​📚2 運作結果​​

​​🎉3 參考文獻​​

​​👨‍💻4 Matlab代碼實作 ​​

💥1 概述

       當觀察周圍環境時,人們首先注意到的是物體及其周圍環境的顔色、紋理、形狀和空間關系等等,形狀是物體最基本的有感覺意義的特征之一.在計算機視覺和模式識别中,形狀是對目标範圍的二值圖像表示,可以看成是目标的輪廓,它是用于目辨別别的重要特征.為了節省存儲空間、易于特征計算﹐需要對形狀作進一步的表示,這些表示通常可以分為兩類:編碼方式.如鍊碼﹑遊程碼, freeman碼等;簡化方式,如樣條(B樣條,3次·5次樣條八插值、多項式、多邊形逼近、和特征點檢測等.另外還可以使用形狀的骨架來描述形狀。

📚2 運作結果

基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)
基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)
基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)
基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)
基于原子勢函數及人工蜂群算法進行形狀比對優化(Matlab代碼實作)
clear all
 close all
 clcglobal exp001
 exp002 = imread('1.bmp');
 exp001 = rgb2gray(exp002);
 exp001 = edge(exp001,'sobel');global flag
 global yanmoload zxx
[mmmm, ~] = size(yanmo);
 flag = (mmmm./2);D = 3;
 NP = 40; %/* The number of colony size (employed bees+onlooker bees)*/
 FoodNumber = NP/2; %/*The number of food sources equals the half of the colony size*/
 maxCycle = 50; %/*The number of cycles for foraging {a stopping criteria}*/
 runtime = 3;%/*Algorithm can be run many times in order to see its robustness*/
 limit = D*NP./2; %/*A food source which could not be improved through "limit" trials is abandoned by its employed bee*/ 
 [zxx1,zxx2] = size(exp001);
 lb = [flag+1 ,flag+1, 0]; %/*lower bounds of the parameters. */
 ub = [zxx1-(flag + 1),zxx2- (flag + 1),2*pi];%/*upper bound of the parameters.*/GlobalMins=zeros(1,runtime);
 Range = repmat((ub-lb),[FoodNumber 1]);
 Lower = repmat(lb, [FoodNumber 1]); for r=1:runtime
     tic
     Foods = rand(FoodNumber,D) .* Range + Lower;
     for i = 1:FoodNumber
         ObjVal(i) = libai1989(Foods(i,1),Foods(i,2),Foods(i,3));
     end
 Fitness = calculateFitness(ObjVal);
 trial=zeros(1,FoodNumber);
 BestInd=find(ObjVal==max(ObjVal));
 BestInd=BestInd(end);
 GlobalMin = ObjVal(BestInd);
 GlobalParams=Foods(BestInd,:);
 ap = Fitness(1);iter=1;
 while ((iter <= maxCycle)),
     for i=1:(FoodNumber)
     neighbour1 = fix(rand*(FoodNumber)) + 1;
     neighbour2 = fix(rand*(FoodNumber)) + 1;
     while(neighbour2 == i)
          neighbour2 = fix(rand*(FoodNumber)) + 1;
     end;
     vv = (trial(i)+1)./((trial(i) + trial(neighbour2))+2);
        sol=Foods(i,:);
        Param2Change=fix(rand*D)+1;
        sol(Param2Change) = Foods(i,Param2Change) + (Foods(neighbour1,Param2Change)-Foods(neighbour2,Param2Change))*(rand-0.5)*2*vv;
         %
         ind = find(sol<lb);
         sol(ind) = lb(ind);
         ind = find(sol>ub);
         sol(ind) = ub(ind);
         %
         ObjValSol = libai1989(sol(1),sol(2),sol(3));
         FitnessSol=calculateFitness(ObjValSol);
        if (FitnessSol>Fitness(i)) 
             Foods(i,:)=sol;
             Fitness(i)=FitnessSol;
             ObjVal(i)=ObjValSol;
             trial(i)=0;
         else
             trial(i)=trial(i)+1;
        end;
      end;
 prob=(0.9.*Fitness./max(Fitness))+0.1;
 i=1;
 t=0;
 while(t<FoodNumber)
     if(rand<prob(i))
         t=t+1;
         Param2Change=fix(rand*D)+1;
         neighbour=fix(rand*(FoodNumber))+1;     
             while(neighbour==i)
                 neighbour=fix(rand*(FoodNumber))+1;
             end;
         
        sol=Foods(i,:);
        vv = (trial(i) + 1) ./ ((trial(i) + trial(neighbour)) + 2);
        sol(Param2Change) = Foods(i,Param2Change) + (Foods(i,Param2Change)-Foods(neighbour,Param2Change))*(rand-0.5)*2*vv;       
         %
         ind = find(sol < lb);
         sol(ind) = lb(ind);
         ind = find(sol > ub);
         sol(ind) = ub(ind);
         %
         ObjValSol = libai1989(sol(1),sol(2),sol(3));
         FitnessSol=calculateFitness(ObjValSol);
        if (FitnessSol<Fitness(i)) 
             Foods(i,:)=sol;
             Fitness(i)=FitnessSol;
             ObjVal(i)=ObjValSol;
             trial(i)=0;
         else
             trial(i)=trial(i)+1; %/*if the solution i can not be improved, increase its trial counter*/
        end;
     end;
     
     i=i+1;
     if (i==(FoodNumber)+1) 
         i=1;
     end;   
 end; 
          ind=find(ObjVal==max(ObjVal));
          ind=ind(end);
          if (ObjVal(ind)>GlobalMin)
          GlobalMin=ObjVal(ind);
          GlobalParams=Foods(ind,:);
          end;
 ind=find(trial==max(trial));
 ind=ind(end);
 if (trial(ind)>limit)
     trial(ind)=0;
     sol=(ub-lb).*rand(1,D)+lb;
     ObjValSol = libai1989(sol(1),sol(2),sol(3));
     FitnessSol=calculateFitness(ObjValSol);
     Foods(ind,:)=sol;
     Fitness(ind)=FitnessSol;
     ObjVal(ind)=ObjValSol;
 end;fprintf('iteration = %d ObjVal=%g\n',iter, GlobalMin);
 AAA(r,iter) = GlobalMin;iter  = iter +1;
 end % End of ABC
 solution_restore(r,1:3) = GlobalParams;
 save BEend
 asddsa asddsa      

🎉3 參考文獻

👨‍💻4 Matlab代碼實作 

繼續閱讀