Tkinterを使用してNDVIを判別できるグラフィカルインターフェイスを作成しています。その時点までのすべての良い。 NDVI、結果のイメージが黒:(で計算する場合、あなたはそれを保存することはできませんが、画像を印刷するときに、各ピクセルの値を取得します。OpenCv/Tkinter/Pythonを使用して画像を保存して表示することはできません
コード
def ndvi(self,*args):
#self.res_guar esta en BGR
self.res_guar = self.res_guar.astype('float')
(self.r,self.g,self.b) = cv2.split(self.res_guar)
#Calculo NDVI
self.resta = cv2.subtract(self.r,self.b)
self.suma = cv2.add(self.r,self.b)
self.ndvi = cv2.divide(self.resta,self.suma)
self.rows,self.cols,_ = self.res_guar.shape
self.y = np.zeros((self.rows,self.cols,3),dtype=np.uint8) # for output
greenyellow = [4,255,173]
yellow = [0,255,255]
yellowred = [4,111,255]
green = [0,255,0]
blue = [255,0,0]
red = [0,0,255]
white = [255,255,255]
black = [0,0,0]
for i in range(self.rows):
for j in range(self.cols):
k = self.ndvi[i,j]
if 0.0 < k < 0.2 :
self.y[i,j] = yellowred
#print "Pintando AmarilloRojo"
break
elif 0.2 < k < 0.4 :
self.y[i,j] = yellow
#print "Pintando Amarillo"
break
elif 0.4 < k < 0.6 :
self.y[i,j] = greenyellow
#print "Pintando AmarilloVerde"
break
elif k > 0.6 :
self.y[i,j] = green
#print "Pintando Verde"
break
else:
self.y[i,j] = black
#print "Negro"
break
#Print Imagen resultante
print(self.y)
#Guardar Imagen
cv2.imwrite('NDVI.jpg',self.y)
#Mostrar Imagen
ndvi = Image.fromarray(self.y,'RGB').resize((570,650), Image.ANTIALIAS)
# convierte a formato ImageTk
ndvi = ImageTk.PhotoImage(ndvi)
# Ajuste de la imagen de hsv a tk etiqueta de imagen
self.original_img_lbl.configure(image=ndvi)
# adding a reference to the image to Prevent python's garbage collection from deleting it
#Anadiendo una referencia a la imagen para evitar que python garbage collection lo elimine
self.original_img_lbl.image = ndvi
画像オリジナル URL = http://es.zimagez.com/zimage/capturadepantallade2016-12-2310-08-43.php
起訴 URL = http://es.zimagez.com/zimage/capturadepantallade2016-12-2310-09-33.php
NDVI URL = http://es.zimagez.com/zimage/capturadepantallade2016-12-2310-09-40.php
印刷self.y
[[[ 4 111 255]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
[[ 4 111 255]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
[[ 4 111 255]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
...,
[[ 4 255 173]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
[[ 4 255 173]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]
[[ 4 255 173]
[ 0 0 0]
[ 0 0 0]
...,
[ 0 0 0]
[ 0 0 0]
[ 0 0 0]]]
[[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]
...,
[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]
...,
[0 0 0]
[0 0 0]
[0 0 0]]]
NDVIイメージが URLを保存した= http://es.zimagez.com/zimage/ndvi.php
素晴らしい、thaks http://es.zimagez.com/zimage/capturadepantallade2016-12-2312-25-39.php –