计算机应用 | 古代文学 | 市场营销 | 生命科学 | 交通物流 | 财务管理 | 历史学 | 毕业 | 哲学 | 政治 | 财税 | 经济 | 金融 | 审计 | 法学 | 护理学 | 国际经济与贸易
计算机软件 | 新闻传播 | 电子商务 | 土木工程 | 临床医学 | 旅游管理 | 建筑学 | 文学 | 化学 | 数学 | 物理 | 地理 | 理工 | 生命 | 文化 | 企业管理 | 电子信息工程
计算机网络 | 语言文学 | 信息安全 | 工程力学 | 工商管理 | 经济管理 | 计算机 | 机电 | 材料 | 医学 | 药学 | 会计 | 硕士 | 法律 | MBA
现当代文学 | 英美文学 | 通讯工程 | 网络工程 | 行政管理 | 公共管理 | 自动化 | 艺术 | 音乐 | 舞蹈 | 美术 | 本科 | 教育 | 英语 |

基于模糊理论的图像分割算法研究(12)

2013-07-28 01:28
导读:% RecOpt - (optional) Scalar containing the probability of % recombination/crossover occurring between pairs % of individuals. % if omitted or NaN, 1 is assumed % SUBPOP - (optional) Number of subpopu

%    RecOpt    - (optional) Scalar containing the probability of

%                recombination/crossover occurring between pairs

%                of individuals.

%                if omitted or NaN, 1 is assumed

%    SUBPOP    - (optional) Number of subpopulations

%                if omitted or NaN, 1 subpopulation is assumed

%

% Output parameter:

%    NewChrom  - Matrix containing the chromosomes of the population

%                after recombination in the same format as OldChrom.

%  Author:    Hartmut Pohlheim

%  History:   18.03.94     file created

function NewChrom = recombin(REC_F, Chrom, RecOpt, SUBPOP);

% Check parameter consistency

   if nargin < 2, error('Not enough input parameter'); end

   % Identify the population size (Nind)

   [Nind,Nvar] = size(Chrom);

 

   if nargin < 4, SUBPOP = 1; end

   if nargin > 3,

      if isempty(SUBPOP), SUBPOP = 1;

      elseif isnan(SUBPOP), SUBPOP = 1;

      elseif length(SUBPOP) ~= 1, error('SUBPOP must be a scalar'); end

   end

   if (Nind/SUBPOP) ~= fix(Nind/SUBPOP), error('Chrom and SUBPOP disagree'); end

   Nind = Nind/SUBPOP;  % Compute number of individuals per subpopulation

   if nargin < 3, RecOpt = 0.7; end

   if nargin > 2,

      if isempty(RecOpt), RecOpt = 0.7;

      elseif isnan(RecOpt), RecOpt = 0.7;

      elseif length(RecOpt) ~= 1, error('RecOpt must be a scalar');

      elseif (RecOpt < 0 | RecOpt > 1), error('RecOpt must be a scalar in [0, 1]'); end

   end

% Select individuals of one subpopulation and call low level function

   NewChrom = [];

   for irun = 1:SUBPOP,

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

      NewChromSub = feval(REC_F, ChromSub, RecOpt);

      NewChrom=[NewChrom; NewChromSub];

   end

% End of function

附录 七

变异函数mut源代码 :(由谢菲尔德大学Andrew Chipperfield编写)

% MUT.m

%

% This function takes the representation of the current population,

% mutates each element with given probability and returns the resulting

% population.

%

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

%

% Input parameters:

%

%           OldChrom - A matrix containing the chromosomes of the

%                     current population. Each row corresponds to

%                     an individuals string representation.

%

%           Pm  - Mutation probability (scalar). Default value

%                     of Pm = 0.7/Lind, where Lind is the chromosome

%                     length is assumed if omitted.

%

%           BaseV     - Optional row vector of the same length as the

%                     chromosome structure defining the base of the

%                     individual elements of the chromosome. Binary

%                     representation is assumed if omitted.

%

% Output parameter:

%

%           NewChrom - A Matrix containing a mutated version of

%                     OldChrom.

%

% Author: Andrew Chipperfield

% Date: 25-Jan-94

function NewChrom = mut(OldChrom,Pm,BaseV)

% get population size (Nind) and chromosome length (Lind)

[Nind, Lind] = size(OldChrom) ;

% check input parameters

if nargin < 2, Pm = 0.7/Lind ; end

if isnan(Pm), Pm = 0.7/Lind; end

if (nargin < 3), BaseV = crtbase(Lind);  end

if (isnan(BaseV)), BaseV = crtbase(Lind);  end

if (isempty(BaseV)), BaseV = crtbase(Lind);  end

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

   error('OldChrom and BaseV are incompatible'), end

% create mutation mask matrix

BaseM = BaseV(ones(Nind,1),:) ;

% perform mutation on chromosome structure

NewChrom = rem(OldChrom+(rand(Nind,Lind)<Pm).*ceil(rand(Nind,Lind).*(BaseM-1)),BaseM);

附录 八

基于遗传算法的最大类间方差法对JPG格式图像分割的程序源代码:

clear, close all

B=imread('she.jpg');                                          %读入原始jpg格式图像

figure(1);

imshow(B),title('原始jpg格式图像');

I1=rgb2gray(B);                                          %将原图像转化为灰度图象

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);                              %将灰度图像转化为索引图像

I1=double(I1);                                     %将unit8数组转化为double型数组

 Z=I1                                             %将double型数组I1转存到Z中

figure(3)                                              %画出未进行分割的原始图像

image(Z),title('未进行分割的原始图像');colormap(map1);        

NIND=40;                                         %个体

上一篇:计算机多媒体技术应用分析 下一篇:没有了