-
Notifications
You must be signed in to change notification settings - Fork 0
/
otsu_threshold_median.py
38 lines (30 loc) · 1.06 KB
/
otsu_threshold_median.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
Created on Tue Nov 13 21:23:05 2018
@author: pjh523
"""
import gwy
import os
from functions.pygwy_functions import (
threshold_otsu_median,
get_relative_value,
create_mask,
set_mask_colour,
)
plugin_menu = "/Grains/Mark by Otsu's (Median)"
plugin_type = "PROCESS"
plugin_desc = """Mark grains in datafield by Otsu's method with a median descriptor."""
def run():
# get current data and correct container for file
_id = gwy.gwy_app_data_browser_get_current(gwy.APP_DATA_FIELD_ID)
container = gwy.gwy_app_data_browser_get_current(gwy.APP_CONTAINER)
# create undo point
gwy.gwy_undo_qcheckpoint(container, container.keys())
# get datafield and compute threshold
datafield = container.get_object(gwy.gwy_app_get_data_key_for_id(_id))
threshold = threshold_otsu_median(datafield)
# create grain mask
grains = create_mask(datafield, threshold)
# add mask field to container
container.set_object(gwy.gwy_app_get_mask_key_for_id(_id), grains)
# set mask colour and opacity
set_mask_colour(container, _id)