我想读取.tif文件并计算图像中像素的数量并确定对象的密度,但是当我尝试这个y, x = np.indices(image.shape)
时,它会给我在python中读取像素:“ValueError太多值来解压缩”
Value Error (ValueError: too many values to unpack, File "<stdin>", line 1, in <module>).
我的代码如下:
import sys
import os
import numpy as np
from pylab import *
import scipy
import matplotlib.pyplot as plt
import math
#Function
def radial_plot(image):
y, x = np.indices(image.shape) # <----- Problem here???
center = np.array([(x.max()-x.min())/2.0, (x.max()-x.min())/2.0])
r = np.hypot(x - center[0], y - center[1])
ind = np.argsort(r.flat)- center[1])
r_sorted = r.flat[ind]
i_sorted = image.flat[ind]
r_int = r_sorted.astype(int)
deltar = r_int[1:] - r_int[:-1]
rind = np.where(deltar)[0]
nr = rind[1:] - rind[:-1]
csim = np.cumsum(i_sorted, dtype=float)
tbin = csim[rind[1:]] - csim[rind[:-1]]
radial_prof = tbin/nr
return rad
#Main
img = plt.imread('dat.tif')
radial_plot(img)
您使用的是什么版本的Python? – wnnmaw
嗨wnnmaw:我正在使用Python 2.7.5 –