2016-10-26 6 views

답변

2

0이 아닌 255으로 변경해야하는 모든 요소를 ​​어떻게 PIL 사용에 대한

a[a != 0] = 255 
0

와 같은 기능을합니다

def convert (self,image): 
    return image.convert('1') 

테스트 코드 :

from PIL import Image 
import matplotlib.pyplot as plt 

def convert (image): 
    return image.convert('1') 

img = Image.open('./test.png') 
plt.figure(); plt.imshow(img) 
BW = convert(img) 
plt.figure(); plt.imshow(BW) 
plt.show() 

을 결과 :

enter image description here enter image description here

그리고 BTW, 경우에 당신은 PIL 이미지 객체의 NumPy와 배열을 필요로 쉽게 사용하여 얻을 수 있습니다 :

matrix_of_img = numpy.asarray(img.convert('L')) 
관련 문제