Seamless Cloning#
Detailed Description#
Useful links:
https://www.learnopencv.com/seamless-cloning-using-opencv-python-cpp
Enumerations#
enum cv::SeamlessCloneFlags {
cv::NORMAL_CLONE = 1,
cv::MIXED_CLONE = 2,
cv::MONOCHROME_TRANSFER = 3,
cv::NORMAL_CLONE_WIDE = 9,
cv::MIXED_CLONE_WIDE = 10,
cv::MONOCHROME_TRANSFER_WIDE = 11
}Flags for the seamlessClone algorithm. View details
Enumeration Type Documentation#
SeamlessCloneFlags#
#include <opencv2/photo.hpp>
Flags for the seamlessClone algorithm.
Enumerator:
|
Normal seamless cloning. This method is ideal for inserting objects with complex outlines into a new background. It preserves the original appearance and lighting of the inserted object, ensuring a natural blend. |
|
Mixed seamless cloning. This method addresses cases where simple color-based selection or alpha masking is time-consuming and may result in undesirable halos. By combining structure from the source and texture from the destination, mixed seamless cloning is highly effective, even with loosely defined selections. |
|
Monochrome transfer cloning. This method allows users to replace specific features of an object, such as grayscale textures or patterns, with alternative features. It is particularly useful for artistic effects or targeted object modifications. |
|
Enhanced normal seamless cloning. Similar to |
|
Enhanced mixed seamless cloning. Similar to |
|
Enhanced monochrome transfer cloning. Similar to |
Function Documentation#
colorChange()#
void cv::colorChange(
InputArray src,
InputArray mask,
OutputArray dst,
float red_mul = 1.0f,
float green_mul = 1.0f,
float blue_mul = 1.0f )
#include <opencv2/photo.hpp>
Python:
cv.colorChange(src, mask[, dst[, red_mul[, green_mul[, blue_mul]]]]) -> dst
Given an original color image, two differently colored versions of this image can be mixed seamlessly.
Multiplication factor is between .5 to 2.5.
Parameters
src— Input 8-bit 3-channel image.mask— Input 8-bit 1 or 3-channel image.dst— Output image with the same size and type as src .red_mul— R-channel multiply factor.green_mul— G-channel multiply factor.blue_mul— B-channel multiply factor.
illuminationChange()#
void cv::illuminationChange(
InputArray src,
InputArray mask,
OutputArray dst,
float alpha = 0.2f,
float beta = 0.4f )
#include <opencv2/photo.hpp>
Python:
cv.illuminationChange(src, mask[, dst[, alpha[, beta]]]) -> dst
Applying an appropriate non-linear transformation to the gradient field inside the selection and then integrating back with a Poisson solver, modifies locally the apparent illumination of an image.
This is useful to highlight under-exposed foreground objects or to reduce specular reflections.
Parameters
src— Input 8-bit 3-channel image.mask— Input 8-bit 1 or 3-channel image.dst— Output image with the same size and type as src.alpha— Value ranges between 0-2.beta— Value ranges between 0-2.
seamlessClone()#
void cv::seamlessClone(
InputArray src,
InputArray dst,
InputArray mask,
Point p,
OutputArray blend,
int flags )
#include <opencv2/photo.hpp>
Python:
cv.seamlessClone(src, dst, mask, p, flags[, blend]) -> blend
Performs seamless cloning to blend a region from a source image into a destination image. This function is designed for local image editing, allowing changes restricted to a region (manually selected as the ROI) to be applied effortlessly and seamlessly. These changes can range from slight distortions to complete replacement by novel content [244].
Parameters
src— The source image (8-bit 3-channel), from which a region will be blended into the destination.dst— The destination image (8-bit 3-channel), where the src image will be blended.mask— A binary mask (8-bit, 1, 3, or 4-channel) specifying the region in the source image to blend. Non-zero pixels indicate the region to be blended. If an empty Mat is provided, a mask with all non-zero pixels is created internally.p— The point where the center of the src image is placed in the dst image.blend— The output image that stores the result of the seamless cloning. It has the same size and type asdst.flags— Flags that control the type of cloning method, can take values ofcv::SeamlessCloneFlags.
textureFlattening()#
void cv::textureFlattening(
InputArray src,
InputArray mask,
OutputArray dst,
float low_threshold = 30,
float high_threshold = 45,
int kernel_size = 3 )
#include <opencv2/photo.hpp>
Python:
cv.textureFlattening(src, mask[, dst[, low_threshold[, high_threshold[, kernel_size]]]]) -> dst
By retaining only the gradients at edge locations, before integrating with the Poisson solver, one washes out the texture of the selected region, giving its contents a flat aspect. Here Canny Edge Detector is used.
Note
The algorithm assumes that the color of the source image is close to that of the destination. This assumption means that when the colors don’t match, the source image color gets tinted toward the color of the destination image.
Parameters
src— Input 8-bit 3-channel image.mask— Input 8-bit 1 or 3-channel image.dst— Output image with the same size and type as src.low_threshold— Range from 0 to 100.high_threshold— Value > 100.kernel_size— The size of the Sobel kernel to be used.