Object based phase correlation tracking method.....

3 vues (au cours des 30 derniers jours)
Harsha Vardhan Rao  Avunoori
[EDIT: 20110524 09:49 CDT - reformat - WDR]
I have been trying to implement object based phase correlation tracking to track birds in my images....and there are some issues with my code...On running the code I got these errors which are quite clear that they is something wrong with the code I wrote to perform erosion...
% To implement Correlation Tracking
%Author: Harsha Vardhan Rao Avunoori
%Steps to implement Correlation 1.Load Images 2.Convert into Gray Scale
%3.Perform FFT on images 4.Convolve Images 5.Post Processing stage which
%includes Median Filtering Dilation and Erosion
%Loading Input Image
a = imread('img_9.jpg');
figure(1)
imshow(a)
%Loading Target Image
b = imread('img_11.jpg');
figure(2)
imshow(b)
size(a)
size(b)
%RGB2GRAY conversion of input image
i = rgb2gray(a);
[r c] = size(i);
figure(3)
imshow(i)
size(i)
%RGB2GRAY conversion of target image
p=rgb2gray(b);
figure(4)
imshow(p)
%Performing FFT of input image and target image
img_i = fft2(i);
img_p=fft2(p);
figure(5)
plot(img_i)
figure(6)
plot(img_p)
img_f = zeros(r,c);
%Multiplying the FFT of Input and Target Images
for i=1:r
for j= 1:c
img_f(i,j) = img_i(i,j).*img_p(i,j);
end
end
img_if = zeros(r,c);
%Perfrom inverse FFT on multiplied image
for i=1:r
for j=1:c
img_if(i,j) = ifft2(img_f(i,j));
end
end
figure(7)
imshow(img_if)
img_if1 = zeros(r,c);
%Perform Median filtering using medfilt2 for a 3 x 3 neighborhood
%Point to note is medfilt2 is not accepting complex values so I took
%abs(img_if) to make it a real value
img_if1 = medfilt2(abs(img_if),[3 3]);
figure(8)
imshow(img_if1)
%Perform Erosion using imerode function
%Never tried erosion before so took a simple strel
z = ones(4,4)
SE = strel(z)
img_ero=imerode(img_if1,'SE');
%Something is wrong erosion gives out an error
figure(9)
imshow(img_ero)
%Perform Dilation using imdilate function
h = eye(5)
SE = strel(h)
img_dil=imdilate(img_ero,'SE');
figure(10)
imshow(img_dil)
Errors after executing the code
??? Error using ==> strelcheck at 19
Function imerode expected its second input argument, SE, to be either numeric or logical.
Error in ==> morphop>ParseInputs at 165
se = strelcheck(se,func_name,'SE',2);
Error in ==> morphop at 14
[A,se,pre_pad,...
Error in ==> imerode at 123
B = morphop(A,se,'erode',mfilename,varargin{:});
Error in ==> Test2 at 81
img_ero=imerode(img_if1,'SE');
What might be the problem ?? Any help would be appreciated...

Réponse acceptée

Sean de Wolski
Sean de Wolski le 29 Mar 2011
'SE' is a two element string
imdilate(img_ero,SE)
  1 commentaire
Harsha Vardhan Rao  Avunoori
Hey Sean thanks for letting me know I have changed SE = strel('line',4,45) where 4 = length and 45 = degrees....On execution I don't get an error now but the image is complete white...I think I should look at the Median filtering code.....
Thanks for helping out....

Connectez-vous pour commenter.

Plus de réponses (1)

Sean de Wolski
Sean de Wolski le 29 Mar 2011
I'm just getting ready to leave work for the day, but here are a few things:
don't call fft2/ifft2 in a for-loop! You're taking the DFT/IDFT at each point, not the matrix as a whole:
FFTR = fft2(img1).*fft2(img2); %don't call the variables i as this is the square root of negative 1 and WILL affect your results
PCM = ifft2(FFTR./(3+abs(FFTR))); %peak correlation matrix
[pk idx] = max(PCM);
[row_pk, col_pk] = ind2sub(size(PCM),idx);
  2 commentaires
Harsha Vardhan Rao  Avunoori
Sean how can I plot motion field for this phase correlation method ?
Sean de Wolski
Sean de Wolski le 30 Mar 2011
doc quiver

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by