How to use PSO for edge detection?

2 visualizaciones (últimos 30 días)
Musa M.Ameen
Musa M.Ameen el 10 de En. de 2016
Respondida: Selva el 17 de Sept. de 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
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 comentarios
qiwu li
qiwu li el 18 de Jun. de 2017
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
Walter Roberson el 18 de Jun. de 2017
qiwu li: the person who posted this Question will not be notified about your comment.

Iniciar sesión para comentar.

Respuestas (3)

Walter Roberson
Walter Roberson el 10 de En. de 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.
  4 comentarios
Musa M.Ameen
Musa M.Ameen el 11 de En. de 2016
Do you have or know any algorithm that works with gradients?
Walter Roberson
Walter Roberson el 11 de En. de 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.

Iniciar sesión para comentar.


Selva
Selva el 25 de Ag. de 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
Selva el 17 de Sept. de 2017

Categorías

Más información sobre Particle Swarm en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by