图像的运算、加减乘除与或、异或
此处对图像的运算构建一个枚举类型
public enum ImageOperation
{
Add,
Divide,
Multiply,
SubStact,
And,
Or,
Xor,
Max,
Min
}
对图像的操作运行进行封装,方便使用。
1:Add 图像相加 两个矩阵的值直接进行加
2:Divide 图像相除,两个矩阵对应的值进行除 scr1/scr2*scale
3: Multiply 图像相乘,两个矩阵对应的值进行乘 scr1*scr2*scale
4:SubStact 图像相减,两个矩阵对应的值进行减
5:And 与
6:or 或
7:xor 异或
8:Max 两个矩阵对应位置的最大值
9:Min 两个矩阵对应位置的最小值
/// <summary>
/// 图片运算
/// </summary>
/// <param name="Srcimage">输入图片1</param>
/// <param name="Srcimage1">输入图片2</param>
/// <param name="mode">运算模式</param>
/// <param name="dst">输出图像</param>
/// <param name="scale">缩放系数</param>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static void ImageOperation(InputArray Srcimage, InputArray Srcimage1, ImageOperation mode, OutputArray dst, int scale = 0)
{
switch (mode)
{
case ImageOperation.Add:
Cv2.Add(Srcimage, Srcimage1, dst);
break;
case ImageOperation.Divide:
Cv2.Divide(Srcimage, Srcimage1, dst, scale);
break;
case ImageOperation.Multiply:
Cv2.Multiply(Srcimage, Srcimage1, dst, scale);
break;
case ImageOperation.SubStact:
Cv2.Subtract(Srcimage, Srcimage1, dst);
break;
case ImageOperation.And:
Cv2.BitwiseAnd(Srcimage, Srcimage1, dst);
break;
case ImageOperation.Or:
Cv2.BitwiseOr(Srcimage, Srcimage1, dst);
break;
case ImageOperation.Xor:
Cv2.BitwiseXor(Srcimage, Srcimage1, dst);
break;
case ImageOperation.Max:
Cv2.Max(Srcimage, Srcimage1, dst);
break;
case ImageOperation.Min:
Cv2.Min(Srcimage, Srcimage1, dst);
break;
default:
throw new ArgumentOutOfRangeException(nameof(mode), mode, null);
}
}
图像绝对值
一般用于sobel等边缘查找等算法中
Cv2.ConvertScaleAbs(Srcimage, dst);