Seamless Blending and Saliency Blending #4712
Locked
fmw42
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Imagemagick 7.1.0-20 introduces two new masked compose methods: 1) seamless-blend and 2) saliency-blend.
Note, that both methods work best when HDRI is enabled. Saliency-blending will be a bit slower than seamless blending.
These compose methods are implementations of Poisson Image Editing by Perez et. al.. Imagemagick uses an iterative finite difference implementation.1
The seamless-blend method simply tries to blend the overlay image smoothly over the background image. It is essentially a smoothly blended insert.
The saliency-blend method merges the background and overlay images such that the image that is the most salient at each pixel is preferentially put on top. That is it keeps the texture from whichever of the overlay or background image that has the most detail at each pixel.
The syntax is the same as any masked composite, namely,
Both methods require an appropriate mask. Arguments are set using either -set option:args or as follows using -define:
and
where Max-Iterations is the maximum number of iterations to compute before stopping, Distortion is the RMSE convergence stopping value between iterations, and the optional <Print-Iterations> is the number of iterations between printout to the terminal.
The first example does a seamless-blend of the bear image into the water image at an offset using the mask that outlines outside the bear. Add
-verboseto the command to see the iterations.One thing to note is that the bear image gets brightened by the seamless blend, because the background is lighter. To mitigate this, one can use a second mask image that outlines inside the bear. Since this is implemented using a read-mask, the polarity must be inverted. That is the inside of the mask is black and the outside is white.
The next example does a saliency-blend of some text scribble with an image of a wall. Since the text is on a constant background (little background detail) the textured wall will show in the background region of the text. This is similar to a regular -compose over where the background region of the overlay image is transparent. However, with saliency-blending, we do not have to explicitly make the background transparent. Because the background of the scribble image is constant color, the mask simply can be the full image, i.e. white with a 1 pixel black border (or an outline).
Likewise, we can add a rainbow into an image of an island with palm trees using saliency blending. Since the sky is a relatively constant color in the rainbow image, we can again use either an outline mask or the full image mask.
The final application creates seamless tiling of the follow image.
For comparison to seamless tiling, we first use the image to make a simple 3x3 tiled image by appending.
Note that in the above result, the tiled image clearly shows the seams between the tiles.
Next, we make the image into a seamless tile. However, first we have to use the image to create a background image with the constraints that the opposite sides are identical. This is done by averaging the opposite 1-pixel wide outer sides and replacing opposing sides with these averages.
This background image is now used with the original image as the overlay in a seamless-blend composite followed by a 3x3 append. The mask is the full image with a one-pixel wide black outline.
Hard seams in this 3x3 tiling are hardly seen.
Footnotes
Thanks to Imagemagick users snibgo and fmw42 for the finite difference implementation concept, prototyping and testing. ↩
Beta Was this translation helpful? Give feedback.
All reactions