Image-Py / imagepy

Image process framework based on plugin like imagej, it is esay to glue with scipy.ndimage, scikit-image, opencv, simpleitk, mayavi...and any libraries based on numpy
http://imagepy.org
BSD 4-Clause "Original" or "Old" License
1.29k stars 330 forks source link

Automatic conversion from int to float causes segfault #85

Closed CsatiZoltan closed 4 years ago

CsatiZoltan commented 4 years ago

When I tick the preview checkbox, the para-changed method is invoked. This implicitly converts an int to a float. In the screenshot below you can see that the value for the 'window_size' key in the para dictionary is 5 as an int. However, after executing line 101, the result is a float, as shown in the right window. int-float The error arises in this file: https://github.com/Image-Py/imagepy/blob/c0804fa690d7f0a52acc948b9f17067f7b2c0397/imagepy/ui/panelconfig.py#L101

Code to reproduce:

from imagepy.core.engine import Filter
from scipy.ndimage import median_filter

class FilterImage(Filter):
    title = 'Filter image'
    note = ['all', 'auto_msk', 'auto_snap', 'preview']
    para = {'window_size': 5}
    view = [(int, 'window_size', (0, 30), 1, 'window size', 'pixel')]

    def run(self, ips, snap, img, para=None):
        median_filter(snap, para['window_size'], output=img)

plgs = [FilterImage, '-']

This is almost the same as your Gaussian class, with the exception that I defined an integer. When the median_filter function of scipy.ndimage receives a float, it terminates with a segmentation fault.

yxdragon commented 4 years ago

view = [(int, 'window_size', (0, 30), 1, 'window size', 'pixel')] please use: view = [(int, 'window_size', (0, 30), 0, 'window size', 'pixel')]

for loat, it is the accuracy. I want to keep a same format with the float, so put 0 there.

CsatiZoltan commented 4 years ago

My bad, now it works. Thanks.