scikit-image filters frangi produces wrong results
Description:
For quite some time (see report #7403) the output of Frangi filter is wrong. Most likely, the Hessian matrix elements are not scaled according to the scale (aka sigma). The scaling was present in 0.19.3:
but I don't see in 0.25.1 where the Hessian is simply plugged into the eigvalues method w/o scaling:
Please see two test below done with version 0.19.3 (the elongated black feature is highlighted: correct output) and 0.25.1 (scale maximization doesn't seem to work anymore and the filter works as some sort of edge detector):
Due to the missing scale corrections only the smallest scale affects the filter output. Please see the code below to reproduce my tests.
Way to reproduce:
import numpy as np import math from matplotlib import pyplot as plt from skimage.draw import disk
from skimage.filters import frangi
IMAGE_H = 300 IMAGE_W = 200
MIN_S = 1.0 MAX_S = 12.0 AMPL = 15.0
Y_OFFS = 20
img_array = np.ones(shape = (IMAGE_H, IMAGE_W), dtype = np.float32)
for y in range(Y_OFFS, IMAGE_H-Y_OFFS) : lam = (y-Y_OFFS)/(IMAGE_H-2Y_OFFS) x = 0.5IMAGE_W + AMPLmath.sin(lam5*math.pi)
if y < 0.5*IMAGE_H :
lam = (y-Y_OFFS)/(0.5*IMAGE_H-Y_OFFS)
else :
lam = 1 - (y-0.5*IMAGE_H)/(0.5*IMAGE_H-Y_OFFS)
rad = MAX_S*lam + (1-lam)*MIN_S
x1 = int(x-rad)
x2 = int(x+rad)
img_array[y,x1:x2] = 0.0rr,cc = disk((25,50), 15) img_array[rr,cc] = 0.0
rr,cc = disk((IMAGE_H-25,IMAGE_W-50), 15) img_array[rr,cc] = 0.0
ridge_image = frangi(img_array, sigmas = np.array([2, 5, 10, 15, 25]), beta = 0.3, gamma = 1.0)
fig = plt.figure(figsize=(10, 8))
ax1 = fig.add_subplot(1,2,1)
ax1.imshow(img_array, cmap='gray', interpolation='none', origin = 'lower')
ax2 = fig.add_subplot(1,2,2)
ax2.imshow(ridge_image, cmap = 'gray', interpolation='none', origin = 'lower')
plt.show()
Version information:
Python 3.11.11 | packaged by conda-forge | (main, Dec 5 2024, 14:06:23) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys; print(sys.version)
3.11.11 | packaged by conda-forge | (main, Dec 5 2024, 14:06:23) [MSC v.1942 64 bit (AMD64)]
>>> import platform; print(platform.platform())
Windows-10-10.0.19045-SP0
>>> import skimage; print(f'scikit-image version: {skimage.__version__}')
scikit-image version: 0.25.1
>>> import numpy; print(f'numpy version: {numpy.__version__}')Source: scikit-image/scikit-image