mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-08 21:03:45 +08:00
fix 8bit-16bit discepencies
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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__':
|
||||
|
||||
Reference in New Issue
Block a user