Callback error updating image

Hi all,

I have mat files containing data of the PET/CT scans. I use an upload function to load mat files. Then based on the user inputted threshold values function suppose to create a figure and should display the figure using graph. Please note that all the images are as nd array. I tried almost all the methods and I am kind of new to dash.

My original layout worked like this:

html.Div(
                                [

                                    dcc.Graph(
                                        id="image-display-graph",
                                        figure=fig

                                    )
                                ],
                                style={
                                    "grid-column": "1",
                                    "grid-row": "2",
                                    "background-color": DISPLAY_BG_COLOR,
                                },
                            ),

And the callback I was doing:


@app.callback(

    Output('image-display-graph', 'figure'),
    Input('btn_clicks', 'n_clicks'),
    State('hut', 'value'),
    State('suvt', 'value'),
    State('upload_file', 'filename')

)

And the function to get the segmented figure I was doing:

def make_seg_image(filename, hu, suvt, btn_clicks):
    data = read_mat(os.path.join('D:\data', filename))
    if 'pt_image' in data:
        ct_image = data['ct_image']
        pt_image = data['pt_image']

        mid_slice_pt = np.round(np.array(pt_image.shape) / 2).astype(int)
        pt_slice = pt_image[:, :, mid_slice_pt[2]]

        mid_slice_ct = np.round(np.array(ct_image.shape) / 2).astype(int)
        ct_slice = ct_image[:, :, mid_slice_ct[2]]

        # ct_segmentation
        threshold_ct_img = ct_slice > hu
        # Apply PET image to CT bone mask
        pet_mask = np.multiply(pt_slice, threshold_ct_img)

        pt_image_suvt = pet_mask > suvt
        fig = px.imshow(pt_image_suvt, animation_frame=0, facet_col=1, binary_string=True)

        return fig

But I am continuously getting callback errors

Hi @iromi

Add the ERROR message to understand where the problem is.

Hi, I got this error

Callback error updating image-display-graph.figure

TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’

## Traceback (most recent call last)

*** #### File “C:\Users\Iromi\anaconda3\envs\tensorflow_GPU\Lib\ntpath.py”, line 91 , in join**

for p in map(os.fspath, paths):

*** During handling of the above exception, another exception occurred:**

*** #### File “C:\Users\Iromi\anaconda3\envs\tensorflow_GPU\Lib\genericpath.py”, line 152 , in _check_arg_types**

raise TypeError(f’{funcname}() argument must be str, bytes, or '

> TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’

Traceback (most recent call last):
** File “C:\Users\Iromi\anaconda3\envs\tensorflow_GPU\Lib\ntpath.py”, line 91, in join**
** for p in map(os.fspath, paths):**
TypeError: expected str, bytes or os.PathLike object, not int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
** File “C:\Users\Iromi\anaconda3\envs\tensorflow_GPU\Lib\genericpath.py”, line 152, in _check_arg_types**
** raise TypeError(f’{funcname}() argument must be str, bytes, or '**
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'int’

Thanks

Hi,

If make_seg_image is your callback, then the arguments order is wrong and filename is the click counter (that’s why os.path.join is complaining about an int type).

The signature should be make_seg_image(btn_clicks, hu, suvt, filename).

Hi,

Thanks for the reply. I make it correct. Now there are no errors. But still, the image is not showing.

Thanks