Add dynamic denoising and inpaint bbox sizing
This commit adds two features I've personally found useful, but I'm unsure if they would be beneficial to others. I thought I'd create a pull request to see if there's any interest in them, and to make sure they work correctly on other configurations.
Dynamic denoising strength
Denoising strength is a difficult value to tune, as the amount of denoising is often linked to the size of the inpaint region, with smaller areas requiring stronger denoising, and larger areas less.
This is my attempt to try and somewhat automate denoising strength tweaking. Basically, I take the pixel area of the bbox and the area of the original image, normalise the value, and apply power scaling to it. This value is then multiplied by the "Inpaint denoising strength" value (which effectively sets the maximum denoising value).
I've found this approach very effective at modulating the denoise strength, and it can modulate it per bbox, so that if there are multiple areas of different sizes in the one image, the strength is tweaked appropriately for each. Recommended settings:
Inpaint denoising strength: 0.6 - 0.7 (now effectively a maximum value, which is scaled down)
Power scaling value: 2.0-4.0 (modulates the scaling by a power curve)
By default, the power scaling value is 0, which disables the feature. It also supports negative values for the sake of completeness, but I found in testing you usually want a sharp drop off in denoising strength between small and large areas.
Match inpaint dimensions to bbox size
If the user doesn't specify their own inpaint width and height, the original dimensions of the image are used, which makes complete sense. However, it's often the case these dimensions are at odds with those of the bbox, resulting in a sub-optimal inpainting region.
With models like SDXL, that natively support alternate aspect ratios, we can calculate a better width and height from the bbox, and use that instead. It's highly likely you could come up with some resolutions for other models too; SDXL is the only model I've tested with (and so this feature is limited to SDXL only).
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.
Your idea is awesome, let's just review a few things and merge it.
Quality Gate passed
Issues
1 New issue
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code
I've consolidated the Free mode into a single setting after realising I was overcomplicating how the dimensions should be calculated. Definitely done with changes for now.
Before merge it, could you write a paragraph describing each features? I'm not a very good writer.
Before merge it, could you write a paragraph describing each features? I'm not a very good writer.
Of course, no worries.
In the Settings tab, under the ADetailer section, two options are available to optimize the inpainting process. By default, both options are disabled.
Power scaling for dynamic denoise strength based on bounding box size
Purpose: Automatically adjusts the denoising strength for each subject, reducing or eliminating the need for manual tweaking.
Accepted values: -10 to 10.
Recommended setting: Between 2 and 4, or set to 0 to disable.
When enabled, the Inpaint denoising strength will be dynamically scaled based on the size of each bounding box relative to the entire image. The value of this setting controls the steepness of the scaling curve: higher values lead to smaller areas receiving more denoising and larger areas less, while lower values create a more gradual curve. Note that Inpaint denoising strength sets the maximum denoising strength this scaling can apply.
Try to match inpainting size to bounding box size, if 'Use separate width/height' is not set
Purpose: Automatically adjusts the inpainting dimensions to match the bounding box aspect ratio, reducing the need to manually set inpainting width/height.
Accepted values: Off, Strict, Free.
Recommended setting: Use "Strict" for SDXL models and "Free" for other models.
When enabled, this setting overrides the inpainting width and height per bounding box with values that better match the box's aspect ratio, as long as the new dimensions are not significantly smaller. In "Strict" mode, the nearest SDXL-trained resolution is used to maximize compatibility. In "Free" mode, the larger of the original inpainting dimensions is scaled by the aspect ratio. This results in an exact match, but may not conform to the model's recommended aspect ratios/resolutions. For either mode to work, you must disable the Use separate width/height option in ADetailer's inpainting settings.
Thank you!