Demo: Training data generation for combined denoising and upsamling of synthetic 3D data

This notebook demonstrates training data generation for a combined denoising and upsampling task of synthetic 3D data, where corresponding pairs of isotropic low and high quality stacks can be acquired. Anisotropic distortions along the Z axis will be simulated for the low quality stack, such that a CARE model trained on this data can be applied to images with anisotropic resolution along Z.

We will use only a few synthetically generated stacks for training data generation, whereas in your application you should aim to use stacks from different developmental timepoints to ensure a well trained model.

More documentation is available at http://csbdeep.bioimagecomputing.com/doc/.

In [1]:
from __future__ import print_function, unicode_literals, absolute_import, division
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format = 'retina'

from tifffile import imread
from csbdeep.utils import download_and_extract_zip_file, plot_some, axes_dict
from csbdeep.io import save_training_data
from csbdeep.data import RawData, create_patches
from csbdeep.data.transform import anisotropic_distortions

Download example data

First we download some example data, consisting of a synthetic 3D stacks with membrane-like structures.

In [2]:
download_and_extract_zip_file (
    url       = 'http://csbdeep.bioimagecomputing.com/example_data/synthetic_upsampling.zip',
    targetdir = 'data',
)
Files missing, downloading... extracting... done.

data:
- synthetic_upsampling
- synthetic_upsampling/test_stacks_sub_4
- synthetic_upsampling/test_stacks_sub_4/stack_low_sub_4_03.tif
- synthetic_upsampling/training_stacks
- synthetic_upsampling/training_stacks/high
- synthetic_upsampling/training_stacks/high/stack_01.tif
- synthetic_upsampling/training_stacks/high/stack_02.tif
- synthetic_upsampling/training_stacks/high/stack_00.tif
- synthetic_upsampling/training_stacks/low
- synthetic_upsampling/training_stacks/low/stack_01.tif
- synthetic_upsampling/training_stacks/low/stack_02.tif
- synthetic_upsampling/training_stacks/low/stack_00.tif

We plot XY and XZ slices of a training stack pair:

In [3]:
y = imread('data/synthetic_upsampling/training_stacks/high/stack_00.tif')
x = imread('data/synthetic_upsampling/training_stacks/low/stack_00.tif')
print('image size =', x.shape)

plt.figure(figsize=(16,15))
plot_some(np.stack([x[5],y[5]]),
          title_list=[['XY slice (low)','XY slice (high)']],
          pmin=2,pmax=99.8);

plt.figure(figsize=(16,15))
plot_some(np.stack([np.moveaxis(x,1,0)[50],np.moveaxis(y,1,0)[50]]),
          title_list=[['XZ slice (low)','XZ slice (high)']],
          pmin=2,pmax=99.8);
image size = (128, 512, 512)