How to use PSO for edge detection?
3 次查看(过去 30 天)
显示 更早的评论
I'm new in matlab and I'm currently working on a edge detection using PSO (Particle Swarm Optimazation). I have this PSO code (I got it from internet and NOT sure if its right one or not), I want to use it for edge detection but I dont know how to initialize the image or where to put image matrix??
If its possible could you convert it to a function so it can take any image and outputs image(edge) matrix.
I would appreciate your answers
Regards
clc
n = 50; % Size of the swarm " no of birds "
bird_step = 50; % Maximum number of "birds steps"
dim = 2; % Dimension of the problem
c2 =1.1; % PSO parameter C1 1.1
c1 = 0.12; % PSO parameter C2 0.12
w =0.9; % pso momentum or inertia 0.9
fitness=0*ones(n,bird_step);
%-----------------------------%
% initialize the parameter %
%-----------------------------%
R1 = rand(dim, n);
R2 = rand(dim, n);
current_fitness =0*ones(n,1);
%------------------------------------------------%
% Initializing swarm and velocities and position %
%------------------------------------------------%
current_position = 10*(rand(dim, n)-.5);
velocity = .3*randn(dim, n) ;
local_best_position = current_position ;
%-------------------------------------------%
% Evaluate initial population %
%-------------------------------------------%
for i = 1:n
current_fitness(i) = Live_fn(current_position(:,i));
end
local_best_fitness = current_fitness ;
[global_best_fitness,g] = min(local_best_fitness) ;
for i=1:n
globl_best_position(:,i) = local_best_position(:,g) ;
end
%-------------------%
% VELOCITY UPDATE %
%-------------------%
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
%------------------%
% SWARMUPDATE %
%------------------%
current_position = current_position + velocity ;
%------------------------%
% evaluate anew swarm %
%------------------------%
%%Main Loop
iter = 0 ; % Iterations’counter
while ( iter < bird_step )
iter = iter + 1;
for i = 1:n,
current_fitness(i) = Live_fn(current_position(:,i)) ;
end
for i = 1 : n
if current_fitness(i) < local_best_fitness(i)
local_best_fitness(i) = current_fitness(i);
local_best_position(:,i) = current_position(:,i) ;
end
end
[current_global_best_fitness,g] = min(local_best_fitness);
if current_global_best_fitness < global_best_fitness
global_best_fitness = current_global_best_fitness;
for i=1:n
globl_best_position(:,i) = local_best_position(:,g);
end
end
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
current_position = current_position + velocity;
x=current_position(1,:);
y=current_position(2,:);
clf
plot(x, y , 'h')
axis([-5 5 -5 5]);
pause(.2)
end % end of while loop its mean the end of all step that the birds move it
[Jbest_min,I] = min(current_fitness); % minimum fitness
current_position(:,I); % best solution
2 个评论
qiwu li
2017-6-18
I'm also working on an edge detection using PSO,and it really troubles me.Have you solved it yet?if you have,please email me at 13720438707@163.com,and i need your help.Thank you
Walter Roberson
2017-6-18
qiwu li: the person who posted this Question will not be notified about your comment.
回答(3 个)
Walter Roberson
2016-1-10
The means to input anything to that PSO code would be related to the function Live_fn which you do not show here. The Live_fn is the objective function. It is being passed in a column which is an x/y coordinate pair, and it is responsible for somehow translating that coordinate pair into a fitness of whatever you are seeking.
You could use the technique of parameterizing functions to pass additional information in to an objective function.
You have the difficulty that Particle Swarm techniques are looking for a single optimum over the entire range, whereas edge detection algorithms need to find edges all over the image. It is even possible that every point in the image is on some edge -- for example if you alternate red pixels and green pixels then each red point is an edge between adjacent green areas and each green point is an edge between adjacent red areas.
We have no advice on how to convert a coordinate pair into a edge detection goodness, or how to extend a global minimization technique into a lot of local values. You will need to research that. When people ask this question they either do not get an answer or they get told to research the matter. We do not know ourselves.
4 个评论
Walter Roberson
2016-1-11
It is plausible that the algorithm might work if g is the sum of squares of the two gradient components. However, I do not know how one might use a PSO on a pixel to "get a fitness curve C", or what the G_c or min_L is.
Selva
2017-8-25
Mahdi S, Mengjie Z, Mark J. A novel particle swarm optimisation approach to detecting continuous, thin and smooth edges in noisy images. Inf Sci 2013;246:28–51.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!