Skip to content

Commit

Permalink
added median filter widget
Browse files Browse the repository at this point in the history
  • Loading branch information
RoccoDAnt committed Dec 10, 2023
1 parent 04480e9 commit 9d1a2ad
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
20 changes: 18 additions & 2 deletions napari_zelda/napari_zelda.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def mock():
"Plot": "results_widget",
"Image Calibration": "image_calibration",
"Morphological Operations":"morphological_operations",
"Filter by Area":"filterByArea_widget"
"Filter by Area":"filterByArea_widget",
"Median Filter":"median_filter"
}

protocols_description=open(os.path.join(prot_path,'napari_zelda','protocols_description.txt'), 'r').read()
Expand Down Expand Up @@ -672,7 +673,7 @@ def new_protocol_widget(viewer: 'napari.Viewer',
np_steps,
Log
):
steps_types = ['Threshold', 'GaussianBlur', 'DistanceMap', 'ShowSeeds', 'Watershed', 'Measure', 'Plot','Image Calibration','Morphological Operations','Filter by Area']
steps_types = ['Threshold', 'GaussianBlur', 'DistanceMap', 'ShowSeeds', 'Watershed', 'Measure', 'Plot','Image Calibration','Morphological Operations','Filter by Area', 'Median Filter']
np_container=Container()
for k in range(0, np_steps):
np_container.insert(k, ComboBox(choices=steps_types, value=steps_types[0], label='Select step '+str(k+1)+':', name='step_'+str(k)+'', tooltip='Choose a function for this step of the custom protocol'))
Expand Down Expand Up @@ -733,6 +734,21 @@ def filterByArea_widget(viewer: 'napari.Viewer',
mask=np.isin(layer.data, filteredAreaValues)
viewer.add_image(layer.data*np.array(mask), scale=layer.scale, name='FilteredByArea_'+str(Area_Min)+'-'+str(Area_Max), opacity=0.6, blending='opaque', colormap='inferno')

@magicgui(labels=False,
label={'widget_type':'Label', 'value':"Median Filter"},
element_size={'widget_type': 'IntSlider', "max": 15, 'min':0},
mode={"choices": ["reflect", "constant", "nearest", "mirror", "wrap"]},
call_button="Apply",
persist=True)
def median_filter(viewer: 'napari.Viewer', label, layer: Image, element_size: int = 1, mode="nearest")-> napari.types.ImageData:
if layer:
if len(layer.data.shape)==2:
selem = skimage.morphology.disk(element_size)
elif len(layer.data.shape)==3:
selem = skimage.morphology.cube(element_size)
median=skimage.filters.median(layer.data, footprint=selem, mode=mode)
viewer.add_image(median, scale=layer.scale, name='Median radius='+str(element_size)+' of '+str(layer.name))

### Add here new functionalities for ZELDA ###
### @magicgui(layout="vertical")
### def new_functionality_widget(viewer: 'napari.Viewer'):
Expand Down
10 changes: 10 additions & 0 deletions napari_zelda/protocols_dict.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
"step_name": "Morphological Operations"
}
]
},
{
"name": "Median Filter",
"widget": "Median Filter_protocol_widget",
"steps": [
{
"step_number": 1,
"step_name": "Median Filter"
}
]
}
]
}
1 change: 1 addition & 0 deletions napari_zelda/protocols_history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Data Plotter
Design a New Protocol
Import and Export Protocols
MorphologicalOperations
Median Filter

0 comments on commit 9d1a2ad

Please sign in to comment.