How to use PSO for edge detection?

16 views (last 30 days)
Musa M.Ameen
Musa M.Ameen on 10 Jan 2016
Answered: Selva on 17 Sep 2017
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
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
% 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));
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) ;
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
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)) ;
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) ;
[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);
velocity = w *velocity + c1*(R1.*(local_best_position-current_position)) + c2*(R2.*(globl_best_position-current_position));
current_position = current_position + velocity;
plot(x, y , 'h')
axis([-5 5 -5 5]);
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
Walter Roberson
Walter Roberson on 18 Jun 2017
qiwu li: the person who posted this Question will not be notified about your comment.

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 10 Jan 2016
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.
Walter Roberson
Walter Roberson on 11 Jan 2016
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.

Sign in to comment.

Selva on 25 Aug 2017
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.

Selva on 17 Sep 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by