私の質問をお読みいただきありがとうございます。イメージ(np.array)をバイナリイメージに変換する
私はPythonには新しく、scipyに興味がありました。私はRacoonのイメージを(scipy miscで)バイナリイメージ(黒、白)にする方法を理解しようとしています。これはscipy-lectureチュートリアルでは教えられません。
これは、これまでの私のコードです:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import misc #here is how you get the racoon image
face = misc.face()
image = misc.face(gray=True)
plt.imshow(image, cmap=plt.cm.gray)
print image.shape
def binary_racoon(image, lowerthreshold, upperthreshold):
img = image.copy()
shape = np.shape(img)
for i in range(shape[1]):
for j in range(shape[0]):
if img[i,j] < lowerthreshold and img[i,j] > upperthreshold:
#then assign black to the pixel
else:
#then assign white to the pixel
return img
convertedpicture = binary_racoon(image, 80, 100)
plt.imshow(convertedpicture, cmap=plt.cm.gist_gray)
私は絵のバイナリを作るためのOpenCVを使用して他の人を見てきましたが、私はピクセルをループすることにより、この方法でそれを行うことができますどのように疑問に思って?私は上限値と下限値にどのような値を与えるのか分からないので、80と100の推測値を作りました。これを決定する方法はありますか?あなたがこのoverthinkingいる
なぜあなたは '下しきい値> IMG [I、J]とIMG [I、J]期待>今までに' true'を可能にupperthreshold'?それは '80> 100'を意味するでしょう! – Eric