我要测量图像的平均像素强度和色彩。为此,我采用了这种方法(如果有其他方法,请告诉我):
a)计算平均像素强度:
im = Image.open('images-16.jpeg')
stat = ImageStat.Stat(im)
r,g,b = stat.mean
mean = sqrt(0.241* (r ** 2) + 0.691* (g ** 2) + 0.068* (b ** 2))
print(mean)
b)测量色度:
将颜色空间分成64个立方块,每个维度有四个相等的分区
w,h=im.size
bw,bh = 8, 8 #block size
img = np.array(im)
sz = img.itemsize
shape = (h-bh+1, w-bw+1, bh, bw)
strides = (w*sz, sz, w*sz, sz)
blocks = np.lib.stride_tricks.as_strided(img, shape=shape, strides=strides)
print (blocks[1,1])
计算每个立方体的几何中心Ci之间的欧几里德距离
Not able to compute (say d(a,b)=rgb(Ca)-rgb(Cb))
分布D1被生成为假设图像的颜色分布,使得对于64个采样点中的每一个,频率为1/64-
pixels = im.load()
all_pixels = []
for x in range(218): #put your block width size
for y in range(218): #your block heigh size
cpixel = pixels[x, y]
all_pixels.append(cpixel)
分布D2由给定图像计算,方法是找到64个立方体中每个立方体中出现颜色的频率How can i do this?
Earth Mover's Distance: (D1,D2,d(a,b))
-d(a,b)在上面计算这样做对吗?有什么支持文件来实现这一点?感谢您对代码的任何帮助。谢谢。在
你需要pyemd库。在
相关问题 更多 >
编程相关推荐