파이썬으로 Homomorphic Filtering 하기
import cv2 # For OpenCV modules (For Image I/O and Contour Finding) import numpy as np # For general purpose array manipulation import scipy . fftpack # For FFT2 #### imclearborder definition def imclearborder ( imgBW , radius ): # Given a black and white image, first find all of its contours imgBWcopy = imgBW . copy () contours , hierarchy = cv2 . findContours ( imgBWcopy . copy (), cv2 . RETR_LIST , cv2 . CHAIN_APPROX_SIMPLE ) # Get dimensions of image imgRows = imgBW . shape [ 0 ] imgCols = imgBW . shape [ 1 ] contourList = [] # ID list of contours that touch the border # For each contour... for idx in np . arange ( len ( contours )): # Get the i'th contour cnt = contours [ idx ] # Look at each point in the contour for pt in cnt : rowCnt = pt [ 0 ][ 1 ] colCnt = pt [ 0 ][ 0 ] # If this is within the radius of th...
꿀꺽 꿀꺽 쉽게 pylearn2를 사용까지의 단계를 쓰면 이렇게된다
답글삭제(전제) python, git, pip를 사용할 수있는 상태. numpy와 scipy가 설치되어있다.
1 theano 설치
2 pylearn2를 설치한다. (그렇다고해도 git clone을)
python, git, pip, numpy, scipy 사용 준비의 설명은 이번 뺀다.
theano 설치
답글삭제pip install theano
에서 끝장 인 것 (설정이 잘되어 있으면)
필요한 라이브러리
답글삭제PIL
PyYAML
IPython
Cython
전부 pip install명령으로 낙승이다.
그러나 PIL은 pip install PIL는 안되고 pip install pillow으로
pylearn2 설치
답글삭제다음의 두 명령을 실행하면 잘될 (두)
git clone git://github.com/lisa-lab/pylearn2.git
python setup.py develop
pylearn2 테스트
답글삭제pylearn2의 사용법은 간단하게 정리하면,
데이터 세트를 준비한다 ( .plk되고, .csv이든지)
훈련 데이터의 경로와 훈련 방법의 레시피를 작성 (* .yaml 파일에)
train 레서피인 yaml 파일 실행
이 사이트의 아래쪽에 CIFAR10과 MNIST라는 이미지 데이터 세트의 샘플 실행 예가있다.
http://deeplearning.jp/?p=196
http://shower.human.waseda.ac.jp/~asaitaku/toolsManual/_build/html/python/pylearn2/main.html
https://github.com/laughing/grbm_sample
답글삭제-여배우 목록에서 원하는 여배우의 이미지를 모아 온다.
-여배우의 사진을 입력하고 Deep learning 모델을 구축 본다.
-공통적 인 특징 량을 추출한다.
rgb2gray.py
답글삭제------------------------------------------------------
#! /usr/bin/python
from PIL import Image
from PIL import ImageOps
import os
import sys
if __name__ == "__main__":
if len(sys.argv)==3:
input_path = sys.argv[1]
output_path = sys.argv[2]
else:
sys.exit("Need 2 args. Input ans Output path")
input_image = Image.open(input_path)
output_image = ImageOps.grayscale(input_image)
output_image.save(output_path)
img2hsv,py
답글삭제------------------------------------------------
import numpy
import Image
import ImageOps
import ImageFilter
import sys
import glob
def usage():
print "./img2csv.py img csv"
if len(sys.argv) != 3:
usage()
exit(0)
_, imgPath, csvPath = sys.argv
def gs(path):
im = Image.open(path)
im = ImageOps.grayscale(im)
im.save("%s_gs.png" % path.split(".")[0])
return im
def resize(im, x, y):
return im.resize((x, y))
def edge(im):
return im.filter(ImageFilter.FIND_EDGES)
def img2text(path):
im = resize(gs(path), 48, 48)
# im.save("gs.png")
l = (numpy.asarray(im).flatten() / 255.0).tolist()
#l = [1 if e > 0.5 else 0 for e in l]
l = [str(e) for e in l]
return " ".join(l)
def img2csv(imgPath, csvPath):
import csv
f = open(csvPath, "w")
writer = csv.writer(f)
writer.writerow([1,1])
for e in glob.glob(imgPath):
print e
l = img2text(e)
writer.writerow([1, l])
f.close()
if __name__ == "__main__":
img2csv(imgPath, csvPath)
python img2hsv.py gray1.jpg gray2.jpg ... train.csv
답글삭제를 실행한다.