Focus Peaking
Categories:
Focus Peaking: The Laplacian of Gaussian Method
Focus Mask and Focus Point controls are moved to the Settings View. Now, switch them on/off only within the image.
Note: To obtain the most optimal results in Focus Peak view (extract), it is recommended to extract the JPG file from the RAW file. While it is possible to view Focus Peek by creating thumbnails, the mask is more effective when applied to JPGs. To access Focus Peek, double-click on the image in main view. In the Settings menu, Thumbnails tab, disable the “Use Thumbnail for Zoom” to use JPGs as base for Focus Peak.
What Is Focus Peaking?
Focus peaking is a visual aid that highlights which areas of a photograph are in sharp focus. Rather than relying on your eye alone to judge sharpness, focus peaking overlays a red highlight on pixels where edge detail and contrast are strongest. Those highlighted pixels are the ones in sharpest focus — everything else stays unchanged.
The Focus Peak is computed by the GPU on your Mac, making it a fast process even when the mask is generated on the fly.

Why the Laplacian of Gaussian?
Several mathematical approaches can measure local sharpness, but the Laplacian of Gaussian (LoG) is one of the most effective for focus peaking because it combines two complementary operations.
The Gaussian blur is applied first, suppressing sensor noise and low-amplitude out-of-focus texture — water ripples, skin, smooth backgrounds — before sharpness detection runs. Without this step, the Laplacian would flag noise and soft texture as “sharp.”
The Laplacian then computes, for each pixel, how much its intensity differs from its immediate neighbours. In a blurry region those differences are small and smooth. At a sharply rendered edge they spike. The key insight is that the Laplacian measures second-order intensity change — it responds to genuine focus-induced contrast spikes rather than gradual gradients, which blurred regions produce even when they have visible texture.
The Kernel
Rather than the classic 4-neighbour approximation, RawCull uses a full 8-neighbour kernel computed on the GPU via Metal:
L = 8 × center − (N + S + E + W + NE + NW + SE + SW)
This 3×3 formulation is more isotropic than the 4-neighbour version — it responds equally to edges in all directions, including diagonals, which matters for natural subjects like feathers and fur.
The sharpness energy at each pixel is then computed as a luminance-weighted magnitude:
energy = |L.r| × 0.299 + |L.g| × 0.587 + |L.b| × 0.114
This preserves perceptual weighting — the green channel contributes most, matching human sensitivity to luminance detail.
Step-by-Step: How It Works
1. Downscale. The image is reduced to 1024 pixels wide before processing. The algorithm operates on pixel neighbourhoods, so full resolution is unnecessary and the performance gain is significant.
2. Pre-blur (Gaussian). A Gaussian blur is applied to the downscaled image. This suppresses out-of-focus texture and sensor noise before the Laplacian runs, preventing false highlights in blurred regions. The blur radius is adaptive: the base value set in the Focus Peak controls is scaled upward automatically — by up to 3× — based on the image’s ISO value (higher ISO → more noise → larger radius) and the image resolution (larger images → radius scaled by √(width/512) to maintain consistent edge selectivity). CIGaussianBlur accepts a maximum radius of 100; the effective radius is clamped to that limit.
3. Laplacian kernel (Metal GPU). The 8-neighbour kernel runs on every pixel in parallel on the GPU, computing the second-order derivative of brightness across all channels.
4. Energy and amplification. The per-pixel result is converted to a single luminance-weighted sharpness energy value and amplified. The amplification factor is user-adjustable.
5. Threshold. Any pixel below the threshold is discarded (black). Only genuinely sharp pixels survive. The threshold is the primary control — lower values highlight more of the image, higher values restrict highlights to only the sharpest edges.
6. Erosion. A morphological erosion pass removes isolated speckle pixels that survive the threshold but are too small to represent genuine edges. The erosion radius is quantised to the nearest whole pixel (a radius of 0 skips this pass). This cleans up the mask before it is expanded.
7. Dilation. Surviving pixels are expanded morphologically, turning scattered dots into solid readable regions without introducing false edges. The dilation radius is likewise quantised to whole pixels.
8. Border inset. The outer 4 % of each edge is zeroed out before the mask is composited. This matches the same inset used by the sharpness scorer and prevents Gaussian pre-blur edge artifacts — a thin blurry fringe that forms where the blur kernel reaches past the image border — from appearing as false focus highlights around the frame edge.
9. Red overlay. Surviving pixels are colourised red and composited over the original photograph using a screen blend mode. Black (non-sharp) areas are transparent in screen blending, so only the red sharpness regions show through over the photo.
10. Feather. A final Gaussian blur softens the edges of the red overlay, giving the mask a smooth, natural appearance rather than a hard pixelated boundary.
Tunable Parameters
RawCull exposes the following controls in the Focus Peak panel:
| Control | Effect |
|---|---|
| Pre-blur | Base Gaussian blur radius applied before edge detection. The effective radius is scaled automatically with the image’s ISO value and resolution — this control sets the baseline from which adaptive scaling is applied. Higher values suppress background texture and high-ISO noise more aggressively. |
| Threshold | Primary sharpness cutoff. Raise to restrict highlights to only the sharpest edges; lower to highlight more of the image. Default 0.46. |
| Erosion radius | Morphological erosion applied after thresholding. Removes isolated speckle noise before dilation. Quantised to whole pixels — set to 0 to skip. Default 1 px. |
| Dilation radius | Morphological expansion applied after erosion. Widens edge regions into solid, readable patches — increase for small or fine-detailed subjects. Quantised to whole pixels — set to 0 to skip. Default 1 px. |
| Amplify | Multiplier applied to the raw sharpness signal. Higher values make weak edges more visible; too high reintroduces noise. |
| Feather | Gaussian softening applied to the final mask edges. Visual only — does not affect the underlying score. |
| Show raw Laplacian | Replaces the thresholded overlay with the unprocessed Laplacian output. Useful for diagnosing tuning or calibration issues. |
A Reset button returns all values to their defaults.
Practical Considerations
Threshold tuning is the most important variable. Too low and nearly the entire image lights up. Too high and only the absolute sharpest micro-contrast registers. The default of 0.46 suits most sessions well; adjust up or down from there based on the scene.
Pre-blur is your noise lever — but it adapts automatically. The effective pre-blur radius is scaled by the image’s EXIF ISO value (√(ISO/400), capped at 3×) and by the image width (√(width/512), capped at 3×), so high-ISO files and larger images automatically receive more pre-smoothing without manual intervention. The slider sets the baseline; adjust it upward for scenes with particularly prominent out-of-focus texture — water, foliage, bokeh — or downward for very clean, low-ISO files where you want maximum edge sensitivity.
Subject texture matters. Smooth, low-contrast surfaces — clear sky, still water, skin — produce a weak Laplacian response even when perfectly focused, because there is little edge detail to detect. Focus peaking works best on subjects with natural texture: feathers, fur, foliage, fabric.
RAW vs JPG. The mask is more effective when applied to extracted JPGs rather than thumbnails. Thumbnails are heavily processed and downscaled before RawCull sees them, which reduces the fine edge detail the Laplacian depends on.
Summary
RawCull’s Focus Peaking runs a Laplacian of Gaussian pipeline entirely on the GPU via Metal. An ISO- and resolution-adaptive Gaussian pre-blur suppresses noise and out-of-focus texture; an 8-neighbour Laplacian kernel detects genuine sharpness spikes; thresholding followed by morphological erosion and dilation (both quantised to whole pixels) produces a clean, solid mask; a 4 % border inset removes pre-blur edge artifacts; a final feather pass softens the overlay edges; and screen blending composites the red overlay non-destructively over the original image. The result is a fast, accurate, and visually interpretable sharpness map that makes focus assessment immediate — particularly valuable when reviewing large numbers of action or wildlife shots where critical focus on a small moving subject is difficult to judge from the image alone.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.