[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의 경우도 마찬가지임.

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
'Programming/DIP' 카테고리의 다른 글
  • [DIP] Interpolation (on Image)
  • [DIP] Image Morphing (Simple)
  • [DIP] Image 다루기: cv2-기본편 1 (Summary)
  • [DIP] cv2.imwrite
dsaint31x
dsaint31x
    반응형
    250x250
  • dsaint31x
    Dsaint31's blog
    dsaint31x
  • 전체
    오늘
    어제
    • 분류 전체보기 (785)
      • Private Life (15)
      • Programming (55)
        • DIP (116)
        • ML (34)
      • Computer (119)
        • CE (53)
        • ETC (33)
        • CUDA (3)
        • Blog, Markdown, Latex (4)
        • Linux (9)
      • ... (368)
        • Signals and Systems (115)
        • Math (176)
        • Linear Algebra (33)
        • Physics (43)
        • 인성세미나 (1)
      • 정리필요. (61)
        • 의료기기의 이해 (6)
        • PET, MRI and so on. (7)
        • PET Study 2009 (1)
        • 방사선 장해방호 (5)
        • 방사선 생물학 (3)
        • 방사선 계측 (9)
        • 기타 방사능관련 (3)
        • 고시 (9)
        • 정리 (18)
      • RI (0)
      • 원자력,방사능 관련법 (2)
  • 블로그 메뉴

    • Math
    • Programming
    • SS
    • DIP
  • 링크

    • Convex Optimization For All
  • 공지사항

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

  • 태그

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

  • 최근 글

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

티스토리툴바