Matrix 연산

이주희·2022년 10월 4일
0

이미지 타입 확인하기

import cv2 as cv
import numpy as np

def func1():
    img1 = cv.imread('CV Images/cat.bmp', cv.IMREAD_GRAYSCALE)
    
    if img1 is None:
        print('Image load failed!')
        return
    
    print(type(img1))
    print(img1.shape)

    if len(img1.shape) == 2:
        print('img is a grayscale image')
    elif len(img1.shape)== 3:
        print('img1 is a truecolor image')
    cv.imshow('img1',img1)
    cv.waitKey()
    cv.destroyAllWindows()
    
func1()

shape가 2이면 이미지의 가로 세로 2차원 가진 것임
-> 그레이스케일

shape가 3이면 가로 세로 3색 3차원을 가진 것임
-> 컬러

부분행렬 추출

import cv2 as cv
import numpy as np


img1 = cv.imread('CV Images/lenna.bmp', cv.IMREAD_GRAYSCALE)
img2 = img1[200:400,200:400]
cv.imshow('img2',img2)
cv.waitKey()
cv.destroyAllWindows()

이미지 반전 : 255-그림

0개의 댓글