dst ( I ) = ¬ src ( I ) \texttt{dst} (I) = \neg \texttt{src} (I) dst(I)=¬src(I)
CV_EXPORTS_W void bitwise_not(InputArray src, OutputArray dst, InputArray mask = noArray());
Mat mask = Mat::zeros(512, 512, CV_8UC1); Rect rect = Rect(100, 100, 200, 200); mask(rect) = Scalar(1); Mat bitwiseNot; bitwise_not(left, bitwiseNot, mask); imshow("bitwise_not", bitwiseNot);
src1
和 src2
是两个大小相同的图像矩阵dst ( I ) = src1 ( I ) ∧ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)∧src2(I)if mask(I)=0
src1
是图像矩阵,src2
是 Scalardst ( I ) = src1 ( I ) ∧ src2 if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \wedge \texttt{src2} \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)∧src2if mask(I)=0
src1
是 Scalar ,src2
是图像矩阵dst ( I ) = src1 ∧ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} \wedge \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1∧src2(I)if mask(I)=0
CV_EXPORTS_W void bitwise_and(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray());
Mat bitwiseAnd; Scalar scalar = Scalar(255,255); bitwise_and(left, scalar, bitwiseAnd); imshow("bitwise_and", bitwiseAnd);
src1
和 src2
是两个大小相同的图像矩阵dst ( I ) = src1 ( I ) ∨ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)∨src2(I)if mask(I)=0
src1
是图像矩阵,src2
是 Scalardst ( I ) = src1 ( I ) ∨ src2 if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \vee \texttt{src2} \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)∨src2if mask(I)=0
src1
是 Scalar ,src2
是图像矩阵dst ( I ) = src1 ∨ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} \vee \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1∨src2(I)if mask(I)=0
CV_EXPORTS_W void bitwise_or(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray());
Mat bitwiseOr; Scalar scalarOr = Scalar(255); bitwise_or(left, scalarOr, bitwiseOr); imshow("bitwise_or", bitwiseOr);
src1
和 src2
是两个大小相同的图像矩阵dst ( I ) = src1 ( I ) ⊕ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)⊕src2(I)if mask(I)=0
src1
是图像矩阵,src2
是 Scalardst ( I ) = src1 ( I ) ⊕ src2 if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} (I) \oplus \texttt{src2} \quad \texttt{if mask} (I) \ne0 dst(I)=src1(I)⊕src2if mask(I)=0
src1
是 Scalar ,src2
是图像矩阵dst ( I ) = src1 ⊕ src2 ( I ) if mask ( I ) ≠ 0 \texttt{dst} (I) = \texttt{src1} \oplus \texttt{src2} (I) \quad \texttt{if mask} (I) \ne0 dst(I)=src1⊕src2(I)if mask(I)=0
CV_EXPORTS_W void bitwise_xor(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray());
Mat bitwiseXor; Scalar scalarXor = Scalar(255, 255); bitwise_xor(left, scalarXor, bitwiseXor); imshow("bitwise_xor", bitwiseXor);
图像矩阵的 add
、subtract
、multiply
、divide
四则运算是针对矩阵内对应元素的操作,并非矩阵的加减乘除。
dst ( I ) = saturate ( src1 ( I ) + src2 ( I ) ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1(I)+src2(I))if mask(I)=0
src1
为图像矩阵,src2
为 Scalardst ( I ) = saturate ( src1 ( I ) + src2 ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) + \texttt{src2} ) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1(I)+src2)if mask(I)=0
src1
为 Scalar,src2
为 图像矩阵dst ( I ) = saturate ( src1 + src2 ( I ) ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} + \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1+src2(I))if mask(I)=0
dst ( I ) = saturate ( src1 ( I ) − src2 ( I ) ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2}(I)) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1(I)−src2(I))if mask(I)=0
src1
为图像矩阵,src2
为 Scalardst ( I ) = saturate ( src1 ( I ) − src2 ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1}(I) - \texttt{src2} ) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1(I)−src2)if mask(I)=0
src1
为 Scalar,src2
为图像矩阵dst ( I ) = saturate ( src1 − src2 ( I ) ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src1} - \texttt{src2}(I) ) \quad \texttt{if mask}(I) \ne0 \\ dst(I)=saturate(src1−src2(I))if mask(I)=0
dst ( I ) = saturate ( src2 − src1 ( I ) ) if mask ( I ) ≠ 0 \texttt{dst}(I) = \texttt{saturate} ( \texttt{src2} - \texttt{src1}(I) ) \quad \texttt{if mask}(I) \ne0 dst(I)=saturate(src2−src1(I))if mask(I)=0
dst ( I ) = saturate ( scale ⋅ src1 ( I ) ⋅ src2 ( I ) ) \texttt{dst} (I)= \texttt{saturate} ( \texttt{scale} \cdot \texttt{src1} (I) \cdot \texttt{src2} (I)) dst(I)=saturate(scale⋅src1(I)⋅src2(I))
dst(I) = saturate(src1(I)*scale/src2(I)) \texttt{dst(I) = saturate(src1(I)*scale/src2(I))} \\ dst(I) = saturate(src1(I)*scale/src2(I))
dst(I) = saturate(scale/src2(I)) \texttt{dst(I) = saturate(scale/src2(I))} dst(I) = saturate(scale/src2(I))
CV_EXPORTS_W void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1);
CV_EXPORTS_W void subtract(InputArray src1, InputArray src2, OutputArray dst, InputArray mask = noArray(), int dtype = -1);
CV_EXPORTS_W void multiply(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1);
CV_EXPORTS_W void divide(InputArray src1, InputArray src2, OutputArray dst, double scale = 1, int dtype = -1);
int8_t b[6] = {8, 9, 10, 11, 12, 13};int8_t c[6] = {6, 7, 5, 4, 3, 9};Mat first = Mat(3, 2, CV_8UC1, b);Mat second = Mat(3, 2, CV_8UC1, c);Mat third = Mat(2, 3, CV_8UC1, c);// 算数运算Mat addResult;add(first, second, addResult);cout << "add" << endl << format(addResult, Formatter::FMT_C) << endl << endl;Mat subtractResult;subtract(first, second, subtractResult);cout << "subtract" << endl << format(subtractResult, Formatter::FMT_C) << endl << endl;Mat multiplyResult;multiply(first, first, multiplyResult);cout << "multiply" << endl << format(multiplyResult, Formatter::FMT_C) << endl << endl;Mat divideResult;divide(first, second, divideResult);cout << "divide" << endl << format(divideResult, Formatter::FMT_C) << endl << endl;