• 大小: 4.9MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-09-18
  • 语言: Matlab
  • 标签: matlab  智能算法  

资源简介

精通MATLAB智能算法(配套代码),包括所有章节的源代码

资源截图

代码片段和文件信息

%%%%%%%%%%%%%%%%遗传算法在道路图像阈值分割中的应用%%%%%%%%%%%%
function main()
clear all
close all
clc
global chrom oldpop fitness lchrom  popsize cross_rate mutation_rate thresholdsum
global maxgen  m n fit gen threshold A B C oldpop1 popsize1 b b1 fitness1 threshold1
A=imread(‘1.jpg‘);     %读入道路图像
A=imresize(A0.5);     %利用imresize函数通过默认的最近邻插值将图像放大0.5倍
B=rgb2gray(A);         %灰度化
C=imresize(B0.2);     %将读入的图像缩小到0.2倍
lchrom=10;              %染色体长度
popsize=10;            %种群大小
cross_rate=0.8;        %交叉概率
mutation_rate=0.5;     %变异概率
maxgen=100;            %最大代数
[mn]=size(C);
initpop;    %初始种群
for gen=1:maxgen
    generation;  %遗传操作
end
findthreshold_best; %图象分割结果
%%%%%%%%%%%%%%%%%%%输出进化各曲线%%%%%%%%%%%
figure;
gen=1:maxgen;
plot(genfit(1gen)); 
title(‘最佳适应度值进化曲线‘);
xlabel(‘代数‘)
ylabel(‘最佳适应度值‘)
figure;
plot(genthreshold(1gen));
title(‘每一代的最佳阈值变化曲线‘);
xlabel(‘代数‘)
ylabel(‘每一代的最佳阈值‘)
%%%%%%%%%%%%%%%%%%%初始化种群%%%%%%%%%%%%%%%%%%%%
function initpop()
global lchrom oldpop popsize chrom C
imshow(C);
for i=1:popsize
    chrom=rand(1lchrom);
    for j=1:lchrom
        if chrom(1j)<0.5
            chrom(1j)=0;
       else 
           chrom(1j)=1;
        end
    end
    oldpop(i1:lchrom)=chrom;    %给每一个个体分配8位的染色体编码
end

%%%%%%%%%%%%%%%%%产生新一代个体%%%%%%%%%%%%%%%%%%%%%%
function generation()
fitness_order;                  %计算适应度值及排序
select;                         %选择操作
crossover;                      %交叉
mutation;                       %变异
%%%%%%%%%%%%%%%%%计算适度值并且排序%%%%%%%%%%%%%%%%%%%
function fitness_order()
global lchrom oldpop fitness popsize chrom fit gen C m n  fitness1 thresholdsum
global lowsum higsum u1 u2 threshold gen oldpop1 popsize1 b1 b threshold1 
if popsize>=5
    popsize=ceil(popsize-0.03*gen);
end
if gen==75     %当进化到末期的时候调整种群规模和交叉、变异概率
    cross_rate=0.3;        %交叉概率
    mutation_rate=0.3;     %变异概率
end
%如果不是第一代则将上一代操作后的种群根据此代的种群规模装入此代种群中
if gen>1   
    t=oldpop;
    j=popsize1;
    for i=1:popsize
        if j>=1
            oldpop(i:)=t(j:);
        end
        j=j-1;
    end
end
%计算适度值并排序
for i=1:popsize
    lowsum=0;
    higsum=0;
    lownum=0;
    hignum=0;
    chrom=oldpop(i:);
    c=0;
    for j=1:lchrom
        c=c+chrom(1j)*(2^(lchrom-j));
    end
    b(1i)=c*255/(2^lchrom-1);  %转化到灰度值        
    for x=1:m
        for y=1:n
            if C(xy)<=b(1i)
                lowsum=lowsum+double(C(xy));%统计低于阈值的灰度值的总和
                lownum=lownum+1; %统计低于阈值的灰度值的像素的总个数
            else
                higsum=higsum+double(C(xy));%统计高于阈值的灰度值的总和
                hignum=hignum+1; %统计高于阈值的灰度值的像素的总个数
            end
        end
    end
    if lownum~=0
        u1=lowsum/lownum; %u1、u2为对应于两类的平均灰度值
    else
        u1=0;
    end
    if hignum~=0
        u2=higsum/hignum;
    else
        u2=0;
    end   
    fitness(1i)=lownum*hignum*(u1-u2)^2; %计算适度值
