基于原子势函数及人工蜂群算法进行形状匹配优化(Matlab代码实现)

欢迎来到本博客❤️❤️❤️

博主优势:博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

目录

1 概述

2 运行结果

3 参考文献

‍4 Matlab代码实现 

1 概述

       当观察周围环境时,人们首先注意到的是物体及其周围环境的颜色、纹理、形状和空间关系等等,形状是物体最基本的有感觉意义的特征之一.在计算机视觉和模式识别中,形状是对目标范围的二值图像表示,可以看成是目标的轮廓,它是用于目标识别的重要特征.为了节省存储空间、易于特征计算﹐需要对形状作进一步的表示,这些表示通常可以分为两类:编码方式.如链码﹑游程码, freeman码等;简化方式,如样条(B样条,3次·5次样条八插值、多项式、多边形逼近、和特征点检测等.另外还可以使用形状的骨架来描述形状。

2 运行结果

基于原子势函数及人工蜂群算法进行形状匹配优化(Matlab代码实现)_第1张图片

基于原子势函数及人工蜂群算法进行形状匹配优化(Matlab代码实现)_第2张图片

基于原子势函数及人工蜂群算法进行形状匹配优化(Matlab代码实现)_第3张图片

部分代码:

clear all
close all
clc

global exp001
exp002 = imread('1.bmp');
exp001 = rgb2gray(exp002);
exp001 = edge(exp001,'sobel');

global flag
global yanmo

load 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         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     if(rand         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             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 BE

end
asddsa


asddsa

3 参考文献

[1]Bai Li and Yuan Yao, "An Edge-based Optimization Method for Shape Recognition Using Atomic Potential Function", Engineering Applications of Artificial Intelligence, no. 35, pp. 14–25, 2014.
[2]Bai Li, Raymond Chiong and Mu Lin, "A Balance-Evolution Artificial Bee Colony Algorithm for Protein Structure Optimization Based on a Three-dimensional AB Off-Lattice Model", Computational Biology and Chemistry, no. 54, pp. 1–12, 2015.

‍4 Matlab代码实现 

你可能感兴趣的:(#,算法,matlab,开发语言)