RapidRAW Logo RapidRAW
Verified in v1.6.8
Documentation Menu

AI & Masks

A hotel selected with a Subject mask, a mountain sky selected with a Sky mask, and a wind turbine split before and after AI Remove

All AI features in RapidRAW run locally with ONNX Runtime, except the optional generative Replace through RapidRAW Cloud or your own AI Connector server. Models are downloaded the first time a feature needs them.

Runtime

  • ONNX Runtime 1.22, bundled with the app.
  • GPU acceleration: DirectML on Windows (the high-performance GPU is chosen), Core ML on macOS. Linux runs the models on the CPU.
  • If a model fails on the GPU, RapidRAW logs it, switches all AI models to the CPU for the rest of the session and continues. Changing the AI GPU setting resets this.
  • Models come from the RapidRAW-Models repository on Hugging Face. Each file is checked against a fixed SHA-256 hash after downloading, and re-downloaded if it doesn't match. Downloads are written to a temporary file first, so an interrupted download never leaves a broken model.
Feature Model Input size Runs on
Subject mask, Quick Eraser Segment Anything (SAM ViT-B) 1024 CPU
Foreground mask BiRefNet (general, lite) 1024 GPU when possible
Sky, text prompt, face detection EfficientSAM3 1008 GPU when possible
Face parts MediaPipe Face Landmarker and Selfie Multiclass 256 CPU
Depth mask, Lens Blur, Fog, Motion Blur depth (in masks) Depth Anything V2 (small) 518 GPU
Relight MoGe-2 normals (small) up to 768 GPU when possible
AI Denoise NIND UTNet 504 tiles GPU
AI Remove LaMa (fp16) up to 768x768 CPU
Auto tagging CLIP 224 GPU when possible

On macOS, only Depth Anything and AI Denoise use Core ML; the other models run on the CPU there.

What the models see

Mask models look at the unedited, geometry-corrected image: your lens correction and transform are applied, but not your color and tone edits. So a mask doesn't change when you edit the photo, and it's recalculated when you change the geometry. Crop, rotation and flips are stored with the mask and applied when it's drawn, so cropping never needs a new mask.

Each AI result is stamped with a source id: a hash of the file size and its first and last 64 KB. If the file changes, the result is marked stale and regenerated in the background. Renaming or moving the file keeps it valid.

Background jobs

When you paste settings, apply a preset or sync edits to photos that aren't open, the AI parts (masks, AI Denoise, depth and normal maps) are queued and generated in the background. The photo open in the editor always goes first. The queue survives a restart, and failed jobs are retried up to three times. Exports wait for any missing AI results of the photos being exported.

Subject mask (Segment Anything)

  1. The image is scaled so the long side is 1024 px, and SAM computes an image embedding. This happens when you choose the Subject tool, so the actual selection is fast.
  2. Your box is passed as two corner points (or a click as one foreground point).
  3. Second pass: RapidRAW takes the first result and adds more hints automatically: the point deepest inside the mask as an extra foreground point, the largest hole inside the bounding box as a background point, the mask's bounding box, and the first mask itself as a prior. SAM then runs again. This fixes most missing parts and holes.
  4. Edge refinement: the mask is upscaled to full resolution and refined with a guided filter using the photo's luminance (radius 0.75% of the long edge, 8 to 24 px). This makes the edge follow hair and fine outlines.

A box is more accurate than a click because it tells the model both what the subject is and how big it is.

Subject mask being created by dragging a box around a hotel building
Dragging a box for a Subject mask.

Foreground mask (BiRefNet)

BiRefNet finds the main subject without any input. It runs at 1024x1024. If the subject is small (less than 60% of the frame), RapidRAW runs it a second time on a zoomed-in crop around the subject, and blends that sharper result in with soft edges if it agrees with the first one.

Sky, text prompt and face detection (EfficientSAM3)

EfficientSAM3 is a promptable segmentation model. RapidRAW uses it in three ways:

  • Sky: a stored "sky" prompt. Matches above a score of 0.6 are combined, then refined at full resolution with a color guided filter (radius 16), so the edge follows trees and buildings.
  • Text prompt (for example "red car" or "dog"): your text is tokenized with the CLIP tokenizer (up to 16 tokens) and encoded. Results above a score of 0.3 are used, with the same refinement and a zoomed second pass for small objects.
  • Faces: a stored "face" prompt returns face boxes for the Face mask.
Sky mask on a mountain photo, the sky shown in red and following the ridge line
A Sky mask. The guided-filter refinement makes the edge follow the rocks and snow.

Face parts

For each face box:

  1. Landmarks: MediaPipe Face Landmarker finds 478 points (including the irises). The face is straightened using the eye corners and the fit is repeated up to four times. Each box is tried in four orientations, so sideways faces work.
  2. Segmentation: a selfie segmentation model finds hair, face skin and body skin.
  3. Parts:
