Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit e6fe7b3

Browse files
committed
pkg relative imports
* update docs * explaining constants * freeze packages for Py2 * fix ransac_segm
1 parent 6419217 commit e6fe7b3

21 files changed

+167
-94
lines changed

MANIFEST.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ include LICENSE
1111

1212
# Include the Requirements
1313
include requirements.txt
14-
exclude requirements-*.txt
1514

1615
# Include package
1716
recursive-include imsegm *.py *.pyx

experiments_ovary_centres/run_center_evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def load_center_evaluate(idx_row, df_annot, path_annot, path_visu=None,
156156
return dict_row
157157

158158
assert all(c in df_annot.columns for c in tl_visu.COLUMNS_POSITION_EGG_ANNOT), \
159-
'some required columns %s are missing for %s' % \
159+
'some required columns %r are missing for %s' % \
160160
(tl_visu.COLUMNS_POSITION_EGG_ANNOT, df_annot.columns)
161161
mask_eggs = estimate_eggs_from_info(df_annot.loc[idx], img.shape[:2])
162162

experiments_ovary_detect/run_ellipse_annot_match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def select_optimal_ellipse(idx_row, path_dir_csv, overlap_thr=OVERLAP_THRESHOLD)
8383
path_csv = os.path.join(path_dir_csv, row['image_name'] + '.csv')
8484
df_ellipses = pd.read_csv(path_csv, index_col=0)
8585

86-
pos = row[tl_visu.COLUMNS_POSITION_EGG_ANNOT]
86+
pos = row[list[tl_visu.COLUMNS_POSITION_EGG_ANNOT]]
8787
max_size = 2 * max(pos) + min(pos)
8888

8989
pos_ant = [[row['ant_x'], row['ant_y']]]

imsegm/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"""
66

77
try:
8-
import imsegm.utilities
9-
imsegm.utilities
8+
from . import utilities
9+
utilities
1010
except ImportError:
1111
import traceback
1212
traceback.print_exc()

imsegm/annotation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
from scipy import interpolate
1616

1717
# sys.path += [os.path.abspath('.'), os.path.abspath('..')] # Add path to root
18-
from imsegm.utilities.data_io import io_imread
18+
from .utilities.data_io import io_imread
1919

20+
#: names of annotated columns
2021
COLUMNS_POSITION = ('ant_x', 'ant_y', 'post_x', 'post_y', 'lat_x', 'lat_y')
2122
SLICE_NAME_GROUPING = 'stack_path'
22-
# set distance in Z axis whether near sliuce may still belong to the same egg
23+
#: set distance in Z axis whether near slice may still belong to the same egg
2324
ANNOT_SLICE_DIST_TOL = { # stage : distance in z-axis
2425
1: 1,
2526
2: 2,
@@ -28,11 +29,11 @@
2829
5: 3,
2930
6: 0,
3031
}
31-
# default colors for particular label
32+
#: default colors for particular label
3233
DICT_COLOURS = {
33-
0: (0, 0, 255),
34-
1: (255, 0, 0),
35-
2: (0, 255, 0),
34+
0: (0, 0, 255), # blue
35+
1: (255, 0, 0), # red
36+
2: (0, 255, 0), # green
3637
3: (255, 229, 0), # yellow
3738
4: (142, 68, 173), # purple
3839
5: (127, 140, 141), # gray

imsegm/classification.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,37 @@
3131
except Exception:
3232
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
3333

34-
from imsegm.labeling import relabel_max_overlap_unique
35-
from imsegm.utilities.experiments import WrapExecuteSequence, nb_workers
34+
from .labeling import relabel_max_overlap_unique
35+
from .utilities.experiments import WrapExecuteSequence, nb_workers
3636

3737
# NAME_FILE_RESULTS = 'results.csv'
38+
#: name template forexporting trained classifier (adding classifier name and version)
3839
TEMPLATE_NAME_CLF = 'classifier_{}.pkl'
40+
#: default (recommended) classifier for supervised segmentation
3941
DEFAULT_CLASSIF_NAME = 'RandForest'
42+
#: default (recommended) clustering for unsupervised segmentation
4043
DEFAULT_CLUSTERING = 'kMeans'
4144
# DEFAULT_MIN_NB_SPL = 25
4245
# nb_workers_CLASSIF_SEARCH = 5
4346
# NB_CLASSIF_SEARCH_ITER = 250
47+
#: file name of exported evaluation on feature quality
4448
NAME_CSV_FEATURES_SELECT = 'feature_selection.csv'
49+
#: exporting partial results about trained classifier
4550
NAME_CSV_CLASSIF_CV_SCORES = 'classif_{}_cross-val_scores-{}.csv'
51+
#: exporting partial results about trained classifier - Receiver Operating Characteristics
4652
NAME_CSV_CLASSIF_CV_ROC = 'classif_{}_cross-val_ROC-{}.csv'
53+
#: exporting partial results about trained classifier - Area Under Curve
4754
NAME_TXT_CLASSIF_CV_AUC = 'classif_{}_cross-val_AUC-{}.txt'
55+
#: default types of computed metrics
4856
METRIC_AVERAGES = ('macro', 'weighted')
57+
#: default computed metrics
4958
METRIC_SCORING = ('f1_macro', 'accuracy', 'precision_macro', 'recall_macro')
50-
# rounding unique features, in case to detail precision
59+
#: rounding unique features, in case to detail precision
5160
ROUND_UNIQUE_FTS_DIGITS = 3
61+
#: default number of workers
5262
NB_WORKERS_SERACH = nb_workers(0.5)
5363

54-
64+
#: mapping of metrics names to used functions
5565
DICT_SCORING = {
5666
'f1': metrics.f1_score,
5767
'accuracy': metrics.accuracy_score,

imsegm/descriptors.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,24 @@
2929
print('descriptors: using pure python libraries')
3030
USE_CYTHON = False
3131

32+
#: define all available statistic computed on superpixels
3233
NAMES_FEATURE_FLAGS = ('mean', 'std', 'energy', 'median', 'meanGrad')
34+
#: define sigmas for Lewen-Malik filter bank
3335
DEFAULT_FILTERS_SIGMAS = (np.sqrt(2), 2, 2 * np.sqrt(2), 4)
36+
#: define small list/range of sigmas for Lewen-Malik filter bank
3437
SHORT_FILTERS_SIGMAS = (np.sqrt(2), 2, 4)
38+
#: define the richest version of computed superpixel features
3539
FEATURES_SET_ALL = {'color': ('mean', 'std', 'energy', 'median', 'meanGrad'),
3640
'tLM': ('mean', 'std', 'energy', 'median', 'meanGrad')}
41+
#: define basic color features for supepixels
3742
FEATURES_SET_COLOR = {'color': ('mean', 'std', 'energy')}
43+
#: define basic texture features (complete LM filter bank) for supepixels
3844
FEATURES_SET_TEXTURE = {'tLM': ('mean', 'std', 'energy')}
45+
#: define basic color features for (small LM filter bank) supepixels
3946
FEATURES_SET_TEXTURE_SHORT = {'tLM_short': ('mean', 'std', 'energy')}
47+
#: define circular diamters for computing label histogram
4048
HIST_CIRCLE_DIAGONALS = (10, 20, 30, 40, 50)
41-
# maxila reposnse is bounded by fix number to preven overflowing
49+
#: maximal response is bounded by fix number to prevent overflowing (for LM filer bank)
4250
MAX_SIGNAL_RESPONSE = 1.e6
4351

4452
# Wavelets:

imsegm/ellipse_fitting.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,21 @@
1010

1111
from skimage.measure import fit as sk_fit
1212
# from skimage.measure.fit import EllipseModel # fix in future skimage>0.13.0
13-
from imsegm.utilities.drawing import ellipse
14-
from imsegm.descriptors import (reduce_close_points, compute_ray_features_segm_2d,
15-
reconstruct_ray_features_2d)
16-
from imsegm.superpixels import (segment_slic_img2d, superpixel_centers,
17-
make_graph_segm_connect_grid2d_conn4)
18-
19-
INIT_MASK_BORDER = 50.
13+
from .utilities.drawing import ellipse
14+
from .descriptors import (
15+
reduce_close_points, compute_ray_features_segm_2d, reconstruct_ray_features_2d)
16+
from .superpixels import (
17+
segment_slic_img2d, superpixel_centers, make_graph_segm_connect_grid2d_conn4)
18+
19+
# INIT_MASK_BORDER = 50.
20+
#: define minimal size of estimated ellipse
2021
MIN_ELLIPSE_DAIM = 25.
22+
#: define maximal Figure size in larger dimension
2123
MAX_FIGURE_SIZE = 14
22-
SEGM_OVERLAP = 0.5
24+
# SEGM_OVERLAP = 0.5 # define transparency for overlapping two images
25+
#: smoothing background with morphological operation
2326
STRUC_ELEM_BG = 15
27+
#: smoothing foreground with morphological operation
2428
STRUC_ELEM_FG = 5
2529

2630

@@ -207,21 +211,21 @@ def ransac_segm(points, model_class, points_all, weights, labels, table_prob,
207211
best_inliers = None
208212

209213
if isinstance(min_samples, float):
210-
if not (0 <= min_samples <= 1):
211-
raise ValueError("`min_samples` as ration must be in range (0, 1)")
214+
if not (0 < min_samples <= 1):
215+
raise ValueError("`min_samples` as ration must be in range (0, 1]")
212216
min_samples = int(min_samples * len(points))
213-
if min_samples < 0:
214-
raise ValueError("`min_samples` must be greater than zero")
217+
if not (0 < min_samples <= len(points)):
218+
raise ValueError("`min_samples` must be in range (0, <nb-samples>]")
215219

216220
if max_trials < 0:
217221
raise ValueError("`max_trials` must be greater than zero")
218222

219-
# make sure points is list and not tuple, so it can be modified below
223+
# make sure points is ndarray and not tuple/list, so it can be modified below
220224
points = np.array(points)
221225

222226
for _ in range(max_trials):
223227
# choose random sample set
224-
random_idxs = np.random.randint(0, len(points), min_samples)
228+
random_idxs = np.random.choice(len(points), min_samples, replace=False)
225229
samples = points[random_idxs]
226230
# for d in points:
227231
# samples.append(d[random_idxs])

imsegm/graph_cuts.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@
1212
from sklearn import metrics, preprocessing
1313
from sklearn import pipeline, cluster, mixture, decomposition
1414

15-
from imsegm.utilities.drawing import (
15+
from .utilities.drawing import (
1616
draw_graphcut_unary_cost_segments, draw_graphcut_weighted_edges, draw_color_labeling)
17-
from imsegm.superpixels import (
17+
from .superpixels import (
1818
make_graph_segm_connect_grid2d_conn4, make_graph_segm_connect_grid3d_conn6, superpixel_centers)
19-
from imsegm.descriptors import compute_selected_features_img2d
19+
from .descriptors import compute_selected_features_img2d
2020

21+
#: define munber of iteration in Grap-Cut optimization
2122
DEFAULT_GC_ITERATIONS = 25
22-
COEF_INT_CONVERSION = 1e6
23-
DEBUG_NB_SHOW_SAMPLES = 15
23+
# COEF_INT_CONVERSION = 1e6
24+
# DEBUG_NB_SHOW_SAMPLES = 15
25+
#: define minimal value of unary (being a class) term in Graph-Cut
2426
MIN_UNARY_PROB = 0.01
27+
#: define maximal value of parwise (smoothness) term in Graph-Cut
2528
MAX_PAIRWISE_COST = 1e5
26-
# max is this value and min is inverse (1 / val)
29+
#: max is this value and min is inverse (1 / val)
2730
MIN_MAX_EDGE_WEIGHT = 1e3
2831

2932

imsegm/labeling.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from scipy import ndimage
1111
import skimage.segmentation as sk_segm
1212

13-
from imsegm.utilities.data_io import get_image2d_boundary_color
13+
from .utilities.data_io import get_image2d_boundary_color
1414

1515

1616
def neighbour_connect4(seg, label, pos):

0 commit comments

Comments
 (0)