使用Python,我必须:
Test_Image
和Reference_image
成5×5块,image1(1,1)
使用image2(1,1)
。到目前为止,我已经使用以下方法计算了整个图像的直方图 hist=numpy.histogram(image,bins=256)
我想分割图像,然后为所有这些块计算直方图。我也想使用巴塔查亚的系数来衡量相似度。
谁能指导我完成这一过程?提前致谢 :)
不知道您是否正在寻找这样的东西,这是蛮力的版本。它可能很慢。但是它确实起作用。您必须决定如何处理边界。除非窗口正好适合,否则这将不包括边界
import numpy as numpy
grey_levels = 256
# Generate a test image
test_image = numpy.random.randint(0,grey_levels, size=(11,11))
# Define the window size
windowsize_r = 5
windowsize_c = 5
# Crop out the window and calculate the histogram
for r in range(0,test_image.shape[0] - windowsize_r, windowsize_r):
for c in range(0,test_image.shape[1] - windowsize_c, windowsize_c):
window = test_image[r:r+windowsize_r,c:c+windowsize_c]
hist = numpy.histogram(window,bins=grey_levels)
以下是结果,完整图像位于末尾。r,c代表视窗的左上角
r=0,c=0
[[ 63 173 131 205 239]
[106 37 156 48 81]
[ 85 85 119 60 228]
[236 79 247 1 206]
[ 97 50 117 96 206]]
r=0,c=5
[[108 241 155 214 183]
[202 2 236 183 225]
[214 141 1 185 115]
[ 4 234 249 95 67]
[232 217 116 211 24]]
r=5,c=0
[[179 155 41 47 190]
[159 69 211 41 92]
[ 64 184 187 104 245]
[190 199 71 228 166]
[117 56 92 5 186]]
r=5,c=5
[[ 68 6 69 63 242]
[213 133 139 59 44]
[236 69 148 196 215]
[ 41 228 198 115 107]
[109 236 191 48 53]]
[[ 63 173 131 205 239 108 241 155 214 183 42]
[106 37 156 48 81 202 2 236 183 225 4]
[ 85 85 119 60 228 214 141 1 185 115 80]
[236 79 247 1 206 4 234 249 95 67 203]
[ 97 50 117 96 206 232 217 116 211 24 242]
[179 155 41 47 190 68 6 69 63 242 162]
[159 69 211 41 92 213 133 139 59 44 196]
[ 64 184 187 104 245 236 69 148 196 215 91]
[190 199 71 228 166 41 228 198 115 107 82]
[117 56 92 5 186 109 236 191 48 53 65]
[177 170 114 163 101 54 80 25 112 35 85]]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句