Skip to content

Ostu threshold

Goal

Create a container and run the otsu step in the container image tagged localhost/otsu:latest.

Lab

This step has a dedicated lab available at /workspace/mastering-app-package/practice-labs/Containers/otsu.ipynb

Container

Each step has its own recipe to build the container image.

The otsu step container image recipe is:

otsu/Dockerfile
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
FROM docker.io/library/python:3.11-slim@sha256:91e9d01cf4bd56be7128c603506b6fe367ef7506f9f2ad8f3a908aeec8941bb9

# System deps needed by rasterio wheels
RUN apt-get update && \
    apt-get install -y --no-install-recommends libexpat1 && \
    rm -rf /var/lib/apt/lists/*

RUN pip install --no-cache-dir "rasterio==1.4.3" "scikit-image==0.25.2" "click==8.2.1" "loguru==0.7.3" && \
    python -c "import rasterio"

ADD app.py /app/app.py

ENTRYPOINT []

Build the container image with:

terminal
1
2
3
export WORKSPACE=/workspace/mastering-app-package

podman build --format docker -t localhost/otsu:latest ${WORKSPACE}/water-bodies/command-line-tools/otsu

Run the container

The command to run the otsu step in the container is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
podman \
    run \
    -i \
    --userns=keep-id \
    --mount=type=bind,source=/workspace/mastering-app-package/runs,target=/runs \
    --mount=type=bind,source=/workspace/mastering-app-package/runs/norm_diff.tif,target=/inputs/norm_diff.tif,readonly \
    --workdir=/runs \
    --read-only=true \
    --user=1001:100 \
    --rm \
    --env=HOME=/runs \
    --env=PYTHONPATH=/app \
    localhost/otsu:latest \
    python \
    -m \
    app \
    /inputs/norm_diff.tif

Step

Run the command to run the otsu step with:

sh -x ${WORKSPACE}/scripts/podman-otsu.sh

Expected outcome

The folder /workspace/mastering-app-package/runs contains:

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

0 directories, 4 files