fix 8bit-16bit discepencies

This commit is contained in:
Olivier Debeir
2012-10-11 12:13:01 +02:00
parent 42feb70a31
commit b208060cdf
2 changed files with 7 additions and 10 deletions
+3 -3
View File
@@ -35,7 +35,7 @@ cdef inline np.uint16_t kernel_autolevel(int* histo, float pop, np.uint16_t g,in
break
delta = imax-imin
if delta>0:
return <np.uint16_t>(maxbin*1.*(g-imin)/delta)
return <np.uint16_t>(1.*(maxbin-1)*(g-imin)/delta)
else:
return <np.uint16_t>(imax-imin)
@@ -59,7 +59,7 @@ cdef inline np.uint16_t kernel_equalize(int* histo, float pop, np.uint16_t g,int
if i>=g:
break
return <np.uint16_t>((maxbin*1.*sum)/pop)
return <np.uint16_t>(((maxbin-1)*sum)/pop)
else:
return <np.uint16_t>(0)
@@ -107,7 +107,7 @@ cdef inline np.uint16_t kernel_meansubstraction(int* histo, float pop, np.uint16
if pop:
for i in range(maxbin):
mean += histo[i]*i
return <np.uint16_t>((g-mean/pop)/2.+midbin)
return <np.uint16_t>((g-mean/pop)/2.+(midbin-1))
else:
return <np.uint16_t>(0)
+4 -7
View File
@@ -108,19 +108,16 @@ class TestSequenceFunctions(unittest.TestCase):
# filters applied on 8bit image ore 16bit image (having only real 8bit of dynamic) should be identical
i8 = data.camera()
i16 = i8.astype(np.uint16)
assert (i8==i16).all()
methods = ['autolevel','bottomhat','equalize','gradient','maximum','mean'
,'meansubstraction','median','minimum','modal','morph_contr_enh','pop','threshold', 'tophat']
for method in methods:
func = eval('rank.%s'%method)
print func
f8 = func(i8,disk(3))
f16 = func(i16,disk(3))
# if (f8==f16).all() is False:
if not (f8==f16).all():
print f8
print f16
assert (f8==f16).all()
if __name__ == '__main__':