Skip to content
Snippets Groups Projects
Commit d8665867 authored by gkj1g12's avatar gkj1g12
Browse files

Upload New File

parent b8dc8fe8
No related branches found
No related tags found
No related merge requests found
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% Girish K. Jankee %%%%%%
%%%%%% University of Southampton %%%%%%
%%%%%% April 2019 %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the main script which generate stereoscopic PIV images. You are
% required to ONLY change the directory and the variables prior to usage.
%
% Any other changes to the script should ONLY BE MADE AFTER DISCUSSION WITH
% THE AUTHORS. WHENEVER MAKING USAGE OF THIS SCRIPT, PLEASE REFER TO AND CITE
% DOI OF THE FOLLOWING PAPER:
% "Comparison between object and image plane cross-correlation for
% stereoscopic PIV in the presence of pixel locking", Girish K. Jankee and
% Bharathram Ganapathisubramani, Experiments in Fluids, February 2020
% DOI: 10.1007/s00348-020-2916-x
% -------------------------------------------------------------------------
% Version 1.0 June 2019
% -------------------------------------------------------------------------
%% Tidy workspace
close all
clearvars
clc
drawnow
tic
warning off
%% User-defined variables
% Directory
root_in_dir = 'I:\Paper 2\Raw Images\'; % Define the root directory where folder will be created
raw_out_dir = [root_in_dir 'Raw Images 1\']; % Path where the synthetic images will be saved
% Calib_dir = ['\\filestore.soton.ac.uk\users\gkj1g12\mydocuments\PhD\Paper 2\Synthetic Image Generator v4\'];
% Calib_file = 'pinhole.mat';
Calib_dir = 'I:\Validation_case7\Properties\Calibration\'; % Define the directory of the calibration file
Calib_file = 'MarkPositionTable.xml'; % Filename which contains the marker locations and properties of calibration
file_out = 'B'; % Filename for generated images
ext_out = '.tiff'; % Format of generated images
% Make directory if it does not exist yet
if exist(raw_out_dir,'dir')~=7
mkdir(raw_out_dir);
end
% Variables
n = 1; % number of synthetic images to be generated
Calib_type = 1; % (1/2) Select 1 for 3rd order polynomial or 2 for Camera pinhole model
sizex = 200; % Dimension of volume to be generated in x-direction [mm]
sizey = 100; % Dimension of volume to be generated in y-direction [mm]
sizez = 1; % Dimension of volume to be generated in z-direction [mm]
Param.density = 70; % Number of particles per mm3
Param.Z = 0.25; % Thickness of laser sheet [px]
Param.dp = 1; % Mean particle diameter [px]
Param.ddp = 0.68; % Standard deviation of the particle diameter [px]
Rot_angles = [0,0,0]; % Vector containing Euler angles that describe 3D rotation;
Trans.x = 0; % Translation in x-direction [px]
Trans.y = 0; % Translation in y-direction [px]
Trans.z = 0.5; % Translation in z-direction [px]
Scale = 1; % Uniform scaling factor to apply to frames (if needed)
noise.app = 0; % Select whether to apply noise or not to the images (0/1)
noise.mean = 0; % Mean of noise signal to add to the images
noise.var = 0.005; % Variance of noise signal to add to the images
turb.mean = 0; % Mean of turbulence profile
turb.var = 0.2*(40/sizey)*Trans.z; % Variance of turbulence profile (default: 10% of max translation)
sv = 0; % (0/1) Select 0 if you do not want to save the images and 1 if you want to save the generated images
plot = 1; % (0/1) Select 0 if you do not want to plot the images and 1 if you want to plot the generated images
%% Calibration and sensor size determination
if Calib_type == 1
% Retrieve calibration markers coordinate for both left and right camera
calibname = [Calib_dir Calib_file];
[Coord,corners_cam] = retrieve_marker_coord(calibname);
% Find coefficients of 3rd order polynomial for transformation from object plane to image plane
[Calib_XL,Calib_YL,mapping_fun] = poly_fit(Coord.Left); % Calibration coefficients for left camera
[Calib_XR,Calib_YR,~] = poly_fit(Coord.Right); % Calibration coefficients for right camera
Transform.Leftcam{1,1} = Calib_XL;
Transform.Leftcam{1,2} = Calib_YL;
Transform.Rightcam{1,1} = Calib_XR;
Transform.Rightcam{1,2} = Calib_YR;
% Sensor size
sensor.x = corners_cam(1,2); % Size of sensor in x direction [px]
sensor.y = corners_cam(2,3); % Size of sensor in y direction [px]
else
% Load calibration properties and projection matrix
load([Calib_dir Calib_file]);
% Retrieve left and right camera transformation from projection matrix
Transform.Leftcam = camera(1).calib.P;
Transform.Rightcam = camera(2).calib.P;
% Sensor size
sensor.x = size(camera(1).i_axis,2); % Size of sensor in x direction [px]
sensor.y = size(camera(1).j_axis,2); % Size of sensor in y direction [px]
end
%% Define the density of particles in the volume
numP = round(Param.density*(sizey)*(sizex)*(sizez));
%% Define laser sheet intensity
z0_pre = randn(numP,1); %distributed sheet intensity for frame 1
randn('state', sum(100*clock));
z1_pre = randn(numP,1); %distributed sheet intensity for frame 2
z0 = z0_pre*0.5 + z1_pre*0.5;
z1 = z0_pre*0.5 + z1_pre*0.5;
I0 = 255*exp(-(Param.Z^2./(0.125*z0.^2))); %particle intensity for frame 1
I0(I0>20) = 255;
I0(I0<20) = 0;
I1 = 255*exp(-(Param.Z^2./(0.125*z1.^2))); %particle intensity for frame 2
I1(I1>20) = 255;
I1(I1<20) = 0;
%% Particle diameter distribution
randn('state', sum(100*clock));
d1 = randn(numP,1)/2; %particle diameter distribution
d1 = Param.dp + d1*Param.ddp;
d1(d1<0) = 0;
rd1 = -8.0 ./ d1.^2;
%% Main script
%Create waitbar
wb = waitbar(0,'1','Name','SIG in process...','CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(wb,'canceling',0);
for i = 1:n
% Check for clicked Cancel button
if getappdata(wb,'canceling')
break
end
% Update waitbar and message
waitbar(i/n,wb,[sprintf('%12.1f',i/n.*100) '%']);
% Generate initial volume of particles
[ini,Cam1]=volume_gen(sizex,sizey,sizez,numP,Transform,Calib_type);
% Place particles in frame
% Left camera
[A.Frame1] = frame_gen(Cam1.L,d1,rd1,numP,sensor,I0);
% Right camera
[B.Frame1] = frame_gen(Cam1.R,d1,rd1,numP,sensor,I0);
% define turbulent intensity
pdx = makedist('Normal','mu',turb.mean,'sigma',turb.var);
pdy = makedist('Normal','mu',turb.mean,'sigma',turb.var);
pdz = makedist('Normal','mu',turb.mean,'sigma',turb.var);
tx = truncate(pdx,-turb.var,turb.var);
ty = truncate(pdy,-turb.var,turb.var);
tz = truncate(pdz,-turb.var,turb.var);
turb_intx = random(tx,[numP,1]);
turb_inty = random(ty,[numP,1]);
turb_intz = random(tz,[numP,1]);
% Apply shear flow
for k = 1:numP
disp.X1(k,1) = ini.X1(k,1) + turb_intx(k,1);
disp.Y1(k,1) = ini.Y1(k,1) + turb_inty(k,1);
disp.Z1(k,1) = ini.Z1(k,1) + (Trans.z./sizey)*ini.Y1(k,1) + turb_intz(k,1);
end
% for k = 1:numP
% disp.X1(k,1) = ini.X1(k,1);
% disp.Y1(k,1) = ini.Y1(k,1);
% disp.Z1(k,1) = ini.Z1(k,1) + (Trans.z./sizey)*ini.Y1(k,1) ;
% end
% Generate displaced volume of particles
[~,Cam2]= volume_gen2(disp,Transform,Calib_type);
% Place particles in frame 2
% Left camera
[A.Frame2] = frame_gen(Cam2.L,d1,rd1,numP,sensor,I1);
% Right camera
[B.Frame2] = frame_gen(Cam2.R,d1,rd1,numP,sensor,I1);
% Apply noise
if noise.app == 1
Frame1.L = imnoise(A.Frame1,'gaussian',noise.mean,noise.var);
Frame1.R = imnoise(B.Frame1,'gaussian',noise.mean,noise.var);
Frame2.L = imnoise(A.Frame2,'gaussian',noise.mean,noise.var);
Frame2.R = imnoise(B.Frame2,'gaussian',noise.mean,noise.var);
else
Frame1.L = A.Frame1;
Frame1.R = B.Frame1;
Frame2.L = A.Frame2;
Frame2.R = B.Frame2;
end
% Save images
if sv ==1
imwrite(Frame1.L, [raw_out_dir file_out sprintf('%05i',i) '_1L' ext_out],'Compression','none');
imwrite(Frame2.L, [raw_out_dir file_out sprintf('%05i',i) '_2L' ext_out],'Compression','none');
imwrite(Frame1.R, [raw_out_dir file_out sprintf('%05i',i) '_1R' ext_out],'Compression','none');
imwrite(Frame2.R, [raw_out_dir file_out sprintf('%05i',i) '_2R' ext_out],'Compression','none');
end
end
% Delete waitbar
delete(wb)
% Plot last set of generated images
if plot == 1
figure(1)
imagesc(Frame1.L)
colormap(gray)
figure(2)
imagesc(Frame2.L)
colormap(gray)
figure(3)
imagesc(Frame1.R)
colormap(gray)
figure(4)
imagesc(Frame2.R)
colormap(gray)
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment