Need help with Phase Only Image Correlation

조회 수: 3 (최근 30일)
Twain
Twain 2014년 7월 10일
답변: Dima Lisin 2014년 7월 22일
Hello, I am attempting to correlate an image drawn from a video with a cropped out portion of the same image. We are having dimension problems that wont seem to go away. I believe that there may be some underlying problem that I am not recognizing. Any help is appreciated, I have posted the code below. Unfortunately the Mp4 file we used is too large to attach, but this code should operate the same for any video file.
function[] = Again(~)
prompt = 'Name of file?\n'; %Prompt user to input a video file.
result = input(prompt);
%Step through the video frame by frame. We chose 58 as an arbitrary point %to stop where we know a good variety of objects are present.
videoFReader = vision.VideoFileReader(result);
videoPlayer = vision.VideoPlayer;
j = 0;
while j<58;
%while ~isDone(videoFReader)
videoFrame = step(videoFReader);
step(videoPlayer,videoFrame);
j=j+1;
i=step(videoFReader); %Save the image as variable i
hold on
end
%imtool(i);
%Crop out a section of image(i) and assign it variable h. Here we did it in %two seperate ways, just for fun...
%h=imcrop(i,[1016 488 219 157]);
h = i(488:645,1016:1235,3);
h(720,1280,3)= 0; %Ensure image dimensions of i and h match
imshow (h); %Now the hat is red?
figure, imshow (i);
%Here we used the ndims, length, & numel functions to determine if each image %has the desired matrix dimensions and more importatntly that they are %identicle.
%ndims(i)
%length(i)
%numel(i)
%ndims(h)
%length(h)
%numel(h)
%In our first attempt to correlate two images we chose to first attempt to %use both magnitude and phase. However now we are attempting to us only the %phase to correlate the images and create a mesh to show any matches. We %have included both attempts although neither work. Each returns similar %errors about the matrix dimensions of the two files.
%********************* Attemp to coorrelate #1*****************************
%To ensure the the cropped image has the same dimensions %as image i, we include the 720,1280
I = fft2(i);
H = fft2(h,720,1280);
%Here is what we beleive to be two functional ways to extract the phase %information the fourier transfor of an image. We chose the latter for %simplicity.
%F_Phase = cos(angle(I)) + j*(sin(angle(I)));
%F_Phase2 = cos(angle(H)) + j*(sin(angle(H)));
F_Phase = exp(1j*angle(I));
F_Phase2 = exp(1j*angle(H));
%This is what we beleive would be the way to correlate two images based on %phase and magnitude information.
%conjH=conj(H);
%R = I .* conjH;
%We have read that correlation is like convlution but rotated 180 degrees, % and mathmatically it makes sense. However this is where the error occur. % The error we get regularily is that "The Matrix sizes must be the same" % despite the images being the same dimensions.
R = F_Phase .* (rot90(F_Phase2,2));
%Here we take the inverse fourier transform and set it to real values so %that we may view the results using the mesh function.
res=real(ifft2®);
%size(res)
mesh(res);
%*************************************************************************
%Release the video player and reader.
release(videoPlayer);
release(videoFReader);
end
  댓글 수: 1
Image Analyst
Image Analyst 2014년 7월 10일
Does your code demonstrate the same error if we use rhinos.avi or traffic.avi - the demo movies that ship with MATLAB?

댓글을 달려면 로그인하십시오.

답변 (1개)

Dima Lisin
Dima Lisin 2014년 7월 22일
Image Processing Toolbox now includes the imregcorr function, which does phase correlation.

카테고리

Help CenterFile Exchange에서 Point Cloud Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by