Home (All Topics) → Technology → Software → AI-Created Software
Paint over part of a depth map and get a grayscale mask of everything at that depth: white at the painted depth, fading toward black the further a pixel’s depth is from it. Use it to isolate a subject for grading or compositing, build depth-of-field or fog passes, or cut a foreground element out of a color frame.

Python 3.8 or newer with Tk (included with the python.org installers; on Debian and Ubuntu, sudo apt install python3-tk):
pip install pillow numpy
python depth-map-reference-mask.py
Optional packages, each used only when installed:
opencv-python: EXR depth maps, and full precision for 16-bit color PNG and TIFF files (Pillow reads them at 8 bits). For EXR, install OpenCV 4 (pip install "opencv-python<5"): OpenCV 5.0 from pip has no EXR support.scipy: faster connected regions on large images.rawpy: camera RAW files as cutout photos.
Every control in the bottom panels has a tooltip. The status line shows what just happened; right-click it to copy the whole message, even when it is cut short. About (or F1) shows the version and links to the app’s page. The interface is drawn in neutral grays only, so nothing beside the images tints how you see them, and it follows the display scaling set in Windows or Linux.
The reference is the depth the mask centers on. All depth maths is on a 0–255 scale, whatever the file’s bit depth; a 16-bit source keeps its precision.
Spread shows how much depth varies under the paint (5th to 95th percentile). A large spread usually means the brush crossed an edge.
| Control | What it does |
|---|---|
| Plateau | A band either side of the reference that stays fully white. Fit to paint sets it to half the painted spread. |
| Near falloff, Far falloff | How far the fade reaches toward and away from camera before black. |
| Auto range | Sets both falloffs so the fade just reaches the ends of the image’s depth range, ignoring the outer 0.5 % at each end. |
| Brighter = nearer | Turn off for maps where larger values are further away, such as metric depth. |
| Curve | Linear, Smooth (no creases where the fade meets white and black), or Gamma (above 1 falls away faster). |
| Connected | Keeps only areas joined to the painted pixels through mask values at or above the threshold, which separates two objects at the same depth. |
The histogram shows how many pixels sit at each depth, on a log scale, with the mask curve (green), the reference (red, dashed when locked), the plateau (blue band) and the falloff ends (dashed blue).
Drag a line to change it; dragging a falloff end turns auto range off.
Input range decides which file values map onto 0 and 255: Format (0–255 for 8-bit files, 0–65535 for 16-bit, and for float files whichever of 0–1, 0–255 or 0–65535 fits), Stretch (the data’s 0.1–99.9 percentile range, for metric or disparity maps) or Custom. The Data readout shows the file’s own minimum and maximum.
NaN and infinite values (often the sky in EXR renders) show blue and are always black in the mask. When a file needs attention, a notes link appears in the status bar.
Save as writes into the folder you choose, asking first if that would replace any files; on Windows the picker suggests a new folder’s name. File names start with the cutout photo’s name and then the depth map’s. For IMG_0042.jpg and shot01.png:
| File | Contents |
|---|---|
IMG_0042_shot01_mask.png |
The mask, 8- or 16-bit as Bit depth says (Match writes 16-bit for a deeper source). |
IMG_0042_shot01_painted-area.png |
The painted area. |
IMG_0042_shot01_cutout.png |
With RGBA cutout on: the photo (or the depth map) with the mask as alpha, 8-bit sRGB. |
IMG_0042_shot01.json |
The project: every setting, the reference used, and paint statistics. |
shot01.png, IMG_0042.jpg |
The depth map and photo, as a link where possible, otherwise a copy. |
Save replaces its own files without asking. Files are written to temporary names and flushed to the disk before they replace the old ones, so a failed save, or a power cut just after one, leaves the previous results intact. Opening another depth map, loading a project or closing the window offers to save unsaved work first.
Load project restores the depth map, cutout photo, painted area and every setting. It looks for the files beside the project first, so a saved folder can be moved or copied. After loading, the app compares its result with the saved mask, and shows the project as saved only if they match. Projects from older versions still open, with the Mean estimator.
Apply a saved project to a sequence of frames without opening the window:
python depth-map-reference-mask.py --project-file-or-folder-path shot01.json --frames-file-or-folder-path "frames/*.png" --output-folder-path masks/ --rgba TRUE --color-folder-path color/
Each frame’s reference is re-estimated from the project’s painted area, so it follows a subject whose depth drifts; auto range, Stretch and connected regions are worked out per frame too. The frames value is a file, a folder, or a wildcard pattern (*, ?, [0-4]), which the app expands itself, so put it in quotes. Files the app wrote are skipped, so the output can go beside the frames. Each run writes batch.json, recording the reference and falloffs used for every frame. The exit code is 0 when every frame was written or skipped, 1 if any failed. Batch mode doesn’t need Tk.
The window’s place, last-used folders and view choices are kept in depth-map-reference-mask.ini in the working folder, beside the launcher unless --working-folder-path names another.
Mask settings belong to projects, not to this file.
Every option is --name VALUE (or --name=VALUE), in any order; yes/no options take TRUE or FALSE. An option left out is blank.--help lists them all.
| Option | Effect |
|---|---|
--working-folder-path FOLDER |
The folder for settings and temporary files. Blank: the launcher’s folder. |
--project-file-or-folder-path PROJECT |
A project’s .json file, or a folder holding only that project. Opened in the window, or applied in batch mode. |
--frames-file-or-folder-path FRAMES |
Runs batch mode on these depth frames: a file, a folder or a wildcard pattern. |
--output-folder-path FOLDER |
Batch mode: where to write. Blank: <project name>_batch beside the first frame. |
--rgba TRUE |
Batch mode: also write RGBA cutouts. Blank: no. |
--color-folder-path FOLDER |
Batch mode: color frames for the cutouts, matched by file name. Blank: the cutouts use the depth map. |
--fixed-reference TRUE |
Batch mode: use the project’s saved reference for every frame. Blank: re-estimate it. |
--bit-depth match |
Batch mode: match, 8 or 16-bit masks. Blank: the project’s choice. |
--overwrite TRUE |
Batch mode: replace existing results. Blank: skip frames that have one. |
A mistake (an unknown option, a missing value, a batch option without frames) stops with a message and exit code 2.
| Key | Action |
|---|---|
| Left drag / right drag | Paint / erase |
| Alt-click, or I then click | Pick the reference under the brush (Esc cancels) |
| [** and **] | Brush size |
| \ | Toggle the mask overlay |
| Middle drag, Space + drag | Pan (left drag pans the result pane) |
| Ctrl + mouse wheel | Zoom at the cursor |
| Ctrl+0 / Ctrl+1 | Fit / 100 % |
| Ctrl+Z / Ctrl+Y or Ctrl+Shift+Z | Undo / redo (painting, erasing and clearing) |
| Ctrl+S / Ctrl+Shift+S / Ctrl+O | Save / Save as / Open depth map |
| F1 | About |
On macOS, Cmd works for Ctrl and Option for Alt. Shortcuts wait while you type in a field or a dialog is open.
pip install "opencv-python<5".
Version 1.0.0, updated 2026-11-16. infolific.com: https://infolific.com/technology/software-worth-using/ai-created/photo-utilities/depth-map-reference-mask/

