Phase shift of image

Hi, I need a code that allow me to measure the phase shfit of a image, but i don't know how to code it. May i get some help with this? Thank you.

5 Comments

Rik
Rik on 9 Nov 2020
What have you tried so far?
Hi sir, i'm doing phase retrieve algorithm, i manage to retrieve the phase already but i fail to measure the phase shift of the image, I am using around 5 images and i need to measure the phase shift that happened in each image. May I get some help with this? Thank you.
My code:
function F_angle = phase_extraction(data, mode)
% Argument extraction.
default_peak_width = 30;
data= rgb2gray(im2double(imread('50ml(3).jpeg'))); mode = 2; % Data is interferogram image.
img_size = size(data);
%FFT Process and Shift of FFT matrix.
F_data = fft2(data); F_shift_data = fftshift(F_data);
%Data processing on Frequency space.
if (mode == 2)
% setting width of side peak on frequency space.
if (length(3) == 3)
peak_width = varargin(60, 90, 120);
else
peak_width = default_peak_width;
end
% Copying top semicircle of the frequency space to include only one side peak for phase extraction.
separator = 10; % Defining copy-limit from center on frequency space to exclude DC and other side peak.
F_copy_plane = zeros(img_size);
% Copying top semicircle to copy-limit defined by separator.
F_copy_plane(1:round(img_size(1)/2) - separator,:) = F_shift_data(1:round(img_size(1)/2) - separator,:);
% Copying additional region to include right side peak for vertical fringe.
F_copy_plane(round(img_size(1)/2) - separator + 1:round(img_size(1)/2) + separator,round(img_size(2)/2) + separator:img_size(2)) = F_shift_data(round(img_size(1)/2) - separator + 1:round(img_size(1)/2) + separator,round(img_size(2)/2) + separator:img_size(2));
peak_value = max(max(abs(F_copy_plane))); [peak_row,peak_col,~] = find(abs(F_copy_plane) == peak_value); % Finding of peak location.
% Copying only selected region (peak) to the new clean matrix.
F_only_peak = zeros(img_size);
F_only_peak(peak_row - round(peak_width/2):peak_row + round(peak_width/2),peak_col - round(peak_width/2):peak_col + round(peak_width/2)) = F_copy_plane(peak_row - round(peak_width/2):peak_row + round(peak_width/2),peak_col - round(peak_width/2):peak_col + round(peak_width/2));
F_shift_to_center = circshift(F_only_peak,[(round(img_size(1)/2) - peak_row) (round(img_size(2)/2) - peak_col)]);
else
Figure; imagesc(log10(abs(F_shift_data))); colormap('Gray');
title('Select side peak for phase extraction by drawing rectanglar box.');
rect = getrect; % Selecting peak for phase extraction by drawing rectanglar box.
rect = round(rect);
% Copying only selected region (peak) to the new clean matrix.
F_only_peak = zeros(img_size);
F_only_peak(rect(2):rect(2) + rect(4),rect(1) : rect(1) + rect(3)) = F_shift_data(rect(2):rect(2) + rect(4),rect(1) : rect(1) + rect(3));
peak_value = max(max(abs(F_only_peak))); [peak_row,peak_col,~] = find(abs(F_only_peak) == peak_value); % Finding of peak location.
% Shifting peak to the center
F_shift_to_center = circshift(F_only_peak,[(round(img_size(1)/2) - peak_row) (round(img_size(2)/2) - peak_col)]);
end
% Inverse FFT.
F_ishift = ifftshift(F_shift_to_center); Inv = ifft2(F_ishift);
% Phase extraction.
F_angle = angle(Inv);
%Display output as image
figure(1), imagesc(real(F_angle)), title ('Phase Extraction'), colorbar, colormap gray;
end
Rik
Rik on 9 Nov 2020
If you are already able to calculate the phase of each image, shouldn't you simply take one of them as your 0 (subtracting its value from the others) to find the shift?
Hi sir, based on the code i only manage to retrieve the phase and display it in the form of image, there are no values in it, so im not sure how i can do it.
Soong Wei Kang
Soong Wei Kang on 9 Nov 2020
Edited: Soong Wei Kang on 9 Nov 2020
i have attach an image of a graph gotten from a journal article, I think that this is the best way to measure and present the phase shift for diffenrent images (for my case, i am also doing moisture content of leaf), but I'm not sure how to do it and i think is quite impossible to do it on my code. May I get some help with this? Thank you.

Sign in to comment.

Answers (0)

Asked:

on 9 Nov 2020

Edited:

on 9 Nov 2020

Community Treasure Hunt

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

Start Hunting!