AI-Created Software

The following AI-generated aka vibe-coded software. The software is specific to my needs and my system and may not work for you or your system. Support is limited, but if you report a bug I'll certainly look into it. All code is provided in a zip file for you to review should you choose.

Depth Map Reference Mask Tool

A small desktop app (Tkinter) for turning a depth map into a grayscale mask centred on a depth of your choosing.

You load a depth map, paint over the region you want to treat as the reference depth, and the tool produces an image where that depth is pure white and everything else fades toward black as it moves away from the reference — in either direction, whether it sits in front of or behind the reference.


Requirements

  • Python 3.8 or newer, with Tkinter available (bundled with most Python installs; on Debian/Ubuntu you may need sudo apt install python3-tk)
  • pillow
  • numpy
pip install pillow numpy

Running

python depth-map-reference-mask.py

How it works

  1. The loaded image is converted to 8-bit grayscale. Each pixel’s value (0–255) is its depth.

  2. The reference depth is the mean grayscale value of every pixel you painted.

  3. For each pixel the tool computes diff = |depth − reference|.

  4. That difference is divided by the falloff range, clamped to 0–1, and inverted:

    output = (1 − min(diff / falloff, 1)) × 255

So a pixel at exactly the reference depth is 255 (white), a pixel a full falloff range away is 0 (black), and anything beyond is clamped to black. The falloff is symmetric — depth 100 and depth 200 are equally distant from a reference of 150.

Auto falloff range (on by default) sets the falloff to the largest difference present in the image, so the output always uses the full 0–255 range. Turn it off to set the falloff manually with the slider (1–255), which gives you a tighter, more selective band around the reference.


Using the app

Toolbar

Control What it does
Load Depth Image… Opens a depth map (.png, .jpg, .jpeg, .tif, .tiff, .bmp, .exr)
Clear Painted Mask Wipes the painted region and the current result
Save Re-saves into the folder used last time; falls back to Save As… if nothing has been saved yet
Save As… Prompts for a parent folder and creates a new result folder inside it
Load Project Reopens a previously saved result from its sidecar .json
Actual Size / 2x / 0.5x / Fit to Window Zoom controls for both preview panes
Brush size 2–200 px, measured in display pixels
Auto falloff range Toggles automatic vs. manual falloff
Falloff Manual falloff value, 1–255 (enabled only when auto is off)

Painting

  • Left-click / drag — paint the reference area. A translucent red overlay shows what’s painted.
  • Right-click / drag — erase. (Middle-click is also bound to erase, since some macOS input devices send it for a secondary click.)
  • The circle following your cursor previews the brush footprint: teal when painting, red when erasing.
  • The result preview refreshes when you release the mouse button, and the reference depth is shown in the right-hand pane’s header.

Panes

The left pane shows the source image with your painted overlay; the right pane shows the generated result. Both scroll and share the same zoom level.


Output

Save As… asks for a parent folder, then creates a subfolder named after the source image. If a folder with that name already exists, it appends _01, _02, and so on rather than overwriting anything.

Inside that folder, using bedroom.png as an example source:

bedroom/
├── bedroom_with_reference_set.png   # the generated grayscale result
├── bedroom_mask.png                 # the painted mask on its own (white = painted)
├── bedroom.json                     # sidecar metadata (also the project file)
└── bedroom.png                      # symlink or hard link back to the source image

The source image is linked rather than copied. A symlink is tried first, then a hard link. Symlinks on Windows need Developer Mode or admin rights; hard links need the source and destination to be on the same volume. If both fail you get a warning, but the result files are still written. The result filename always carries the _with_reference_set suffix so it can’t collide with the linked source.

Sidecar JSON

Field Meaning
source_image Absolute path to the original depth map
linked_image_file Filename of the link created in the result folder
link_type symlink, hardlink, unchanged, or null if linking failed
image_width, image_height Source dimensions in pixels
reference_depth Mean depth under the painted mask (0–255)
auto_falloff_range Whether auto falloff was active
falloff_range The falloff value actually used
brush_size_px Brush size at save time
mask_file Filename of the saved mask
painted_pixel_count Number of painted pixels
painted_coverage_pct Painted pixels as a percentage of the image
painted_bounding_box x_min/y_min/x_max/y_max of the painted area, or null
generated_at ISO 8601 timestamp

Reopening a project

Load Project takes one of these .json files (or a folder containing one) and restores the source image, the painted mask, the brush size, and the falloff settings, then regenerates the preview. If the mask file is missing or its resolution doesn’t match the image, you get a warning and the remaining settings are applied anyway.

The heading above the result pane reads (unsaved) or (saved as <path>) so you can tell at a glance whether the preview matches what’s on disk.


Persisted app settings

The app writes depth-map-reference-mask.ini next to the script, storing the window geometry, whether the window was maximized, the last folder used for loading, and the last parent folder used for saving. Deleting the file just resets the app to its defaults.

Optional icon files

If you want a custom title-bar and taskbar icon, place these alongside the script:

depth_mask_app.ico
Resources/depth_mask_app_icon_16.png
Resources/depth_mask_app_icon_32.png
Resources/depth_mask_app_icon_64.png

All of it is optional. Missing or unreadable icons print a one-line note to the console and the app falls back to the default Tk icon.

On Windows the app also sets an explicit AppUserModelID (so the taskbar shows the app’s icon instead of python.exe’s) and marks itself DPI-aware (so “Actual Size” really is 1:1 under display scaling above 100%).


Notes and limitations

  • 8-bit depth only. Images are converted to mode L, so a 16-bit or 32-bit depth map is quantized to 256 levels on load. Fine banding in the output is usually this, not the falloff maths.
  • EXR files appear in the file dialog filter, but Pillow can’t read them without an OpenEXR plugin. Convert to 16-bit PNG or TIFF first.
  • Brush size is in display pixels. Painting at 0.5x zoom covers twice as many source pixels per stroke as painting at 1:1.
    Use “Actual Size” when you need precision.
  • The mask is hard-edged. Brush stamps aren’t anti-aliased, and any non-zero mask pixel counts toward the reference average equally.
  • No undo. Right-click erase is the way back; “Clear Painted Mask” starts over.
  • The module docstring says to run depth_mask_app.py; the actual filename is depth-map-reference-mask.py.
(1 votes, average: 5.00 out of 5)

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail.