how to generate a digital hologram.
Show older comments
I have to write a Matlab code for my experiments which could generate a digital hologram. can anyone help me with the code.
Answers (1)
Zulqarnain Sheikh
on 2 Feb 2018
Edited: Guillaume
on 23 Feb 2022
Here you go
clc
close all
clear all
%Gaussian Beam
basenum = 1; %Any number but not 0 x = linspace(-2*basenum,2*basenum,5000); %10000 points between -2 to 2 in case basenum is 1 y = linspace(-2*basenum,2*basenum,5000); %10000 points between -2 to 2 in case basenum is 1
[X,Y] = meshgrid(x,y); %produced 2d array for plot intensity = exp(-2 * (X.^2 + Y.^2) / basenum^2); % Formula to generate pattern of gaussian beam
% figure % Z = imagesc(intensity); % To plot values from matrix as an image I = mat2gray(intensity); % To convert rgb matrix into a grayscale image gaussian_beam = I(2000:3000,2000:3000); gaussian_beam = imresize(gaussian_beam, [500 500]); % Displaying only central portion of gaussian beam figure(1) imshow(gaussian_beam)
% Algo Initiate
% GS imRead
Object=im2double(imread('img1.jpg')); Object_new=im2bw(Object); Object_new=imresize(Object_new, [500 500]); Fk0 = Object_new; figure(2) imshow(Fk0)
% Image + Gauss
Gk = Object_new.*exp(i*gaussian_beam); % figure(3) % imshow(Gk) % Fk0 = fft2(fftshift(Gk)); j1 = Fk0; % j1=fft2(fftshift(Gk)); j=abs(j1)/(max(max(abs(j1)))); j=imadjust(abs(j), [0; 0.01], [0; 1]); rmse = 0; for k=1:1:150 Fk = ifftshift(ifft2(Fk0)); % figure(40 % imshow(Fk) phase = angle(Fk); %Gu=medfilt2(j).*exp(i*phase); Gu=exp(i*phase); Fk1 = fft2(fftshift(Gu)); Fk0=abs(Object_new).*exp(i*angle(Fk1)); figure(4),imagesc(abs(Fk1)); colormap(gray), title(num2str(k));
% RMSE
if k>=2
rmse(k)=sqrt(sum(abs(Fk1(k))-Fk0(k-1))^2/k);
t(k) = 1*k; %simulation time, where dt is time for one increment of loop
end
% if t==0
end figure(5) stem(t,rmse);
Categories
Find more on Color Segmentation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!