Skip to content

Running the step

Goal

Run the otsu step in a Python virtual environment.

Step 1 - Configure the workspace

The results produced will be available in the local folder /workspace/runs

terminal
1
2
3
4
export WORKSPACE=/workspace/app-package-training-bids23
export RUNTIME=/workspace/runs
mkdir -p ${RUNTIME}
cd ${RUNTIME}
source /workspace/app-package-training-bids23/scripts/setup.sh

Step 2 - Create the Python virtual environment

The required Python modules are installed using pip:

terminal
1
2
3
python -m venv env_otsu
source env_otsu/bin/activate
pip install --no-cache-dir rasterio scikit-image click loguru
source ${WORKSPACE}/scripts/otsu_env.sh

Step 3 - Calculate the ostu threshold

The command line tool is invoked to calculate Otsu threshold against the normalized difference:

terminal
1
2
3
4
5
6
7
8
export WORKSPACE=/workspace/app-package-training-bids23
export RUNTIME=/workspace/runs
mkdir -p ${RUNTIME}
cd ${RUNTIME}

python \
    ${WORKSPACE}/water-bodies/command-line-tools/otsu/app.py \
    norm_diff.tif
source ${WORKSPACE}/scripts/otsu.sh

Step 4 - Clean-up

The Python virtual environment is no longer needed.

terminal
1
2
deactivate
rm -fr env_otsu
source ${WORKSPACE}/scripts/otsu_deactivate.sh

Expected outcome

The folder /workspace/runs contains:

(base) jovyan@coder-mrossi:~/runs$ tree .
.
├── crop_green.tif
├── crop_nir.tif
├── norm_diff.tif
└── otsu.tif

0 directories, 4 files