[OpenCV] bitwise op.

2024. 9. 22. 17:58·Programming/DIP
728x90
728x90

Bitwise Operations

AND, OR, NOT, XOR 연산자를 OpenCV가 제공.

  • 주로 특정 영역(사각형 모양이 아닌)을 추출하는데 사용됨.
  • True의 representative value는 1이지만, uint8의 경우 255를 사용함.
  • False의 representative value는 0이지만, uint8의 경우도 마찬가지임.
더보기

This includes bitwise AND, OR, NOT and XOR operations.

  • 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()

'Programming > DIP' 카테고리의 다른 글

[DIP] Interpolation (on Image)  (2) 2024.09.22
[DIP] Image Morphing (Simple)  (0) 2024.09.22
[DIP] Image 다루기: 기본편 1; (Summary)  (0) 2024.09.22
[DIP] cv2.imwrite  (1) 2024.09.22
[DIP] alpha 채널과 검은색 글씨 처리 with convertScaleAbs  (0) 2024.09.16
'Programming/DIP' 카테고리의 다른 글
  • [DIP] Interpolation (on Image)
  • [DIP] Image Morphing (Simple)
  • [DIP] Image 다루기: 기본편 1; (Summary)
  • [DIP] cv2.imwrite
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (740)
      • Private Life (13)
      • Programming (56)
        • DIP (104)
        • ML (26)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (351)
        • Signals and Systems (103)
        • Math (172)
        • Linear Algebra (33)
        • Physics (42)
        • 인성세미나 (1)
      • 정리필요. (54)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (1)
        • PET Study 2009 (1)
        • 방사선 장해방호 (4)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

    • Test
    • PET Study 2009
    • 기타 방사능관련.
  • 인기 글

  • 태그

    numpy
    random
    signal_and_system
    Vector
    Python
    SIGNAL
    function
    Programming
    SS
    Term
    math
    linear algebra
    인허가제도
    검사
    Optimization
    signals_and_systems
    Convolution
    fourier transform
    Probability
    opencv
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
dsaint31x
[OpenCV] bitwise op.
상단으로

티스토리툴바