728x90
728x90
Bitwise Operations:
AND, OR, NOT, XOR 연산자를 OpenCV가 제공.
- 주로 특정 영역(사각형 모양이 아닌)을 추출하는데 사용됨.
- True의 representative value는 1이지만, uint8의 경우 255를 사용함.
- False의 representative value는 0이지만, uint8의 경우도 마찬가지임.
https://gist.github.com/dsaint31x/a9ca880a91bceee901d0cce4903c6f4c
cv_binary_op.ipynb
cv_binary_op.ipynb. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
종류:
- cv2.bitwise_and()
- cv2.bitwise_or()
- cv2.bitwise_not()
- cv2.bitwise_xor()
더보기
This includes bitwise AND, OR, NOT and XORoperations.
- They will be highly useful while extracting any part of the image
- defining and working with non-rectangular ROI etc.
Example :

import cv2
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def show_heatmap(ax,title,img):
ax.set_title(title)
sns.heatmap(img,annot=True,fmt='.2f',cmap=plt.cm.gray, ax =ax,
cbar=False, linewidth=0, linecolor='blue')
for spine in ax.spines.values():
spine.set_visible(True)
spine.set_edgecolor('blue')
spine.set_linewidth(2)
img_0 = np.zeros(shape=(2,2), dtype=np.uint8)
img_0[:,:1]= 255
img_1 = np.zeros_like(img_0)
img_1[:1,:]= 255
d_and = cv2.bitwise_and(img_0,img_1)
d_or = cv2.bitwise_or (img_0,img_1)
d_not = cv2.bitwise_not(img_0)
d_xor = cv2.bitwise_xor(img_0,img_1)
fig, axs = plt.subplots(1,6, figsize=(12,2))
show_heatmap(axs[0], 'img_0', img_0)
show_heatmap(axs[1], 'img_1', img_1)
show_heatmap(axs[2], 'd_and', d_and)
show_heatmap(axs[3], 'd_or' , d_or)
show_heatmap(axs[4], 'd_not(img_0)', d_not)
show_heatmap(axs[5], 'd_xor', d_xor)
plt.tight_layout()
plt.show()
같이 보면 좋은 자료들
https://dsaint31.tistory.com/813
[DIP] Image 다루기: cv2-기본편 3 (Summary)
openCV를 통한 이미지를 다루기 위한 기본 내용 (3) 1. Basic Operationsimage pixel 값에 접근하기: 개별접근과 slicingNumPy의 FancyIndexing이나 mask를 이용한 방식에 대한 이해하고 있는 것이 중요함더보기https:/
dsaint31.tistory.com
728x90
'Programming > DIP' 카테고리의 다른 글
| [DIP] Interpolation (on Image) (2) | 2024.09.22 |
|---|---|
| [DIP] Image Morphing (Simple) (0) | 2024.09.22 |
| [DIP] Image 다루기: cv2-기본편 1 (Summary) (0) | 2024.09.22 |
| [DIP] cv2.imwrite (1) | 2024.09.22 |
| [DIP] alpha 채널과 검은색 글씨 처리 with convertScaleAbs (0) | 2024.09.16 |