Arithmetic operation and logic operation of Video
Arithmetic operation and logic operation of Video
1. Addition operation
dst(x,y) = saturate(src1(x,y)+src2(x,y))
- It Add the pixel value that exists on same position between two videos and Set the pixel value of video.
- If the value is more than 255, set the pixel value to 255.
cv2.add(src1, src2, dst=None, mask=None, dtype=None) -> dst
- src1 : (input) first video or schalar
- src2 : (input) second video or schalar
- dst : (output) result video of addition operation
- mask : mask video
- dtype : type of output video
2. Weighted sum
dst(x,y) = saturate(a * src1(x,y) + b * src2(x,y))
-
Calculating weighted sum about pixel value which exist same position of two video and Setting the pixel value of result video.
-
Genarlly, spacifiy a + b = 1 (Maintaing normal birghtness of two input video)
3. Average operation
dst(x,y) = 1/2(src1(x,y) + src2(x,y))
- Setting the weight with a = b = 0.5
Code of weighted sum
cv2.addWeighted(src1,alpha,src2,beta,gamma,dst=None,dtype=None) -> dst
- src1 : Frist video
- alpha : Weight of first video
- src2 : Second video ( same type & same size with src1)
- beta : Weight of second video
- gamma : Additional added value to result value
- dst : result vieo of weighted sum
- dtype : type of output video(dst)
4. Subtraction operation
dst(x,y) = |src1(x,y) - src2(x,y)
- It doesn’t be effected from order of input video
Code of subtracion operation
cv2.subtract(src1, src2, dst = None, mask = None, dtype = None ) -> dst
- src1 : first video
- src2 : second video
- dst : result video of subtraction operation
- mask : mask video
- dtype : type of output video
5. Bit unit operation ( AND, OR. XOR, NOT)
cv2.bitwise_and(src1, src2, dst = None, mask = None) -> dst
cv2.bitwise_or(src1, src2, dst = None, mask = None) -> dst
cv2.bitwise_xor(src1, src2, dst = None, mask = None) -> dst
cv2.bitwise_not(src1, dst = None, mask = None) -> dst
- src1 : first video
- src2 : second video
- dst : result video
- mask : mask video
Leave a comment