STEM4D Poisson denoising project
Author: Willem.Marais@ssec.wisc.edu
1. Matlab software
1.1 Convert tiff files into Matlab files
Edit the file stem4d/matlab/utilities/convert_tiff_to_matf.m
. This Matlab script converts the tiff files into Matlab mat files, where each Matlab mat file consists of the four diffraction images per image block (e.g. im0).
There are several variables that have to bet set:
- Set the variable
home_dirP_str
to your home directory. - Set the path of the directory of
export_fig
. - The variables
in_dirP_str
,out_dirP_str
andout_preview_dirP_str
are the locations where the tiff images resides, and where the output files should be written to.
1.2 How to create diagnostic images
The following code shows the create an image of image blocks:
%% Setup the path to point to the directories where the Matlab functions are
home_dirP_str = getenv ('HOME');
% Set the directory path of the code
proj_dirP_str = fullfile (home_dirP_str, 'ProjectsSSEC/GitLab/stem4d/matlab');
% Set the path if it is not already set
path (path, fullfile (proj_dirP_str, 'reader'));
path (path, fullfile (proj_dirP_str, 'plots'));
%% Read the image blocks im0, im1, im2, im40, im41, im42, im80, im81, im82
input_dirP_str = '/home/willemm/ProjectsSSEC/BeccaSTEM4D/sto_40nm_7_thickness_cbed_tif/matf/10nm';
fileN_format_str = 'sto_12_12_40nm_im%d_cbed.mat';
startB_nr_int = 0;
endB_nr_int = 82;
strideH_int = 1;
strideV_int = 40;
data_ca = readblocks (input_dirP_str, fileN_format_str, startB_nr_int, endB_nr_int, strideH_int, strideV_int);
%% Display the diffraction images
display_data_ca (data_ca);
2. Python software
2.1. Software requirements
The Python scripts have only been tested on a Python version 2.7 interpreter. The following Python packages are required:
- matplotlib
- scipy
- numpy
2.2 How to create diagnostic images
2.2.1 First convert tiff files into Matlab files
First edit the file stem4d/matlab/utilities/convert_tiff_to_matf.m
. This Matlab script converts the tiff files into Matlab mat files, where each Matlab mat file consists of the four diffraction images per image block (e.g. im0).
There are several variables that have to bet set:
- Set the variable
home_dirP_str
to your home directory. - Set the path of the directory of
export_fig
. - The variables
in_dirP_str
,out_dirP_str
andout_preview_dirP_str
are the locations where the tiff images resides, and where the output files should be written to.
2.2.2 Next create concatenated image blocks
The Python file stem4d/python/utilities/diagnostics_horz_vert.py
create concatenated image blocks (e.g. im0, im1, etc.) where the image blocks are either concatenated horizontally or vertically. For example, the following command stack image blocks im0, im40, im80, im120, im160, im200, im240, im280, im320, im360 on top of each other:
export SCRIPT_DIR=$HOME/ProjectsSSEC/GitLab/stem4d/python/utilities
export SOURCE_DIR=$HOME/ProjectsSSEC/BeccaSTEM4D/sto_40nm_7_thickness_cbed_tif_correct/matf/10nm
export OUTPUT_FILE=$HOME/ProjectsSSEC/sto_12_12_40nm_im0_im40_cbed.pdf
export IMG_LIST="im0 im40 im80 im120 im160 im200 im240 im280 im320 im360"
python $SCRIPT_DIR/diagnostics_horz_vert.py $SOURCE_DIR 'sto_12_12_40nm_{:s}_cbed.mat' $OUTPUT_FILE vertical $IMG_LIST
And the following command stack image blocks im0, im1, im2, ..., im39 next to each other:
export SCRIPT_DIR=$HOME/ProjectsSSEC/GitLab/stem4d/python/utilities
export SOURCE_DIR=$HOME/ProjectsSSEC/BeccaSTEM4D/s9_100nm_sto_4uc_12ucModel_dz_5nm_0p0_0_tilt/matf/10nm
export OUTPUT_FILE=$HOME/ProjectsSSEC/BeccaSTEM4D/s9_100nm_sto_4uc_12ucModel_dz_5nm_0p0_0_tilt/s9_100nm_sto_4uc_12ucModel_dz_5nm_0p0_0_tilt_im0_im39_cbed.pdf
export IMG_LIST="im000 im001 im002 im003 im004 im005 im006 im007 im008 im009 im010 im011 im012 im013 im014 im015 im016 im017 im018 im019 im020 im021 im022 im023 im024 im025 im026 im027 im028 im029 im030 im031 im032 im033 im034 im035 im036 im037 im038 im039"
python $SCRIPT_DIR/diagnostics_horz_vert.py $SOURCE_DIR 's9_0_0_tilt_{:s}_cbed.mat' $OUTPUT_FILE horizontal $IMG_LIST
2.2.3 Create image of unit cell
The Python file stem4d/python/utilities/diagnostics_unit_cell_area.py
creates an image of the upper left unit cell:
export SCRIPT_DIR=$HOME/ProjectsSSEC/GitLab/stem4d/python/utilities
export SOURCE_DIR=$HOME/ProjectsSSEC/BeccaSTEM4D/sto_40nm_7_thickness_cbed_tif_correct/matf/10nm
export OUTPUT_FILE=$HOME/ProjectsSSEC/sto_12_12_40nm_im0_im369_cbed.pdf
python $SCRIPT_DIR/diagnostics_unit_cell_area.py $SOURCE_DIR 'sto_12_12_40nm_im{:d}_cbed.mat' $OUTPUT_FILE 1 40
3. Developer notes
- For some reason I cannot properly read the tiff files using Python. With Matlab I can select one of the three layers in the tiff files. But Python only shows two layers.
- I have to make the script
stem4d/matlab/utilities/convert_tiff_to_matf.m
more automated.