TITLE: CODA (part 1): setting up environment and preparing sample dataset | HuBMAP | JHU-TMC
AUTHORS: Kyu Sang Han, Pei-Hsun Wu, Joel Sunshine, Sashank Reddy, Ashley Kiemen, Denis Wirtz

[DESCRIPTION]
CODA workflow part 1. setting up environment and preparing dataset

[STEPS]
SECTION: Software requirements
1. MATLAB MATLAB (mathworks.com)
Image processing toolbox Image Processing Toolbox - MATLAB (mathworks.com)
Deep learning toolbox Deep Learning Toolbox - MATLAB (mathworks.com)
MATLAB - Resnet50 model MATLAB resnet50 (mathworks.com)
SECTION: Software requirements
2. Aperio ImageScope Aperio ImageScope (leicabiosystems.com)
SECTION: Software requirements
3. FIJI ImageJ Fiji Downloads (imagej.net)
SECTION: Download Source code
4. Codes are available at the following GitHub: CODA Github Repository
SECTION: Download Sample dataset
5. Here, we discuss application to a sample dataset “lungs”,
containing 150 serial histological images. Download the sample dataset (serial
images and sample annotations) here: Lung Sample Dataset on Google Drive
SECTION: Download Sample dataset
6. Images are .ndpi format and were scanned at 20x
magnification (approximately 0.5 micron / pixel resolution), spaced 10 micron
apart. Save the images in a local drive folder (e.g. \\Users\Ashley\Documents\lungs).
SECTION: Download Sample dataset
7. Filenames for each image should be created such that tissue
sections are read consecutively by Matlab. Therefore, include zero-padding in
numerical indices.

CORRECT FILENAMES: lungs_001.ndpi, lungs_002.ndpi, ..., lungs_011.ndpi
INCORRECT FILENAMES (no zero padding): lungs_1.ndpi, lungs_2.ndpi, ..., lungs_11.ndpi
SECTION: Create downsampled copies of high-resolution images
8. The function create_downsampled_tif_images will create downsampled copies of the .ndpi files by directly loading each high-resolution images in tiles and down sampling it to the desired pixel
resolutions. 
SECTION: Create downsampled copies of high-resolution images
9. First, decide the resolution of the images you want to create. Here, we create images of 1 micron / pixel, 2 microns / pixel, and 10 micron / pixel resolution: 

ds=[1 2 10];
SECTION: Create downsampled copies of high-resolution images
10. Next, decide on the name of the output folders for each of the downsampled images you create. Here, we will save the images downsampled to 1 micron / pixel in a folder named “10x”, the images downsampled to 2 micron / pixel in a folder named “5x,” and the images downsampled to 10 micron / pixel in a folder named “1x.”

subfolders=["10x" "5x" "1x"];
SECTION: Create downsampled copies of high-resolution images
11. Finally, call the function: create_downsampled_tif_images(pth,ds,subfolders);
SECTION: Create downsampled copies of high-resolution images
12. Using this function, you will make two subfolders within the original folder containing the .ndpi images. One subfolder named “10x” containing the 20x images downsampled by a factor of 2. The other subfolder named “1x” containing the 20x images downsampled by a factor of 20. Most calculations will be performed on these tif images. Note: here we use 10x and 1x for example, but other resolutions could be created as
desired.

pth10x=[pth,'10x'];
pth1x=[pth,'1x'];
**Note: If this code fails due to memory constraints on your computer, try python Openslide.