Created
May 15, 2019 06:16
-
-
Save rkdgusrn1212/9e678f6d623a8bb76c9f006309652f73 to your computer and use it in GitHub Desktop.
Image Reversion using Pillow in Python.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from PIL import Image | |
import matplotlib.pyplot as plt | |
gray_img = Image.open('Lenna.png').convert("LA")#밝기와 알파값을 이용해서 Grayscale로 변환 | |
gray_img.save("gray_lenna.png")#grayscale로 변환된 흑백 이미지를 출력 | |
row = gray_img.size[0] | |
col = gray_img.size[1] | |
rev_img = Image.new("L", (row, col))#새 흑백이미지를 생성. | |
for x in range(1 , row): | |
for y in range(1, col): | |
rev_img.putpixel((x,y), int(255-gray_img.getpixel((x,y))[0])) | |
rev_img.save("reversion_lenna.png")#반전처리된 이미지 저장 | |
y = gray_img.histogram() | |
y = y[0:256] | |
x = np.arange(len(y)) | |
plt.figure(figsize=(8, 16)) | |
plt.subplot(211) | |
plt.title("grayscale hist") | |
plt.bar(x, y) | |
y = rev_img.histogram() | |
x = np.arange(len(y)) | |
plt.subplot(212) | |
plt.title("reversion hist") | |
plt.bar(x, y) | |
fig = plt.gcf() | |
plt.show() | |
fig.savefig("reversion_histogram.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment