Last active
June 16, 2018 11:17
-
-
Save p-geon/6ea6176f216c7720d412652ef4d1a9fb to your computer and use it in GitHub Desktop.
pythonで便利なやつら
This file contains 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 pdb; pdb.set_trace() | |
# 毎回書くアレ。画像表示用関数 | |
import matplotlib.pyplot as plt | |
def single_color(img, dpi=72): | |
plt.figure(dpi=dpi) | |
plt.imshow(img) | |
plt.show() | |
plt.close() | |
# グレースケール画像用 | |
def single_gray(img, dpi=72): | |
plt.figure(dpi=dpi) | |
plt.imshow(img, cmap='gray', interpolation='none', vmin = 0, vmax = 1.0) | |
plt.show() | |
plt.close() | |
# ヒストグラム保存するやつ | |
def show_hist(x, savedir='./results/histgram.png', dpi=72): | |
plt.figure(dpi=dpi) | |
plt.hist(x, bins=255, range=(0, 1), normed=False, cumulative=False, bottom=None, histtype='bar', label=None) | |
plt.savefig(savedir) | |
plt.close() | |
# GUI環境ないときの matplot | |
#matplotlib.use('Agg') | |
# matplot をjupyter notebookにブチこむアレ | |
%matplotlib inline | |
# 画像保存するやつ | |
from skimage.io import imsave | |
def save(img, name="default"): | |
imsave(fname=f"{name}.png", arr=img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment