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

Commit 819daf1

Browse files
authored
update Segm (#7)
* add binary metrics * add segm options * add config params @segm * extend color features @segm * export npz GMM @segm * simplify expt. @segm * add illustration * swap orient. CC * update CI & style - codacy
1 parent d1da652 commit 819daf1

32 files changed

+833
-573
lines changed

.shippable.yml

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,68 @@
33
# After changing this file, check it on:
44
# http://yaml-online-parser.appspot.com/
55

6+
build:
7+
# https://github.com/Shippable/support/issues/3873
8+
pre_ci_boot:
9+
# image_name: drydock/u14pytall
10+
image_tag: v5.8.2
11+
ci:
12+
- echo $CI_REPORTS && mkdir -p $CI_REPORTS
13+
- echo $COVERAGE_REPORTS && mkdir -p $COVERAGE_REPORTS
14+
15+
env:
16+
global:
17+
- CI_REPORTS=shippable/testresults
18+
- COVERAGE_REPORTS=shippable/codecoverage
19+
620
language: python
721

822
sudo: true
923

1024
python:
1125
- 2.7
12-
- 3.4
26+
- 3.5
1327

1428
cache: pip
1529

16-
env:
17-
- CI_REPORTS=shippable/testresults COVERAGE_REPORTS=shippable/codecoverage
18-
19-
build:
20-
ci:
21-
- echo $CI_REPORTS && mkdir -p $CI_REPORTS
22-
- echo $COVERAGE_REPORTS && mkdir -p $COVERAGE_REPORTS
23-
2430
before_install:
2531
- apt-get update # --fix-missing
2632
- apt-get install freetype*
2733
- apt-get install python-dev python-tk python3-tk
2834
- apt-get install pkg-config
29-
- pip install --upgrade pip
35+
- pip install --upgrade pip wheel
3036

3137
install:
3238
- root=$PWD
33-
- gcc --version
3439
- mkdir libs
3540
# - cd $root/libs && git clone https://github.com/Borda/pyGCO.git
36-
# - cd $root/libs/pyGCO && pip install -r requirements.txt
37-
# - cd $root/libs/pyGCO && python setup.py install
38-
# - rm -r -f $here/libs/pyGCO
39-
- cd $root
41+
# - cd $root/libs/pyGCO && pip install -r requirements.txt && python setup.py install
42+
# - rm -r -f $root/libs/pyGCO
43+
# - cd $root
4044

4145
- pip install -r requirements.txt
42-
- pip install nose>=1.3.7 coverage codecov pytest>=3.0.5
46+
- pip install "nose>=1.3.7" coverage codecov "pytest>=3.0.5"
4347

4448
script:
4549
- mkdir data && mkdir output && mkdir results
50+
- gcc --version ; python --version ; pip --version ; pwd ; ls -l
4651
- python setup.py build_ext --inplace
4752

4853
# - nosetests -v --with-xunit --xunit-file=$CI_REPORTS/nosetests.xml
4954
- nosetests -v --exe --with-doctest --with-xunit --with-coverage --cover-package=imsegm --xunit-file=$CI_REPORTS/nosetests.xml
5055

5156
# ANNOTATION section
52-
- python handling_annotations/run_image_color_quantization.py -imgs "data_images/drosophila_ovary_slice/segm_rgb/*.png"
53-
- python handling_annotations/run_image_convert_label_color.py -imgs "data_images/drosophila_ovary_slice/segm/*.png" -out data_images/drosophila_ovary_slice/segm_rgb
54-
- python handling_annotations/run_overlap_images_segms.py -imgs "data_images/drosophila_ovary_slice/image/*.jpg" -segs data_images/drosophila_ovary_slice/segm -out results/overlap_ovary_segment
55-
- python handling_annotations/run_segm_annot_inpaint.py -imgs "data_images/drosophila_ovary_slice/segm/*.png" --label 0
56-
- python handling_annotations/run_segm_annot_relabel.py -imgs "data_images/drosophila_ovary_slice/center_levels/*.png" -out results/relabel_center_levels
57+
- python handling_annotations/run_image_color_quantization.py -imgs "./data_images/drosophila_ovary_slice/segm_rgb/*.png"
58+
- python handling_annotations/run_image_convert_label_color.py -imgs "./data_images/drosophila_ovary_slice/segm/*.png" -out ./data_images/drosophila_ovary_slice/segm_rgb
59+
- python handling_annotations/run_overlap_images_segms.py -imgs "./data_images/drosophila_ovary_slice/image/*.jpg" -segs ./data_images/drosophila_ovary_slice/segm -out ./results/overlap_ovary_segment
60+
- python handling_annotations/run_segm_annot_inpaint.py -imgs "./data_images/drosophila_ovary_slice/segm/*.png" --label 0
61+
- python handling_annotations/run_segm_annot_relabel.py -imgs "./data_images/drosophila_ovary_slice/center_levels/*.png" -out ./results/relabel_center_levels
5762

5863
# SEGMENTATION section
5964
- rm -r -f results && mkdir results
6065
- python experiments_segmentation/run_compute_stat_annot_segm.py --visual
61-
- python experiments_segmentation/run_segm_slic_model_graphcut.py --path_config experiments_segmentation/sample_config.json --nb_jobs 1
62-
- python experiments_segmentation/run_segm_slic_classif_graphcut.py --path_config experiments_segmentation/sample_config.json --nb_jobs 1
66+
- python experiments_segmentation/run_segm_slic_model_graphcut.py -i "data_images/drosophila_disc/image/img_[5,6].jpg" -cfg ./experiments_segmentation/sample_config.json --visual
67+
- python experiments_segmentation/run_segm_slic_classif_graphcut.py -l data_images/drosophila_ovary_slice/list_imgs-annot-struct_short.csv -i "data_images/drosophila_ovary_slice/image/insitu41*.jpg" -cfg ./experiments_segmentation/sample_config.json --visual
6368

6469
# CENTER DETECT. section
6570
- rm -r -f results && mkdir results
@@ -89,5 +94,5 @@ after_success:
8994
- python setup.py install
9095

9196
- coverage xml -o $COVERAGE_REPORTS/coverage.xml
92-
- codecov -t 80efed4e-ac2b-4fea-a642-0a8b1c82e1c8
97+
- codecov # public repository on Travis CI
9398
- coverage report

.travis.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,31 @@ sudo: false
1515

1616
python:
1717
- 2.7
18-
- 3.4
18+
# - 3.4 # will be deprecated for pandas
1919
- 3.5
2020
- 3.6
21+
# - "3.7-dev"
2122

2223
# See http://docs.travis-ci.com/user/caching/#pip-cache
2324
cache: pip
2425

2526
before_install:
2627
- pip install --upgrade pip
27-
- mkdir libs
2828

2929
install:
30-
- root=$PWD
30+
- mkdir libs
31+
# - root=$PWD
3132
# - cd $root/libs && git clone https://github.com/Borda/pyGCO.git
32-
# - cd $root/libs/pyGCO && pip install -r requirements.txt
33-
# - cd $root/libs/pyGCO && python setup.py install
34-
# - rm -r -f $here/libs/pyGCO
35-
- cd $root
33+
# - cd $root/libs/pyGCO && pip install -r requirements.txt && python setup.py install
34+
# - rm -r -f $root/libs/pyGCO
35+
# - cd $root
3636

3737
- pip install -r requirements.txt
38-
- pip install nose>=1.3.7 coverage codecov pytest>=3.0.5 codacy-coverage
38+
- pip install "nose>=1.3.7" coverage codecov "pytest>=3.0.5" codacy-coverage
3939

4040
before_script:
4141
- mkdir data && mkdir output && mkdir results
42+
- gcc --version ; python --version ; pip --version ; pwd ; ls -l
4243
- python setup.py build_ext --inplace
4344

4445
script:
@@ -47,9 +48,9 @@ script:
4748
- python setup.py install
4849

4950
after_success:
50-
# - codecov # public repository on Travis CI
51+
- codecov # public repository on Travis CI
5152
# private repository on Travis CI
52-
- codecov -t 80efed4e-ac2b-4fea-a642-0a8b1c82e1c8
53+
# - codecov -t 80efed4e-ac2b-4fea-a642-0a8b1c82e1c8
5354
- coverage xml
5455
- python-codacy-coverage -r coverage.xml
5556
- coverage report

README.md

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -121,81 +121,98 @@ We introduce some useful tools for work with image annotation and segmentation.
121121
* **Quantization:** in case you have some smooth color labeling in your images you can remove them with following quantization script.
122122
```bash
123123
python handling_annotations/run_image_color_quantization.py \
124-
-imgs "data_images/drosophila_ovary_slice/segm_rgb/*.png" \
124+
-imgs "./data_images/drosophila_ovary_slice/segm_rgb/*.png" \
125125
-m position -thr 0.01 --nb_jobs 2
126126
```
127127
* **Paint labels:** concerting image labels into colour space and other way around.
128128
```bash
129129
python handling_annotations/run_image_convert_label_color.py \
130-
-imgs "data_images/drosophila_ovary_slice/segm/*.png" \
131-
-out data_images/drosophila_ovary_slice/segm_rgb
130+
-imgs "./data_images/drosophila_ovary_slice/segm/*.png" \
131+
-out ./data_images/drosophila_ovary_slice/segm_rgb
132132
```
133133
* **Visualisation:** having input image and its segmentation we can use simple visualisation which overlap the segmentation over input image.
134134
```bash
135135
python handling_annotations/run_overlap_images_segms.py \
136-
-imgs "data_images/drosophila_ovary_slice/image/*.jpg" \
137-
-segs data_images/drosophila_ovary_slice/segm \
138-
-out results/overlap_ovary_segment
136+
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
137+
-segs ./data_images/drosophila_ovary_slice/segm \
138+
-out ./results/overlap_ovary_segment
139139
```
140140
* **Inpainting** selected labels in segmentation.
141141
```bash
142142
python handling_annotations/run_segm_annot_inpaint.py \
143-
-imgs "data_images/drosophila_ovary_slice/segm/*.png" \
143+
-imgs "./data_images/drosophila_ovary_slice/segm/*.png" \
144144
--label 4
145145
```
146146
* **Replace labels:** change labels in input segmentation into another set of lables in 1:1 schema.
147147
```bash
148148
python handling_annotations/run_segm_annot_relabel.py \
149-
-out results/relabel_center_levels \
149+
-out ./results/relabel_center_levels \
150150
--label_old 2 3 --label_new 1 1
151151
```
152152

153153

154154
### Structure segmentation
155155

156156
We utilize (un)supervised segmentation according to given training examples or some expectations.
157+
![vusial debug](figures/visual_img_43_debug.jpg)
157158

158159
* Evaluate superpixels (with given SLIC parameters) quality against given segmentation. It helps find out best SLIC configuration.
159160
```bash
160161
python experiments_segmentation/run_eval_superpixels.py \
161-
-imgs "data_images/drosophila_ovary_slice/image/*.jpg" \
162-
-segm "data_images/drosophila_ovary_slice/annot_eggs/*.png" \
162+
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
163+
-segm "./data_images/drosophila_ovary_slice/annot_eggs/*.png" \
163164
--img_type 2d_split \
164-
--slic_size 20 --slic_regul 0.25 --slico 0
165+
--slic_size 20 --slic_regul 0.25 --slico
165166
```
166167
* Perform **Unsupervised** segmentation in images given in CSV
167168
```bash
168169
python experiments_segmentation/run_segm_slic_model_graphcut.py \
169-
-l data_images/langerhans_islets/list_lang-isl_imgs-annot.csv -i "" \
170-
--path_config experiments_segmentation/sample_config.json \
171-
-o results -n langIsl --nb_classes 3 --visual --nb_jobs 2
170+
-l ./data_images/langerhans_islets/list_lang-isl_imgs-annot.csv -i "" \
171+
--cdf experiments_segmentation/sample_config.json \
172+
-o ./results -n langIsl --nb_classes 3 --visual --nb_jobs 2
172173
```
173-
OR specified on particuler path:
174+
OR specified on particular path:
174175
```bash
175176
python experiments_segmentation/run_segm_slic_model_graphcut.py \
176-
-l "" -i "data_images/langerhans_islets/image/*.jpg" \
177-
--path_config experiments_segmentation/sample_config.json \
178-
-o results -n langIsl --nb_classes 3 --visual --nb_jobs 2
177+
-l "" -i "./data_images/langerhans_islets/image/*.jpg" \
178+
-cfg ./experiments_segmentation/sample_config.json \
179+
-o ./results -n langIsl --nb_classes 3 --visual --nb_jobs 2
179180
```
181+
![unsupervised](figures/imag-disk-20_gmm.jpg)
180182
* Perform **Supervised** segmentation with afterwards evaluation.
181183
```bash
182184
python experiments_segmentation/run_segm_slic_classif_graphcut.py \
183-
-l data_images/drosophila_ovary_slice/list_imgs-annot-struct.csv \
184-
-i "data_images/drosophila_ovary_slice/image/*.jpg" \
185-
--path_config experiments_segmentation/sample_config.json \
186-
-o results -n Ovary --img_type 2d_split --visual --nb_jobs 2
185+
-l ./data_images/drosophila_ovary_slice/list_imgs-annot-struct.csv \
186+
-i "./data_images/drosophila_ovary_slice/image/*.jpg" \
187+
--path_config ./experiments_segmentation/sample_config.json \
188+
-o ./results -n Ovary --img_type 2d_split --visual --nb_jobs 2
187189
```
190+
![supervised](figures/imag-disk-20_train.jpg)
188191
* For both experiment you can evaluate segmentation results.
189192
```bash
190193
python experiments_segmentation/run_compute-stat_annot-segm.py \
191-
-annot "data_images/drosophila_ovary_slice/annot_struct/*.png" \
192-
-segm "results/experiment_segm-supervise_ovary/*.png" \
193-
-img "data_images/drosophila_ovary_slice/image/*.jpg" \
194-
-out results/evaluation
194+
-annot "./data_images/drosophila_ovary_slice/annot_struct/*.png" \
195+
-segm "./results/experiment_segm-supervise_ovary/*.png" \
196+
-img "./data_images/drosophila_ovary_slice/image/*.jpg" \
197+
-out ./results/evaluation
195198
```
196-
197-
![unsupervised](figures/imag-disk-20_gmm.jpg)
198-
![supervised](figures/imag-disk-20_train.jpg)
199+
![vusial](figures/segm-visual_D03_sy04_100x.jpg)
200+
201+
The previous two (un)segmentation accept [configuration file](experiments_segmentation/sample_config.json) (JSON) by parameter `-cfg` with some extra parameters which was not passed in arguments, for instance:
202+
```json
203+
{
204+
"slic_size": 35,
205+
"slic_regul": 0.2,
206+
"features": {"color_hsv": ["mean", "std", "eng"]},
207+
"classif": "SVM",
208+
"nb_classif_search": 150,
209+
"gc_edge_type": "model",
210+
"gc_regul": 3.0,
211+
"run_LOO": false,
212+
"run_LPO": true,
213+
"cross_val": 0.1
214+
}
215+
```
199216

200217
### Center detection and ellipse fitting
201218

@@ -210,18 +227,18 @@ In general, the input is a formatted list (CSV file) of input images and annotat
210227
1. With zone annotation, we train a classifier for center candidate prediction. The annotation can be a CSV file with annotated centers as points, and the zone of positive examples is set uniformly as the circular neighborhood around these points. Another way (preferable) is to use annotated image with marked zones for positive, negative and neutral examples.
211228
```bash
212229
python experiments_ovary_centres/run_center_candidate_training.py -list none \
213-
-segs "data_images/drosophila_ovary_slice/segm/*.png" \
214-
-imgs "data_images/drosophila_ovary_slice/image/*.jpg" \
215-
-centers "data_images/drosophila_ovary_slice/center_levels/*.png" \
216-
-out results -n ovary
230+
-segs "./data_images/drosophila_ovary_slice/segm/*.png" \
231+
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
232+
-centers "./data_images/drosophila_ovary_slice/center_levels/*.png" \
233+
-out ./results -n ovary
217234
```
218235
1. Having trained classifier we perfom center prediction composed from two steps: i. center candidate clustering and candidate clustering.
219236
```bash
220237
python experiments_ovary_centres/run_center_prediction.py -list none \
221-
-segs "data_images/drosophila_ovary_slice/segm/*.png" \
222-
-imgs "data_images/drosophila_ovary_slice/image/*.jpg" \
223-
-centers results/detect-centers-train_ovary/classifier_RandForest.pkl \
224-
-out results -n ovary
238+
-segs "./data_images/drosophila_ovary_slice/segm/*.png" \
239+
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
240+
-centers ./results/detect-centers-train_ovary/classifier_RandForest.pkl \
241+
-out ./results -n ovary
225242
```
226243
1. Assuming you have an expert annotation you can compute static such as missed eggs.
227244
```bash
@@ -271,13 +288,13 @@ python setup.py install
271288
```bash
272289
python experiments_ovary_detect/run_RG2Sp_estim_shape-models.py \
273290
-annot "~/Medical-drosophila/egg_segmentation/mask_2d_slice_complete_ind_egg/*.png" \
274-
-out data -nb 15
291+
-out ./data_images -nb 15
275292
```
276293
1. Run several segmentation techniques on each image.
277294
```bash
278295
python experiments_ovary_detect/run_ovary_egg-segmentation.py \
279-
-list data_images/drosophila_ovary_slice/list_imgs-segm-center-points.csv \
280-
-out output -n ovary_image --nb_jobs 1 \
296+
-list ./data_images/drosophila_ovary_slice/list_imgs-segm-center-points.csv \
297+
-out ./results -n ovary_image --nb_jobs 1 \
281298
-m ellipse_moments \
282299
ellipse_ransac_mmt \
283300
ellipse_ransac_crit \
@@ -289,16 +306,16 @@ python setup.py install
289306
rg2sp_GC-mixture \
290307
watershed_morph
291308
```
292-
1. Evaluate your segmentation results to expert annotation.
309+
1. Evaluate your segmentation ./results to expert annotation.
293310
```bash
294311
python experiments_ovary_detect/run_ovary_segm_evaluation.py --visual
295312
```
296313
1. In the end, cut individual segmented objects comes as minimal bounding box.
297314
```bash
298315
python experiments_ovary_detect/run_cut_segmented_objects.py \
299-
-annot "data_images/drosophila_ovary_slice/annot_eggs/*.png" \
300-
-img "data_images/drosophila_ovary_slice/segm/*.png" \
301-
-out results/cut_images --padding 50
316+
-annot "./data_images/drosophila_ovary_slice/annot_eggs/*.png" \
317+
-img "./data_images/drosophila_ovary_slice/segm/*.png" \
318+
-out ./results/cut_images --padding 50
302319
```
303320
1. Finally, performing visualisation of segmentation results toghter with expert annotation.
304321
```bash

0 commit comments

Comments
 (0)