CopyMakeBorder border extrapolation
Function description: Fill the border according to the specified border extrapolation method.
void CopyMakeBorder(InputArray src,
OutputArray dst,
int top,
int bottom,
int left,
int right,
BorderTypes borderType,
Scalar? value = null)
parameter | illustrate |
---|---|
InputArray src | source image |
OutputArray dst | output image |
int top | Upper bound extrapolated pixels |
int bottom | Lower bound extrapolated pixels |
int left | left border extrapolated pixels |
int right | Right border extrapolated pixels |
BorderTypes borderType | Boundary Extrapolation Type |
Scalar? value | When the extrapolation type is Constant, the padding value |
BorderTypes values
value | illustrate |
---|---|
Constant | Fill with fixed value `iiiiii|abcdefgh|iiiiiii` with some specified `i` |
Replicate | Repeat filling by boundary value `aaaaaa|abcdefgh|hhhhhhh` |
Reflect | Reflection/mirror fill (starting from boundary pixels) `fedcba|abcdefgh|hgfedcb` |
Wrap | Fill by opposite image pixels `cdefgh|abcdefgh|abcdefg` |
Reflect101 | Mirror fill (starting one pixel inward from the border) `gfedcb|abcdefgh|gfedcba` |
Transparent | CopyMakeBorder function is not supported `uvwxyz|absdefgh|ijklmno` |
Default | Same as Reflect101 |
Isolated | Do not fill based on the original image Same as Constant? |
Fill example
Constant fills with fixed value
Replicate repeats filling by boundary pixels
Reflect reflection/mirror fill
Wrap fills the image pixels on the opposite side
Reflect101 mirror fill (starting 1 pixel inward from the border)
Isolated does not fill based on the original image
Source code example
private void TestBorderTypes(Mat src) {
var bBorderTypes = Enum.GetValues(typeof(BorderTypes));
foreach(BorderTypes b in bBorderTypes) {
try {
//外推宽度
var extend = 100;
using var dst = new Mat();
Cv2.CopyMakeBorder(src, dst, extend, extend, extend, extend, b, Scalar.All(127));
Cv2.Rectangle(dst, new Rect(extend, extend, src.Width, src.Height), Scalar.Red);
Cv2.ImShow($"{b.ToString()}", dst);
}
catch (Exception ex) {
//不支持 Transparent
}
}
Cv2.WaitKey();
Cv2.DestroyAllWindows();
}