Part How it's built
Eyebrows, Lips, Nose Polygons from the landmarks
Eye whites Eye shape minus the iris
Iris Circle from the iris landmarks, clipped by the eye
Teeth Inside the lips, pixels brighter and less saturated than the lips
Hair Segmentation model
Face skin Segmentation inside the face outline, minus eyes, brows and lips
Body skin Segmentation of the whole image

Every part is refined with a color guided filter, so edges are soft but follow the real outline.

Depth mask

Depth Anything V2 estimates relative depth (bright = near) at 518 px, normalized from 0 to 100 for each photo. The mask uses the range sliders:

mask = smoothstep(min − minFade, min, d) · (1 − smoothstep(max, max + maxFade, d)) · d/100

The last term means nearer areas get a slightly stronger mask.

Depth mask selecting the foreground of a landscape
Depth mask set to the near part of the scene.

3D depth view

The Depth mask panel shows the depth map as an interactive point cloud, drawn with WebGL2. The backend sends a small preview (192 px on the long side) of the photo and its depth map, and the view shows it in the photo's orientation. Each preview pixel becomes one point, placed at its estimated distance and colored with the photo.

The shader uses the same band as the mask: smoothstep(min − minFade, min, d) · (1 − smoothstep(max, max + maxFade, d)). Points inside the band keep their color; points outside are drawn as dark grey (30% of their luma) at 40% opacity. The near, far and fade planes are drawn at their depths and can be dragged. A click picks the point under the cursor and centers the band on its depth, keeping the band's width. Dragging a plane writes the same minDepth, maxDepth, minFade and maxFade values as the range bar, so both always agree.

Manual masks

  • Brush: each stroke is drawn as a smooth capsule (no stamped dabs). Inside radius · (1 − feather) it's 100%, then it falls off with a smoothstep. Strokes are combined like layers of light: a + b − a·b.
  • Flow brush: each stroke adds flow percent, so overlapping strokes build up: after n strokes, 1 − (1 − flow)^n.
  • Radial: a linear falloff from the inner ellipse (set by feather) to the outer ellipse.
  • Linear: a linear ramp across the gradient width, 50% on the center line.
  • Color range: RGB distance to the picked color, with tolerance T: full at the color, zero at distance √3·T.
  • Luminance range: luma distance to the picked brightness, zero at distance T.

The color and luminance pickers sample the unedited image, so the selection doesn't move while you edit.

Grow dilates or erodes by up to 1% of the short side; Feather blurs with a Gaussian of up to 0.5% of the short side.

Match Brush

The Match Brush paints a brush mask, but each pixel is weighted by how similar it is to the area under the brush center. Like the AI masks, it works on the unedited, geometry-corrected photo.

1. Features. The photo is box-averaged down to at most 2048 px on the long side (cached until the photo changes). Each pixel gets four values:

Feature How it's computed
Lightness OKLab L, 3x3 box average
Color OKLab a and b, 3x3 box average, weighted 1.5
Texture Standard deviation of L in a 5x5 window, weighted 2

OKLab is computed from the linear average of each block, so it measures color the way you see it. The texture feature is what lets the brush separate a smooth sky from leaves of the same color.

2. Reference per dab. Along the stroke, a dab is placed every 25% of the brush radius. For each dab, the reference is a weighted average of the features in a small core around the center (10% of the brush radius, 1 to 12 px at analysis size). Core pixels that differ from the center pixel get almost no weight (Gaussian with σ = 0.04), so an edge passing near the center doesn't pull the reference toward the wrong side. Because every dab has its own reference, the brush follows gradual changes, such as a sky that darkens toward the top.

3. Similarity. Tolerance t (1 to 100, as 0.01 to 1) sets the base width:

σ           = 0.015 + 0.35 · t²
inverse_c   = 1 / (σ² + min(2 · variance_c, 3 · σ²))
d²          = Σ_c (feature_c − reference_c)² · inverse_c
similarity  = max(0, 1 − d² / 6.25)³

variance_c is the spread of each feature inside the core. A busy reference area (foliage, gravel) therefore accepts more variation, up to twice σ, while a smooth one (clear sky) stays strict. The similarity falls to zero at d = 2.5. At the default Tolerance of 30, σ is about 0.047.

4. Strokes. Inside one stroke, each pixel takes the highest falloff · similarity of all dabs, with the same smoothstep feather as the normal brush. Strokes are combined like the normal brush: painting adds a + b − a·b, erasing multiplies by 1 − b. The eraser uses the same similarity, so it only removes matching pixels.

