• 大小: 19KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: 其他
  • 标签: 边缘检测  

资源简介

写了一些关于图像基于蚁群算法边缘检测的例子,程序含有说明解释,适合初学者。

资源截图

代码片段和文件信息

function edge_ACO
%参考文献:“An Ant Colony Optimization Algorithm For Image Edge
close all; clear all; clc;
% 读入图像
 filename = ‘ant128‘;
img=rgb2gray(imread(‘ant.jpg‘));
img = double(img)./255;
[nrow ncol] = size(img);
%公式(3.24.4)初始化
 for nMethod = 1:4;
  %四种不同的核函数 参见式 (3.24.7)-(3.24.10)
  %E: exponential; F: flat; G: gaussian; S:Sine; T:Turkey; W:Wave
  fprintf(‘Welcome to demo program of image edge detection using ant colony.\nPlease wait......\n‘);
    v = zeros(size(img));
    v_norm = 0;
    for rr =1:nrow
        for cc=1:ncol
            %定义像素团
            temp1 = [rr-2 cc-1; rr-2 cc+1; rr-1 cc-2; rr-1 cc-1; rr-1 cc; rr-1 cc+1; rr-1 cc+2; rr cc-1];
            temp2 = [rr+2 cc+1; rr+2 cc-1; rr+1 cc+2; rr+1 cc+1; rr+1 cc; rr+1 cc-1; rr+1 cc-2; rr cc+1];
            temp0 = find(temp1(:1)>=1 & temp1(:1)<=nrow & temp1(:2)>=1 & temp1(:2)<=ncol & temp2(:1)>=1 & temp2(:1)<=nrow & temp2(:2)>=1 & temp2(:2)<=ncol);
            temp11 = temp1(temp0 :);
            temp22 = temp2(temp0 :);
            temp00 = zeros(size(temp111));
            for kk = 1:size(temp111)
                temp00(kk) = abs(img(temp11(kk1) temp11(kk2))-img(temp22(kk1) temp22(kk2)));
            end
            if size(temp111) == 0
                v(rr cc) = 0;
                v_norm = v_norm + v(rr cc);
            else
                lambda = 10;
                switch nMethod
                    case 1%‘F‘
                        temp00 = lambda .* temp00;        
                    case 2%‘Q‘
                        temp00 = lambda .* temp00.^2;       
                    case 3%‘S‘
                        temp00 = sin(pi .* temp00./2./lambda);
                    case 4%‘W‘
                    temp00 = sin(pi.*temp00./lambda).*pi.*temp00./lambda;
                end
                v(rr cc) = sum(sum(temp00.^2));
                v_norm = v_norm + v(rr cc);
            end
        end
    end
 % 归一化
v = v./v_norm;  
    v = v.*100;
    p = 0.0001 .* ones(size(img));     % 信息素函数初始化
    %参数设置。
alpha = 1;      %式(3.24.4)中的参数
beta = 0.1;     %式(3.24.4)中的参数
rho = 0.1;      %式(3.24.11)中的参数
%式(3.24.12)中的参数
    phi = 0.05;     %equation (12) i.e. (9) in IEEE-CIM-06
    ant_total_num = round(sqrt(nrow*ncol));
 % 记录蚂蚁的位置
    ant_pos_idx = zeros(ant_total_num 2); 
 % 初始化蚂蚁的位置
    rand(‘state‘ sum(clock));
    temp = rand(ant_total_num 2);
    ant_pos_idx(:1) = round(1 + (nrow-1) * temp(:1)); %行坐标
   ant_pos_idx(:2) = round(1 + (ncol-1) * temp(:2)); %列坐标
   search_clique_mode = ‘8‘;   %Figure 1
   % 定义存储空间容量
   if nrow*ncol == 128*128
        A = 40;
        memory_length = round(rand(1).*(1.15*A-0.85*A)+0.85*A);    
elseif nrow*ncol == 256*256
        A = 30;
        memory_length = round(rand(1).*(1.15*A-0.85*A)+0.85*A);
    elseif nrow*ncol == 512*512
        A = 20;
        memory_length = round(rand(1).*(1.15*A-0.85*A)+0.85*A);    
    end
    ant_memory = zeros(ant_tot

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

     文件       5121  2011-07-17 18:09  3.24 基于蚁群算法的图像边缘检测\ant.jpg

     文件       4590  2011-09-26 22:40  3.24 基于蚁群算法的图像边缘检测\ant128_edge_aco_1.jpg

     文件       4506  2011-09-26 22:41  3.24 基于蚁群算法的图像边缘检测\ant128_edge_aco_2.jpg

     文件       8509  2012-02-15 23:25  3.24 基于蚁群算法的图像边缘检测\edge_ACO.m

     文件      24064  2011-09-26 22:48  3.24 基于蚁群算法的图像边缘检测\程序运行说明.doc

     目录          0  2019-06-18 09:26  3.24 基于蚁群算法的图像边缘检测

----------- ---------  ---------- -----  ----

                46790                    6


评论

共有 条评论