Depth Map Reference Mask

← All AI-created software

This is AI-generated (aka vibe-coded) software. It is specific to my needs and my system and may not work for you or yours. Support is limited, but if you report a bug I'll certainly look into it. The code is provided in the zip file for you to review should you choose.
⬇️ Download Depth Map Reference Mask.zip1.6 MBLast Updated: November 27, 2026Python

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.

Main window of Depth Map Reference Mask with a depth map of a room, a figure painted, and its mask
On this page

Features

  • Paint the area to keep; the mask updates as soon as you release the mouse
  • Separate near and far falloffs, a fully white plateau, and linear, smooth or gamma fades
  • A depth histogram with draggable reference, plateau and falloff lines
  • 8- and 16-bit PNG, TIFF, JPEG and BMP depth maps, and EXR with OpenCV
  • 16-bit masks and RGBA cutouts of the matching color photo
  • Projects that save every setting and the painted area, and reopen exactly
  • Batch mode that applies a saved project to a sequence of frames without opening the window

Usage

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.

Making a mask

  1. Open depth map (Ctrl+O) and choose a depth map.
  2. Paint over the surface you want to keep with the left mouse button; erase with the right. The result appears on the right.
  3. Shape the fade in the Falloff shaping panel, or drag the lines on the histogram.
  4. Optionally Add cutout photo: the color photo of the same frame, at the same size, which gives the RGBA cutout its colors. It is converted to sRGB from its embedded profile and turned upright by its EXIF orientation, and the status line says how its colors were read.
  5. Save as (Ctrl+Shift+S) saves into a folder you choose; after that, Save (Ctrl+S) saves into it again.

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.

Reference

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.

  • Painted: estimated from the painted area by Median (the default, which ignores a brush that spills over an edge), Trimmed (the middle 80 % of painted depths) or Mean.
  • Locked: a fixed value. Type it, Alt-click the depth map, or press I and click; picking takes the median depth inside the brush circle.
    Dragging the reference line on the histogram also locks it.

Spread shows how much depth varies under the paint (5th to 95th percentile). A large spread usually means the brush crossed an edge.

Falloff

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.

Histogram and input range

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.

Saving

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.

Projects

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.

Batch mode

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.

Settings

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.

Command line

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.

Keyboard shortcuts

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.

Troubleshooting

  • The window doesn’t open, and the app says Tkinter is not available: install Tk for your Python. Batch mode works without it.
  • EXR files aren’t offered: install OpenCV 4, pip install "opencv-python<5".
  • The mask is almost all white or black, or the histogram is squeezed into a few bars: the map fills only part of its format’s range. Choose Stretch or Custom under Input range.
  • The mask reaches the wrong way: turn Brighter = nearer off.
  • Connected keeps too much: with auto range on, most of the image joins up through the background. Set the falloffs by hand, or raise the threshold.
  • The title says “Administrator”: the app was started with administrator rights, so everything it saves or replaces is done with them too. Close it and start it normally.
  • The taskbar shows a second button, or Python’s icon: a pin made before 2026-09-30 belongs to an old taskbar identity. Unpin it, start the app and pin it again.

Limitations

  • One reference depth per mask: two separate depth bands need two masks.
  • RGBA cutouts are always 8-bit; masks can be 16-bit.
  • Camera RAW photos are decoded with the camera’s white balance, not your darktable edit: for a matching cutout, export the frame from darktable as TIFF or PNG.
  • In batch mode, frames must be the same size as the painted area unless the reference is locked or fixed, and Stretch maps each frame separately, which can flicker across a sequence.
  • Undo history is capped at about 256 MB; zoom goes from 1 % to 3200 %.

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/

⬇️ Download Depth Map Reference Mask.zip1.6 MBLast Updated: November 27, 2026Python

← All AI-created software