생성,복사, 부분 영상 추출

매일 공부(ML)·2021년 11월 3일
0

OPEN CV

목록 보기
2/45

기초 지식

numpy.empty(shape, dtype=float, ...) -> arr
numpy.zeros(shape, dtype=float, ...) -> arr
numpy.ones(shape, dtype=None, ...) -> arr
numpy.full(shape, fill_value, dtype=None, ...) -> arr
  • shape: 각 차원의 크기.(h,w) or (h,w,3)

  • dtype: 원소의 데이터 타입을 나타내는 것으로 보통 numpy.uint8지정

  • arr: 생성된 영상(numpy.ndarrary)

  • numpy.empty(): 임의의 값으로 초기화된 배열

  • numpy.zero(): 0으로 초기화된 배열

  • numpy.ones(): 1로 초기화된 배열

  • numpy.full(): fill_value로 초기화된 배열

생성

img1 = np.empty((360, 480), dtype=np.uint8) #grayscale image
img2 = np.zeros((360, 480, 3), dtype=np.uint8) # color image,RGB
img3 = np.ones((360, 480), dtype=np.uint8) * 255 # white color
img4 = np.full((360, 480, 3), (0, 255, 255), dtype=np.uint8) # yellow color

복사

img1 = cv2.imread('HappyFish.jpg') #파일 불러오기
img2 = img1 # img2에 img1을 할당한다
img3 = img1.copy() # img3에 img1에 복사한다.

img1 = cv2.imread('HappyFish.jpg') #파일 불러오기
img2 = img1 # img2에 img1을 할당한다
img3 = img1.copy() #img1이 다르게 변해도 기존의 할당 파일이 복사됨
img1.fill(255) # img1의 변화가 img2에도 영향을 미치지만 img3엔 미치지 못함

부분 영상 추출

img1 = cv2.imread('HappyFish.jpg') #이미지 할당
img2 = img1[40:120, 30:150] # numpy.ndarray의 슬라이싱 -> 부분 추출 가능하다
img3 = img1[40:120, 30:150].copy() # 부분 추출 영상 복사
img2.fill(0) #black color
profile
성장을 도울 아카이빙 블로그

0개의 댓글