clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
img = double(imread(['siahosefid' '.bmp']))./255;
figure;
imshow(img);
[nrow, ncol] = size(img);
for nMethod = 1:4;
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(temp11,1));
for kk = 1:size(temp11,1)
temp00(kk) = abs(img(temp11(kk,1), temp11(kk,2))-img(temp22(kk,1), temp22(kk,2)));
end
if size(temp11,1) == 0
v(rr, cc) = 0;
v_norm = v_norm + v(rr, cc);
else
lambda = 10;
switch nMethod
case 1
temp00 = lambda .* temp00;
case 2
temp00 = lambda .* temp00.^2;
case 3
temp00 = sin(pi .* temp00./2./lambda);
case 4
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;
beta = 0.1;
rho = 0.1;
phi = 0.05;
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';
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_total_num, memory_length);
if nrow*ncol == 128*128
total_step_num = 300;
elseif nrow*ncol == 256*256
total_step_num = 900;
elseif nrow*ncol == 512*512
total_step_num = 1500;
end
total_iteration_num = 10;
for iteration_idx = 1: total_iteration_num
delta_p = zeros(nrow, ncol);
for step_idx = 1: total_step_num
delta_p_current = zeros(nrow, ncol);
for ant_idx = 1:ant_total_num
ant_current_row_idx = ant_pos_idx(ant_idx,1);
ant_current_col_idx = ant_pos_idx(ant_idx,2);
if search_clique_mode == '4'
rr = ant_current_row_idx;
cc = ant_current_col_idx;
ant_search_range_temp = [rr-1 cc; rr cc+1; rr+1 cc; rr cc-1];
elseif search_clique_mode == '8'
rr = ant_current_row_idx;
cc = ant_current_col_idx;
ant_search_range_temp = [rr-1 cc-1; rr-1 cc; rr-1 cc+1; rr cc-1; rr cc+1; rr+1 cc-1; rr+1 cc; rr+1 cc+1];
end
temp = find(ant_search_range_temp(:,1)>=1 & ant_search_range_temp(:,1)<=nrow & ant_search_range_temp(:,2)>=1 & ant_search_range_temp(:,2)<=ncol);
ant_search_range = ant_search_range_temp(temp, :);
ant_transit_prob_v = zeros(size(ant_search_range,1),1);
ant_transit_prob_p = zeros(size(ant_search_range,1),1);
for kk = 1:size(ant_search_range,1)
temp = (ant_search_range(kk,1)-1)*ncol + ant_search_range(kk,2);
if length(find(ant_memory(ant_idx,:)==temp))==0
ant_transit_prob_v(kk) = v(ant_search_range(kk,1), ant_search_range(kk,2));
ant_transit_prob_p(kk) = p(ant_search_range(kk,1), ant_search_range(kk,2));
else
ant_transit_prob_v(kk) = 0;
ant_transit_prob_p(kk) = 0;
end
end
if (sum(sum(ant_transit_prob_v))==0) | (sum(sum(ant_transit_prob_p))==0)
for kk = 1:size(ant_search_range,1)
temp = (ant_search_range(kk,1)-1)*ncol + ant_search_range(kk,2);
ant_transit_prob_v(kk) = v(ant_search_range(kk,1), ant_search_range(kk,2));
ant_transit_prob_p(kk) = p(ant_search_range(kk,1), ant_search_range(kk,2));
end
end
ant_transit_prob = (ant_transit_prob_v.^alpha) .* (ant_transit_prob_p.^beta) ./ (sum(sum((ant_transit_prob_v.^alpha) .* (ant_transit_prob_p.^beta))));
rand('state', sum(100*clock));
temp = find(cumsum(ant_transit_prob)>=rand(1), 1);
ant_next_row_idx = ant_search_range(temp,1);
ant_next_col_idx = ant_search_range(temp,2);
if length(ant_next_row_idx) == 0
ant_next_row_idx = ant_current_row_idx;
ant_next_col_idx = ant_current_col_idx;
end
ant_pos_idx(ant_idx,1) = ant_next_row_idx;
ant_pos_idx(ant_idx,2) = ant_next_col_idx;
delta_p_current(ant_pos_idx(ant_idx,1), ant_pos_idx(ant_idx,2)) = 1;
if step_idx <= memory_length
ant_memory(ant_idx,step_idx) = (ant_pos_idx(ant_idx,1)-1)*ncol + ant_pos_idx(ant_idx,2);
elseif step_idx > memory_length
ant_memory(ant_idx,:) = circshift(ant_memory(ant_idx,:),[0 -1]);
ant_memory(ant_idx,end) = (ant_pos_idx(ant_idx,1)-1)*ncol + ant_pos_idx(ant_idx,2);
end
p = ((1-rho).*p + rho.*delta_p_current.*v).*delta_p_current + p.*(abs(1-delta_p_current));
end
delta_p = (delta_p + (delta_p_current>0))>0;
p = (1-phi).*p;
end
end
T = func_seperate_two_class(p);
figure;
imshow(uint8(abs((p>=T).*255-255)));
end
fpga和matlab
- 粉丝: 18w+
- 资源: 2651
最新资源
- 粒子滤波在电力负荷预测中的应用:Python代码复现与详细算法解析,关于粒子滤波在电力负荷预测中的应用 python源代码,代码按照高水平文章复现,有详细说明,保证正确 在线预测电力负荷,在贝叶斯框
- 电力价格风险管理:MATLAB源码复现与波动性分析:从布莱克-斯科尔斯模型到极端价格应对策略探索,能源价格风险管理matlab源代码,代码按照高水平文章复现,保证正确 电力价格的波动性远远大于其他通常
- libgpg-error-1.12-3.el7.x64-86.rpm.tar.gz
- libgpg-error-devel-1.12-3.el7.x64-86.rpm.tar.gz
- 电力市场中生产者战略招标:凸规划方法与matlab源代码实践高效解决方案,电力市场中生产者的战略招标:一种凸松弛方法matlab 源代码,代码按照高水平文章复现,保证正确 电力市场中的战略投标问题在电
- libgphoto2-2.5.15-3.el7.x64-86.rpm.tar.gz
- FMC ADC12D2000RF模块:高端数据采集,含开发包与源代码,国内稀缺,珍贵转让,FMC ADC12D2000RF 模块,忍痛出射频直接采集FMC ADC模块,模块基于Ti公司高端ADC12
- libgpod-0.8.2-12.el7.x64-86.rpm.tar.gz
- FPGA PCI代码模块详解:完整实现与详尽注释,FPGA pci代码,模块完整,注释完整 ,FPGA; PCI代码; 模块完整; 注释完整;,"FPGA PCI代码全集:模块完备,详尽注释的编程宝
- libgpod-devel-0.8.2-12.el7.x64-86.rpm.tar.gz
- 欧姆龙CP1e与三台变频器Modbus 485通讯实现启停与频率给定控制,欧姆龙CP1e与三台欧姆龙变频器走485modbus通讯程 启停,频率给定控制 ,核心关键词:欧姆龙CP1e; 欧姆龙变频器
- libgpod-doc-0.8.2-12.el7.x64-86.rpm.tar.gz
- libgs-9.25-5.el7.x64-86.rpm.tar.gz
- 西门子S7-200 Smart与施耐德ATV变频器Modbus通讯:实现稳定控制及自动化启停与状态监测功能,接线与设置指南 ,西门子200smart与施耐德ATV变频器modbus通讯 西门子s7-2
- libgs-devel-9.25-5.el7.x64-86.rpm.tar.gz
- "上市公司TI平台高低压软启动控制源码揭秘:联系获取源码及厂家图,低压软启动方案同时呈现",上市公司的高压软启动控制源码,源码,需要的联系,平台TI,厂家见图,也有低压软起动的方案, ,上市公司; 高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