Skip to content

Instantly share code, notes, and snippets.

@serialhex
Last active July 6, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serialhex/2ba62c53f760364e58f0c6a11f43d1ba to your computer and use it in GitHub Desktop.
Save serialhex/2ba62c53f760364e58f0c6a11f43d1ba to your computer and use it in GitHub Desktop.
all 3 plots should be the same, they are not!
https://postimg.org/image/vdcnsnafb/
%This program is to simulate a continuous phase distribution to act as a dataset
%for use in the 2D phase unwrapping problem
clc; close all; clear
N = 512;
[x,y]=meshgrid(1:N);
image1 = 2*peaks(N) + 0.1*x + 0.01*y;
figure, colormap(gray(256)), imagesc(image1)
title('Continuous phase image displayed as a visual intensity array')
xlabel('Pixels'), ylabel('Pixels')
figure, plot(image1(410,:))
title('Row 410 of the continuous phase image')
xlabel('Pixels'), ylabel('Phase in radians')
figure
surf(image1,'FaceColor','interp', 'EdgeColor','none') %, 'FaceLighting','flat')
view(-30,30)%, camlight left, axis tight
title(' Continuous phase map image displayed as a surface plot')
xlabel('Pixels'), ylabel('Pixels'), zlabel('Phase in radians')
%wrap the 2D image
image1_wrapped = atan2(sin(image1), cos(image1));
figure, colormap(gray(256)), imagesc(image1_wrapped)
title('Wrapped phase image displayed as a visual intensity array')
xlabel('Pixels'), ylabel('Pixels')
figure
surf(image1_wrapped,'FaceColor','interp', 'EdgeColor','none')%, 'FaceLighting','phong')
view(-30,70)%, camlight left, axis tight
title('Wrapped phase image plotted as a surface')
xlabel('Pixels'), ylabel('Pixels'), zlabel('Phase in radians')
figure, plot(image1_wrapped(410,:))
title('Row 410 of the wrapped phase image')
xlabel('Pixels'), ylabel('Phase in radians')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Unwrap the image using the Itoh algorithm: the first method is performed
%by first sequentially unwrapping the all rows, one at a time.
image1_unwrapped = image1_wrapped;
for i=1:N
image1_unwrapped(i,:) = unwrap(image1_unwrapped(i,:));
end
%Then sequentially unwrap all the columns one at a time
for i=1:N
image1_unwrapped(:,i) = unwrap(image1_unwrapped(:,i));
end
figure, colormap(gray(256)), imagesc(image1_unwrapped)
title('Unwrapped phase image using the Itoh algorithm: the first method')
xlabel('Pixels'), ylabel('Pixels')
figure
surf(image1_unwrapped,'FaceColor','interp', 'EdgeColor','none')%, 'FaceLighting','phong')
view(-30,30)%, camlight left, axis tight
title('Unwrapped phase image using the Itoh algorithm: the first method')
xlabel('Pixels'), ylabel('Pixels'), zlabel('Phase in radians')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Unwrap the image using the Itoh algorithm: the second method
%performed by first sequentially unwrapping all the columns one at a time.
image2_unwrapped = image1_wrapped;
for i=1:N
image2_unwrapped(:,i) = unwrap(image2_unwrapped(:,i));
end
%Then sequentially unwrap all the a rows one at a time
for i=1:N
image2_unwrapped(i,:) = unwrap(image2_unwrapped(i,:));
end
figure, colormap(gray(256)), imagesc(image2_unwrapped)
title('Unwrapped phase image using Itoh algorithm: the second method')
xlabel('Pixels'), ylabel('Pixels')
figure
surf(image2_unwrapped,'FaceColor','interp', 'EdgeColor','none')%, 'FaceLighting','phong')
view(-30,30)%, camlight left, axis tight
title('Unwrapped phase image using the Itoh algorithm: the second method')
xlabel('Pixels'), ylabel('Pixels'), zlabel('Phase in radians')
figure, plot(image2_unwrapped(410,:))
title('Row 410 of the unwrapped phase image')
xlabel('Pixels'), ylabel('Phase in radians')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment