From: Sean on
"Jack Andrews" <krehsi01(a)qub.ac.uk> wrote in message <honcem$4t$1(a)fred.mathworks.com>...
> "Sean " <sean.dewolski(a)Idontwantspam.umit.maine.edu> wrote in message <homnh4$ln$1(a)fred.mathworks.com>...
> > "Jack Andrews" <krehsi01(a)qub.ac.uk> wrote in message <homas9$7iq$1(a)fred.mathworks.com>...
> > > ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <04b58921-0df1-43f7-b830-3c28e1099a92(a)z4g2000yqa.googlegroups.com>...
> > > > Jack Andrews:
> > > > Are you aware that fftshift() DOES NOT Fourier transform the image?
> > >
> > > Oops! Thanks for the reply.
> > > It should be like this
> > >
> > > function [x y peak] = poc(OrImage, RefImage)
> > >
> > > % fourier transform both images
> > > fi = fft2(OrImage);
> > > fr = fft2(RefImage);
> > >
> > > % perform phase correlation (amplitude is normalized)
> > > fc = fi .* conj(fr);
> > > fcn = fc ./ abs(fc);
> > >
> >
> >
> > >>peak_correlation_matrix = ifft2(fcn);
> > >>[peak, idx] = max(abs(peak_correlation_matrix));
> > >>[row col] = ind2sub(size(peak_correlation_matrix),idx)
> > %If you want the peak correlation value it'll be 'peak', if you want the whole correlation matrix it'll be peak_correlation_matrix.
> >
> > >
> > > end;
>
> Sean,
>
> function [x y peak] = pruebapoc1(im1, im2)
>
> % fourier transform both images
> fi = fft2(im1);
> fr = fft2(im2);
>
> % perform phase correlation (amplitude is normalized)
> fc = fi .* conj(fr);
> fcn = fc ./ abs(fc);
> %c = real(ifft2(fcn));
>
> peak_correlation_matrix = real(ifft2(fcn));
> [peak, idx] = max(abs(peak_correlation_matrix));
> [x y] = ind2sub(size(peak_correlation_matrix),idx);
>
> end
>
> Will it be like this?


Yes that'll work, though you don't need the call to real().
However, you do need to note that your 'x' component will be pointing along what is typically thought of as the 'y-axis' and vice versa. That's why I used row and column.

Test your algorithm with sample images like this:

>>I = imread('cameraman.tif'); %Load image
>>I2 = zeros(size(I)+10, 'uint8');
>>I2(4:end-7,7:end-4) = I; %Shift image over (4 down, 7 across)
>>I = padarray(I,[10 10], 0, 'post'); %Make original image same size
>>[x y peak] = pruebapoc1(I, I2);
From: Sean on

>> fcn = fc ./ abs(fc);

One other thing, on this line I scale the denominator to avoid dividing by zero. i.e.
>>fcn = fc./(abs(fc) + 2); %Any scalar will work, I just chose 2 for the example.
From: Jack Andrews on
>
> Test your algorithm with sample images like this:
>
> >>I = imread('cameraman.tif'); %Load image
> >>I2 = zeros(size(I)+10, 'uint8');
> >>I2(4:end-7,7:end-4) = I; %Shift image over (4 down, 7 across)
> >>I = padarray(I,[10 10], 0, 'post'); %Make original image same size
> >>[x y peak] = pruebapoc1(I, I2);

Sean,

Thank you for your support. Can you please explain to me what is happening in the above test algorithm please. Like I2 = zeros(size(I)+10, 'unit8');

Thanks Again
From: Jack Andrews on
>
> Test your algorithm with sample images like this:
>
> >>I = imread('cameraman.tif'); %Load image
> >>I2 = zeros(size(I)+10, 'uint8');
> >>I2(4:end-7,7:end-4) = I; %Shift image over (4 down, 7 across)
> >>I = padarray(I,[10 10], 0, 'post'); %Make original image same size
> >>[x y peak] = pruebapoc1(I, I2);

Sean,

Thank you for your support. Can you please explain to me what is happening in the above test algorithm please. Like I2 = zeros(size(I)+10, 'unit8');

Thanks Again
From: Sean on
"Jack Andrews" <krehsi01(a)qub.ac.uk> wrote in message <hoobk5$q2u$1(a)fred.mathworks.com>...
> >
> > Test your algorithm with sample images like this:
> >
> > >>I = imread('cameraman.tif'); %Load image
> > >>I2 = zeros(size(I)+10, 'uint8');
> > >>I2(4:end-7,7:end-4) = I; %Shift image over (4 down, 7 across)
> > >>I = padarray(I,[10 10], 0, 'post'); %Make original image same size
> > >>[x y peak] = pruebapoc1(I, I2);
>
> Sean,
>
> Thank you for your support. Can you please explain to me what is happening in the above test algorithm please. Like I2 = zeros(size(I)+10, 'unit8');
>
> Thanks Again

%%
I2 = zeros(size(I) +10,'uint8');
%This makes a zero matrix of class uint8 (the same as cameraman or I) and makes it 10rows and 10columns bigger
%Then set a part of this bigger matrix to be the exact same as the first image. I.e. I'm setting rows 4:259 of columns 7:262 equal to your original image. This is a perfectly ideal case (no sub pixel shifts) of image motion. It's actually [3 down, 6 over] I was wrong above.
%Then in order for the array multiplication to work the original image needs to be the same size as the second image.
I = padarray(I,[10 10],0,'post');
%This pads the original cameraman image with 10 rows and 10 columns of zeros after the image. For your own understanding run the original code above then do:
>>imtool(I)
>>imtool(I2)
%That should make it clearer.
Then since the algorithm returns x, y indices into the matrix and the original picture starts in position (1,1) the new indices - original indices will be motion.

from above:
[row col] = sub2ind(size(I), idx);
x = row - 1; %Should be 3
y = col - 1; %Should be 6

Now if you were calculating this shift at somewhere other than (1,1) you would have to subtract those coordinates instead. I don't know what you're applying this to so it makes it hard to understand
What is your end goal here?

Good luck!
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: delete more equal rows
Next: Sparse Neural Networks