end
if gen==1 %如果为第一代,从小往大排序
    for i=1:popsize
        j=i+1;
        while

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      53547  2014-04-26 08:36  Intelligent algorithm\10\s10_1\1.jpg

     文件       8775  2014-04-26 09:03  Intelligent algorithm\10\s10_1\s10_1.m

     文件      53547  2014-04-26 08:36  Intelligent algorithm\10\s10_2\1.jpg

     文件       1634  2014-04-26 11:08  Intelligent algorithm\10\s10_2\bys.m

     文件     575694  2014-04-26 10:11  Intelligent algorithm\10\s10_3\1.bmp

     文件      33120  2014-04-26 10:37  Intelligent algorithm\10\s10_3\a.BMP

     文件        309  2014-04-26 10:39  Intelligent algorithm\10\s10_3\gabptrain.m

     文件        985  2014-04-26 10:41  Intelligent algorithm\10\s10_3\gadecod.m

     文件        186  2014-04-26 10:03  Intelligent algorithm\10\s10_3\gafitness.m

     文件        191  2014-04-26 10:39  Intelligent algorithm\10\s10_3\generatesample.m

     文件        615  2014-04-26 10:03  Intelligent algorithm\10\s10_3\getWBbyga.m

     文件        445  2014-04-26 10:45  Intelligent algorithm\10\s10_3\initnet.m

     文件        778  2014-04-26 10:54  Intelligent algorithm\10\s10_3\main.m

     文件       2424  2014-04-26 10:06  Intelligent algorithm\10\s10_3\net.mat

     文件       2424  2014-04-26 10:06  Intelligent algorithm\10\s10_3\net1.mat

     文件        270  2014-04-26 10:46  Intelligent algorithm\10\s10_3\nninit.m

     文件        496  2014-04-26 10:49  Intelligent algorithm\10\s10_3\sample.mat

     文件        306  2014-04-26 10:41  Intelligent algorithm\10\s10_3\segment.m

     文件        712  2014-04-25 19:35  Intelligent algorithm\10\s10_4\cross_2d.m

     文件        816  2014-04-26 14:10  Intelligent algorithm\10\s10_4\cross_2d_improve.m

     文件        474  2014-04-26 13:00  Intelligent algorithm\10\s10_4\cross_ga.m

     文件        579  2014-04-26 12:55  Intelligent algorithm\10\s10_4\cross_ga_improve.m

     文件     343854  2014-04-26 14:22  Intelligent algorithm\10\s10_4\Hepburn.bmp

     文件        614  2014-04-25 19:35  Intelligent algorithm\10\s10_4\ksw.m

     文件        761  2014-04-25 19:35  Intelligent algorithm\10\s10_4\ksw_2d.m

     文件       2560  2014-04-26 15:21  Intelligent algorithm\10\s10_4\ksw_2d_ga.m

     文件       2563  2014-04-26 15:21  Intelligent algorithm\10\s10_4\ksw_2d_ga_improve.m

     文件       1772  2014-04-26 15:21  Intelligent algorithm\10\s10_4\ksw_ga.m

     文件       1820  2014-04-26 15:21  Intelligent algorithm\10\s10_4\ksw_ga_improve.m

     文件      66614  2014-04-25 19:35  Intelligent algorithm\10\s10_4\Lenna.bmp

............此处省略265个文件信息

评论

共有 条评论