1. 픽셀 정보 가져오기
1) (100, 200)에 위치한 pixel의 Blue, Green, Red값 가져오기
px = img[100,200]
print(px)
2) (100,200)에 위치한 pixel의 Blue 값 가져오기
- OpenCV에서는 RGB순이 아닌 BGR이다.
- 즉 Blue는 0, G는 1, R은 2의 인덱스에 위치하게 된다.
b = img[100,200,0]
print(b)
-item() 함수를 사용하여 픽셀의 컬러값을 가져올 수 있다.
# (20,20)에서의 red값
img.item(20,20,2)
3) pixel 값 변경하기 (흰색으로)
img[100,200] = [255,255,255]
2.영상의 속성
- 영상의 형태 정보
img.shape
#(h,w,channel)값을 리턴받음.
- 영상의 넓이
img.size
# W*h값 리턴받음.
- 영상의 데이터 타입
img.dtype
3. 영상의 특정 영역을 복사하여 붙이기
import cv2
import numpy as np
img = cv2.imread('baseball-player.jpeg')
ball= img[409:454,827:894] # 행의 시작점: 끝점, 열의 시작점 :끝점
img[480:525,827:894] = ball
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)
4. 영상 channel 값 변경하기
import cv2
import numpy as np
img = cv2.imread('baseball-player.jpeg')
#Red 성분을 0으로
img[:,:,2] = 0
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(0)
4.이미지 블랜딩(image blending)
import cv2
import numpy as np
img1 = cv2.imread('flower1.jpeg')
img2 = cv2.imread('flower2.jpeg')
w=50
dst = cv2.addWeighted(img1,float(100-w) * 0.01, img2, float(w) * 0.01, 0)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
(image blending 50%)
'CV' 카테고리의 다른 글
이미지 블러링(Images Smoothing/Blurring) (0) | 2022.10.23 |
---|---|
이미지의 기하학적 변환(Geometric Transformations of images) (0) | 2022.10.23 |
도형 그리기(직선, 사각형, 원, 타원, 다각형, 텍스트) (0) | 2022.10.22 |
연결 요소 (0) | 2022.10.22 |
이진화, 오츠 알고리즘(Binarization, Thresholding, Otsu Algorithm) (0) | 2022.10.22 |