앎을 경계하기

DAFIT 66

<DAFIT> 09 OpenCV 연습하기(1) - 02 Blurring Filter

원소 1/9 로 채워진 3x3 필터 : np.full() 사용. 이미지 사이즈는 (256,256), grayscale이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/909/lena.jpg' img = cv2.imread(img_path,2) img = cv2.resize(img,(256,256)) cv2_imshow(img) kernel = np.full((3,3),1/9) kernel after_img = cv2.filter2D(img, -1, kernel) cv2_imshow(after_img) 약간 블러처리된 느낌의 결과 이미..

<DAFIT> 09 OpenCV 연습하기(1) - 01 Convolution Filter

0~1 사이의 값 : random 값 3x3 커널 : [[a,b,c],[d,e,f,],[g,h,i]] 이미지는 (256,256)으로 resizing하고 grayscale로 변환. * 필요한 라이브러리 임포트 import cv2 from google.colab.patches import cv2_imshow import numpy as np * 이미지 읽기 #cv2.filter2D #0~1 사이 값으로 구성된 3x3 커널을 생성한 뒤 이미지에 적용한 두 이미지를 동시에 출력해보자. #이미지에 적용전 높이 너비를 256,256이고 gray로 변환한다. img_path = '/content/drive/My Drive/다핏문제/909/lena.jpg' img = cv2.imread(img_path,2)..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 07 영상 어파인 변환

import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' 세 개의 꼭지점을 정해주면 getAffineTransform을 통해 이미지 변환을 할 수 있다. img = cv2.imread(img_path,1) height, width = img.shape[:2] controls = [] controls.append((0,0)) controls.append((0,height)) controls.append((width,0)) controls.append((width, height)) src = np.float32([list(co..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 06 영상 크기 조절

이번에는 resizing 문제이다. import cv2 from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' img = cv2.imread(img_path,1) height, width = img.shape[:2] down_img = cv2.resize(img,(height//2,width//2)) cv2_imshow(down_img) up_img = cv2.resize(img, (height*2, width*2)) cv2_imshow(up_img) img_list = [] for i in range(100): img_list.append(cv2.resize(img,(he..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 05 영상 뒤집기

이번에는 flip을 해보는 문제이다. import cv2 from google.colab.patches import cv2_imshow import numpy as np img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' flip함수는 사용하는 게 굉장히 쉽다. 1이면 좌우반전, 0이면 상하반전을 한다. img = cv2.imread(img_path,1) print('origin') cv2_imshow(img) v_img = cv2.flip(img, 1) print('\n\nvertical flip') cv2_imshow(v_img) h_img = cv2.flip(img, 0) print('\n\nhorizontal flip') cv2_imshow..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 04 영상 회전

지난번 translation에 이어 이번에는 rotation을 해보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' angle을 지정해서 cv2.getRotationMatrix2D()를 사용해서 이미지의 중심점, 회전할 각도, 이미지크기(scale)을 넣어서 matrix를 구성해서 warpAffine에 넣어주면 된다. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] angle = 90.0 M = cv2.getRotationMatrix2D((cols/2..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 03 영상 이동

사진을 이동시켜보는 문제이다. import cv2 import numpy as np from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' x축으로 50 ( 1, 0, 50 ), y축으로 50 ( 0, 1, 50 ) 이동해보자. img = cv2.imread(img_path,1) rows, cols = img.shape[:2] M = np.float32([[1,0,50],[0,1,50]]) img_result = cv2.warpAffine(img, M, (cols, rows)) cv2_imshow(img_result) 굉장히 쉽게 성공했다! http://www.dafit.m..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 02 영상 읽기, 출력, 저장

이번에는 이미지의 채널을 변환하고 분리하고 병합하는 것이다. import cv2 as cv from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/lena.jpg' * 채널 변환 # OpenCV의 삼원색 기본 순서는 BGR이다. img_bgr = cv.imread(img_path,1) img_rgb = cv.cvtColor(img_rgb, cv.COLOR_BGR2RGB) cv2_imshow(img_bgr) cv2_imshow(img_rgb) * 채널 분리 및 병합 b,g,r = cv.split(img_bgr) img_rbg = cv.merge((r,b,g)) cv2_imshow(img_rbg..

<DAFIT> 07 OpenCV 다루기 첫걸음 - 01 영상 읽기, 출력, 저장

이번 OpenCV 문제들은 lena 사진을 가지고 문제를 진행한다. 레나 이미지는 영상처리를 접해본 적 있다면 한번쯤 어디선가 다 봤을 것 같다. 코랩에서 진행해서 imshow()를 사용하려면 아래 import 과정이 필요하다. import cv2 as cv from google.colab.patches import cv2_imshow img_path = '/content/drive/My Drive/다핏문제/907/DF907_01_01.jpg' #3채널로 이미지 읽기 img3 = cv.imread(img_path, flags=1) imread(이미지 경로, flags=-1,0,1 또는 enum constant) 1 = color 0 = grayscale -1 = alpha 채널 포함 열거형 상..

<DAFIT> 06 머신러닝을 통한 당뇨병 예측 - 07 Feature Importance

지금까지 풀었던 문제를 다시 한 번 정리해볼 수 있는 시간이다. from sklearn.tree import DecisionTreeClassifier from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import train_test_split import pandas as pd 지난 번 예측문제에서 사용했던 의사결정트리와 랜덤포레스트를 다시 한 번 사용한다. 데이터를 로드하고, data = pd.read_csv("/content/drive/My Drive/다핏문제/906/dataset_37_diabetes.csv") data 결측치 처리한다. presd = data.replace({'pres':0},..