Skip to content
Snippets Groups Projects

The NLPCA method for stem4d

The Non Local PCA (NLPCA) method [1] Matlab package was downloaded from http://josephsalmon.eu/code/index_codes.php. The NLPCA_stem4d method is just a wrapper of the NLPCA method tailored for the stem4d project.

Test script for NLPCA_stem4d method

The NLPCA_stem4d method is available in the Matlab script nlpca_stem4d_denoise.m. An example of how to execute the script nlpca_stem4d_denoise.m is available in the script test_nlpca_stem4d_denoise.m.

How to use NLPCA method with stem4d data

The following Matlab code shows how to read the stem4d tiff files of the simulated data and how to use it with the NLPCA_stem4d method.

clear all;
close all;

% Set paths to the appropriate directories
path (path, '/home/willemm/ProjectsSSEC/GitLab/stem4d/matlab/reader')
path (path, '/home/willemm/ProjectsSSEC/GitLab/stem4d/matlab/NLPCA_stem4d')
path (path, '/home/willemm/ProjectsSSEC/GitLab/stem4d/matlab/NLPCA_stem4d/functions')

% Load first chunk row from 4 by 4 unit cell data archive
input_dirP_str = '/home/willemm/ProjectsSSEC/BeccaSTEM4D/s9_100nm_sto_4uc_12ucModel_dz_5nm_0p0_0_tilt/tiff/10nm';
fileN_format_str = 's9_0_0_tilt_im%03d_cbed-%d-%d-2.tif';
startB_nr_int = 0;
endB_nr_int = 39;
strideH_int = 1;
strideV_int = 40;
data_ca = readchunks_tiffs (input_dirP_str, fileN_format_str, startB_nr_int, endB_nr_int, strideH_int, strideV_int);
% img_arr_ca are the first four diffraction image rows
img_arr_ca = stack_horz (data_ca);
clear data_ca;

% Create noisy observations; scale the simulation so that the peak intensity of each unit cell is 10
Y_arr_ca = cell (size (img_arr_ca));
for row_idx = 1:4
    Y_arr_ca{row_idx} = poissrnd (10 * img_arr_ca{row_idx} / 10^(-2.9801));
end

% The denoise data
dn_img_arr_ca = cell (size (img_arr_ca));
for row_idx = 1:4
    dn_img_arr_ca{row_idx} = nlpca_stem4d_denoise (Y_arr_ca{row_idx}, true);
end

% Compare the noisy and denoised diffraction images of image chunk 0 (i = 0, j = 1) 
dsp_arr = [Y_arr_ca{2}(:,:,1),dn_img_arr_ca{2}(:,:,1)];
imagesc (dsp_arr);
colorbar ();
axis image;
caxis ([0, 3]);

References

[1] Salmon, Joseph, et al. "Poisson noise reduction with non-local PCA." Journal of mathematical imaging and vision 48.2 (2014): 279-294.