5. Edge refinement. The selection is refined with a color guided filter (radius 2 px, ε = 0.001) at the analysis size, using the photo as the guide. The filter's linear coefficients are then upsampled bilinearly and applied to the full-resolution colors, so the edge is computed at full resolution no matter how large the photo is. This is why the edge snaps to hair-thin branches even though the matching runs at 2048 px.

Combining masks

Inside a mask, each component is combined with the result so far, in order:

Mode Operation
Add max(a, b)
Subtract max(a − b, 0)
Intersect min(a, b)

Invert and opacity are applied per component and again for the whole mask. Subtract and Intersect need a component above them to work on.

How masks affect adjustments is explained in Tone & Color → Masks.

AI Denoise

Model: NIND UTNet, a U-Net trained on the Natural Image Noise Dataset (real camera noise at different ISOs).

  1. The image is processed in 504 px tiles. The outer 12 px of each tile are discarded, and neighbouring tiles overlap by 64 px with a smooth blend, so there are no visible seams. Edges are mirrored.
  2. Highlights above 1.0 (which the network can't represent) are passed through unchanged, so highlight detail and HDR headroom are kept.
  3. Low-frequency restore: the difference between input and output is averaged over 64 px blocks and added back. So the network can only remove fine noise; it can't shift colors or brightness over larger areas.
  4. The result is stored in a disk cache (half precision, up to 10 GB by default) and in memory.

Amount and Detail are applied live without running the model again:

removed     = original − denoised
luma part   = Rec.709 luma of removed
output      = denoised + (1 − amount)·(removed − luma part) + (1 − amount·(1 − detail))·luma part

So Detail only brings back luminance grain, never color noise. That's why it looks natural even at high values.

AI Denoise works best on RAW files, because the model sees the linear sensor data before any processing. On JPEGs the noise has already been changed by the camera's processing.

Classic denoise (BM3D)

The non-AI option uses BM3D:

  • similar 8x8 blocks within a 19x19 search window are grouped (up to 16);
  • each group is transformed with a 2D DCT plus a Walsh–Hadamard transform across the group;
  • small coefficients are removed in a hard-threshold pass, then a Wiener-filter pass refines the result.

It works in YCbCr with stronger filtering on chroma. A little fine luma detail is added back at the end. It's slower and softer than AI Denoise but needs no model download.

Night scene: no noise reduction, classic sliders, AI Denoise
No noise reduction, the Luminance and Color sliders, and AI Denoise on a high-ISO RAW.

AI Remove and retouching

All retouching tools create a patch: a small image plus a mask, stored in the edit and blended into the photo before geometry and all adjustments. So you can still change everything else afterwards. RAW files are retouched in sRGB and converted back to linear when the patch is applied.

AI Remove (LaMa):

  1. A crop around the mask is taken, with at least 128 px (or 1.5x the object size) of context.
  2. It's scaled down to fit 768x768 if needed and filled by LaMa on the CPU.
  3. If it was scaled down, the result is upscaled with bicubic interpolation, and real full-resolution texture is added back: PatchMatch (7x7 patches, 6 iterations) finds where each filled pixel's content best matches the surrounding photo, and copies the fine grain and detail from there. This prevents the smooth, plastic look of upscaled inpainting.
A wind turbine in front of a cloudy mountain: the original, the same photo with the turbine removed, and close-ups of both showing the filled area
AI Remove on a 24-megapixel photo with the built-in model. The fill is computed at a lower resolution, and PatchMatch adds back real full-resolution texture, so the close-up doesn't look smooth or plastic.

Generative Replace sends a crop (up to 1.5 megapixels) and the mask to RapidRAW Cloud, or the source and mask to your own AI Connector server. Only the masked area of the result is used.

Brush strokes for Clone, Heal, Liquify and Retouch are stored in the coordinates of the displayed image (after rotation and flips, before the crop). Before a patch is computed, the strokes are mapped back into the original image orientation through the inverse geometry transform. So a patch stays on the same spot when you change the crop or rotation later. The source image for a patch is the photo with all other patches applied, so patches can build on each other.

Each stroke is its own spot, with its own source offset. When you haven't placed the source yourself, RapidRAW searches for one:

  1. Search area. The search radius is 3x the spot size (the larger side of its bounding box), but at least 6% of the image's short side. It runs inside the visible crop first, and on the whole image only if nothing fits there.
  2. Coarse grid. The window around the spot is box-averaged so the spot is about 32 cells across (or the search radius about 96 cells, whichever needs the coarser grid). Every offset inside the circle is tested.
  3. Border band. RapidRAW compares the pixels around the spot, not the spot itself (that's the part you want gone). A band around the stroke, 25% of the spot size wide (2 to 16 cells), is compared with the band around the candidate source. Pixels close to the stroke count more.
  4. Cost. Each offset gets a cost (see below). Offsets where the source would overlap or touch the spot itself, or reach outside the search area, are skipped.
  5. Alternatives. The candidates are sorted by cost. Find Another Source takes the next one that is at least half the spot size away from all better ones, so each click gives a clearly different place. When there are no more, it cycles through the ones it found again.
  6. Refinement. The best coarse offset is refined at full resolution within ±1 cell, using the same cost on the real pixels.

The cost of an offset has three parts:

  • Band match: the weighted absolute color difference between the two bands, squared. For Heal, 75% of the average color difference is subtracted first, because Heal corrects the tone anyway. Clone has to match exactly.
  • Texture match: plus 0.1 x the difference in variance between the destination band and the source band, and between the destination band and the source interior. This rejects flat sources for textured areas, and busy sources for smooth ones.
  • Distance: the sum is multiplied by 1 + 0.3 · distance / radius, a small preference for nearby sources.

When you drag the source outline, the offset is simply your new position, and no search runs.

Clone and Heal: blending

Clone copies pixels with a whole-pixel offset (no resampling, so no softening). The feathered brush edge blends it in.

Heal copies the source and adds a smooth correction, so the tone matches the destination while the texture comes from the source. The correction is the difference destination − source, known on a 1 px ring around the spot and solved inside it with the Laplace equation (Poisson blending). This gives the smoothest possible correction that matches the border exactly.

To solve it quickly and evenly even for large spots, RapidRAW uses a multigrid scheme:

  1. The spot is halved repeatedly (up to 12 levels) until it has at most 256 unknown pixels. Each coarse pixel averages the difference of the pixels it covers.
  2. The coarsest level starts from the mean of its border and is solved with red-black successive over-relaxation (ω = 1.85, up to 2000 iterations).
  3. Each finer level starts from a bilinear upsampling of the coarser solution, then runs 80 iterations (150 at full resolution) with ω = 1.9. Every level stops early once no pixel changes by more than 0.01.

The coarse levels fix the large-scale tone, the fine levels only correct details. A single-level solver with a fixed number of iterations converges too slowly on large spots and leaves the middle unfinished. With multigrid, a long wire or a large blemish blends as evenly as a small dust spot.

Liquify

All strokes of one Liquify edit are combined into one displacement field:

  1. Dabs. Each stroke is turned into dabs every 15% of the brush radius. A single click is one dab with a larger step.
  2. Grid. The field is stored on a grid with a spacing of 1/6 of the smallest brush radius (1 to 4 px).
  3. Composition. Each dab computes its own small displacement (push: along the stroke at 0.6 x the stroke step; pinch and expand: toward or away from the center; twirl: a rotation). The falloff is a squared raised cosine, (0.5 · (1 + cos(π·t)))², flat inside the feathered core. The dab is then composed with the field built so far: the new displacement is the dab's offset plus the old field sampled at the displaced position. So a second stroke moves the already-warped pixels instead of adding vectors, and overlapping strokes behave like one continuous drag.
  4. Erase strokes use a reconstruct mode that shrinks the existing displacement toward zero under the brush.
  5. Twirl direction is flipped when the photo is mirrored, so it keeps turning the way you painted it.
  6. The photo is sampled once through the final field with bicubic (Catmull-Rom) interpolation. Only one resampling happens, however many strokes you paint, so the result stays sharp.

Pressure scales every dab, and Liquify Mode applies to all non-erase strokes of the edit.

Skin retouch: frequency separation

Retouch splits each color channel of the brushed area into two layers:

  • Low frequency (tone and color): a Gaussian blur with σ = 0.15 x the smoothing radius (0.8 to 3 px);
  • High frequency (texture): the original minus the low layer.

Only the low layer is smoothed, with an edge-preserving guided filter (the layer guides itself). Its radius follows the brush size, brush radius · (0.03 + 0.08 · s) clamped to 2 to 48 px, and its ε is (0.008 + 0.032 · s)², where s is Intensity from 0 to 1. Then the texture is added back:

result = original + (smooth_low + texture · high − original) · amount
texture = 1 − 0.3 · s
amount  = 1 − (1 − s)³

So blotches and redness are evened out in the low layer, while pores stay in the high layer. At Intensity 40, about 78% of the effect is applied and 88% of the texture is kept. At 100, the full effect is applied and 70% of the texture is kept. The result is blended in with the feathered brush mask.

Auto tagging (CLIP)

CLIP compares the thumbnail (224 px) with about 590 built-in labels or your custom tags. Labels with a probability above 0.5% are kept, sorted, together with their parent categories (for example "woman" also adds "person"), up to the number of tags set in Settings. Up to two dominant color tags are added from a simple HSV analysis.

See also