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

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
* rename data-images
* add pep8speaks
* move figures
* docs preview
* update config
  • Loading branch information
Borda committed Apr 15, 2020
1 parent 6638613 commit 9a98515
Show file tree
Hide file tree
Showing 202 changed files with 275 additions and 214 deletions.
28 changes: 28 additions & 0 deletions .pep8speaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# File : .pep8speaks.yml

scanner:
diff_only: True # If False, the entire file touched by the Pull Request is scanned for errors. If True, only the diff is scanned.
linter: pycodestyle # Other option is flake8

pycodestyle: # Same as scanner.linter value. Other option is flake8
max-line-length: 110 # Default is 79 in PEP 8
ignore: # Errors and warnings to ignore
- W504 # line break after binary operator
- E402 # module level import not at top of file
- E731 # do not assign a lambda expression, use a def
- C406 # Unnecessary list literal - rewrite as a dict literal.
- E741 # ambiguous variable name

no_blank_comment: True # If True, no comment is made on PR without any errors.
descending_issues_order: False # If True, PEP 8 issues in message will be displayed in descending order of line numbers in the file

message: # Customize the comment made by the bot,
opened: # Messages when a new PR is submitted
header: "Hello @{name}! Thanks for opening this PR. "
# The keyword {name} is converted into the author's username
footer: "Do see the [Hitchhiker's guide to code style](https://goo.gl/hqbW4r)"
# The messages can be written as they would over GitHub
updated: # Messages when new commits are added to the PR
header: "Hello @{name}! Thanks for updating this PR. "
footer: "" # Why to comment the link to the style guide everytime? :)
no_errors: "There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: "
26 changes: 13 additions & 13 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,28 @@ recursive-include experiments_* *.py *.yml
recursive-include handling_annotations *.py

# Include the figures
recursive-include docs/source/_figures *.gif *.jpg *.png
recursive-include assets *.gif *.jpg *.png

# Include the sample images
include data_images/others/lena.png
data_images/synthetic/reference.jpg
data_images/synthetic/texture_rgb_3cls.jpg
data_images/others/sea_starfish-2.jpg
data_images/histology_CIMA/29-041-Izd2-w35-CD31-3-les1.jpg
data_images/histology_Flagship/Case001_Cytokeratin.jpg
data_images/drosophila_disc/image/img_6.jpg
data_images/drosophila_disc/annot/img_6.png
data_images/drosophila_ovary_slice/image/insitu7545.jpg
data_images/drosophila_ovary_slice/annot_struct/insitu7545.png
data_images/langerhans_islets/image/gtExoIsl_21.jpg
include data-images/others/lena.png
data-images/synthetic/reference.jpg
data-images/synthetic/texture_rgb_3cls.jpg
data-images/others/sea_starfish-2.jpg
data-images/histology_CIMA/29-041-Izd2-w35-CD31-3-les1.jpg
data-images/histology_Flagship/Case001_Cytokeratin.jpg
data-images/drosophila_disc/image/img_6.jpg
data-images/drosophila_disc/annot/img_6.png
data-images/drosophila_ovary_slice/image/insitu7545.jpg
data-images/drosophila_ovary_slice/annot_struct/insitu7545.png
data-images/langerhans_islets/image/gtExoIsl_21.jpg

prune .git
prune .github
prune libs
prune venv
prune build
prune docs
prune data_images
prune data-images
prune tests
prune notebooks
prune ij_macros
Expand Down
78 changes: 39 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

## Superpixel segmentation with GraphCut regularisation

Image segmentation is widely used as an initial phase of many image processing tasks in computer vision and image analysis. Many recent segmentation methods use superpixels because they reduce the size of the segmentation problem by order of magnitude. Also, features on superpixels are much more robust than features on pixels only. We use spatial regularisation on superpixels to make segmented regions more compact. The segmentation pipeline comprises (i) computation of superpixels; (ii) extraction of descriptors such as colour and texture; (iii) soft classification, using a standard classifier for supervised learning, or the Gaussian Mixture Model for unsupervised learning; (iv) final segmentation using Graph Cut. We use this segmentation pipeline on real-world applications in medical imaging (see [sample images](data_images/).
Image segmentation is widely used as an initial phase of many image processing tasks in computer vision and image analysis. Many recent segmentation methods use superpixels because they reduce the size of the segmentation problem by order of magnitude. Also, features on superpixels are much more robust than features on pixels only. We use spatial regularisation on superpixels to make segmented regions more compact. The segmentation pipeline comprises (i) computation of superpixels; (ii) extraction of descriptors such as colour and texture; (iii) soft classification, using a standard classifier for supervised learning, or the Gaussian Mixture Model for unsupervised learning; (iv) final segmentation using Graph Cut. We use this segmentation pipeline on real-world applications in medical imaging (see [sample images](data-images/).
We also show that [unsupervised segmentation](notebooks/segment-2d_slic-fts-clust-gc.ipynb) is sufficient for some situations,
and provides similar results to those obtained using [trained segmentation](notebooks/segment-2d_slic-fts-classif-gc.ipynb).

![schema](docs/source/_figures/schema_slic-fts-clf-gc.jpg)
![schema](assets/schema_slic-fts-clf-gc.jpg)

**Sample ipython notebooks:**
* [Supervised segmentation](notebooks/segment-2d_slic-fts-classif-gc.ipynb) requires training annotation
Expand All @@ -30,8 +30,8 @@ Image segmentation is widely used as an initial phase of many image processing t

**Illustration**

![input image](docs/source/_figures/insitu7545.jpg)
![segmentation](docs/source/_figures/insitu7545_gc.png)
![input image](assets/insitu7545.jpg)
![segmentation](assets/insitu7545_gc.png)

Reference: _Borovec J., Svihlik J., Kybic J., Habart D. (2017). **Supervised and unsupervised segmentation using superpixels, model estimation, and Graph Cut.** In: Journal of Electronic Imaging._

Expand All @@ -47,8 +47,8 @@ An image processing pipeline to detect and localize Drosophila egg chambers that

**Illustration**

![estimated centres](docs/source/_figures/insitu7545_center_clusters.jpg)
![ellipse fitting](docs/source/_figures/insitu7545_ellipse_fit.png)
![estimated centres](assets/insitu7545_center_clusters.jpg)
![ellipse fitting](assets/insitu7545_ellipse_fit.png)

Reference: _Borovec J., Kybic J., Nava R. (2017) **Detection and Localization of Drosophila Egg Chambers in Microscopy Images.** In: Machine Learning in Medical Imaging._

Expand All @@ -63,8 +63,8 @@ Region growing is a classical image segmentation method based on hierarchical re

**Illustration**

![growing RG](docs/source/_figures/insitu7545_RG2SP_animation.gif)
![ellipse fitting](docs/source/_figures/insitu7545_RG2SP-gc-mm.png)
![growing RG](assets/insitu7545_RG2SP_animation.gif)
![ellipse fitting](assets/insitu7545_RG2SP-gc-mm.png)

Reference: _Borovec J., Kybic J., Sugimoto, A. (2017). **Region growing using superpixels with learned shape prior.** In: Journal of Electronic Imaging._

Expand Down Expand Up @@ -134,26 +134,26 @@ We introduce some useful tools for work with image annotation and segmentation.
* **Quantization:** in case you have some smooth colour labelling in your images you can remove them with following quantisation script.
```bash
python handling_annotations/run_image_color_quantization.py \
-imgs "./data_images/drosophila_ovary_slice/segm_rgb/*.png" \
-imgs "./data-images/drosophila_ovary_slice/segm_rgb/*.png" \
-m position -thr 0.01 --nb_workers 2
```
* **Paint labels:** concerting image labels into colour space and other way around.
```bash
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
-imgs "./data-images/drosophila_ovary_slice/segm/*.png" \
-out ./data-images/drosophila_ovary_slice/segm_rgb
```
* **Visualisation:** having input image and its segmentation we can use simple visualisation which overlap the segmentation over input image.
```bash
python handling_annotations/run_overlap_images_segms.py \
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
-segs ./data_images/drosophila_ovary_slice/segm \
-imgs "./data-images/drosophila_ovary_slice/image/*.jpg" \
-segs ./data-images/drosophila_ovary_slice/segm \
-out ./results/overlap_ovary_segment
```
* **In-painting** selected labels in segmentation.
```bash
python handling_annotations/run_segm_annot_inpaint.py \
-imgs "./data_images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data-images/drosophila_ovary_slice/segm/*.png" \
--label 4
```
* **Replace labels:** change labels in input segmentation into another set of labels in 1:1 schema.
Expand All @@ -167,50 +167,50 @@ We introduce some useful tools for work with image annotation and segmentation.
### Semantic (un/semi)supervised segmentation

We utilise (un)supervised segmentation according to given training examples or some expectations.
![vusial debug](docs/source/_figures/visual_img_43_debug.jpg)
![vusial debug](assets/visual_img_43_debug.jpg)

* Evaluate superpixels (with given SLIC parameters) quality against given segmentation. It helps to find out the best SLIC configuration.
```bash
python experiments_segmentation/run_eval_superpixels.py \
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
-segm "./data_images/drosophila_ovary_slice/annot_eggs/*.png" \
-imgs "./data-images/drosophila_ovary_slice/image/*.jpg" \
-segm "./data-images/drosophila_ovary_slice/annot_eggs/*.png" \
--img_type 2d_split \
--slic_size 20 --slic_regul 0.25 --slico
```
* Perform **Un-Supervised** segmentation in images given in CSV
```bash
python experiments_segmentation/run_segm_slic_model_graphcut.py \
-l ./data_images/langerhans_islets/list_lang-isl_imgs-annot.csv -i "" \
-l ./data-images/langerhans_islets/list_lang-isl_imgs-annot.csv -i "" \
-cfg experiments_segmentation/sample_config.yml \
-o ./results -n langIsl --nb_classes 3 --visual --nb_workers 2
```
OR specified on particular path:
```bash
python experiments_segmentation/run_segm_slic_model_graphcut.py \
-l "" -i "./data_images/langerhans_islets/image/*.jpg" \
-l "" -i "./data-images/langerhans_islets/image/*.jpg" \
-cfg ./experiments_segmentation/sample_config.yml \
-o ./results -n langIsl --nb_classes 3 --visual --nb_workers 2
```
![unsupervised](docs/source/_figures/imag-disk-20_gmm.jpg)
![unsupervised](assets/imag-disk-20_gmm.jpg)
* Perform **Supervised** segmentation with afterwards evaluation.
```bash
python experiments_segmentation/run_segm_slic_classif_graphcut.py \
-l ./data_images/drosophila_ovary_slice/list_imgs-annot-struct.csv \
-i "./data_images/drosophila_ovary_slice/image/*.jpg" \
-l ./data-images/drosophila_ovary_slice/list_imgs-annot-struct.csv \
-i "./data-images/drosophila_ovary_slice/image/*.jpg" \
--path_config ./experiments_segmentation/sample_config.yml \
-o ./results -n Ovary --img_type 2d_split --visual --nb_workers 2
```
![supervised](docs/source/_figures/imag-disk-20_train.jpg)
![supervised](assets/imag-disk-20_train.jpg)
* Perform **Semi-Supervised** is using the the supervised pipeline with not fully annotated images.
* For both experiment you can evaluate segmentation results.
```bash
python experiments_segmentation/run_compute-stat_annot-segm.py \
-a "./data_images/drosophila_ovary_slice/annot_struct/*.png" \
-a "./data-images/drosophila_ovary_slice/annot_struct/*.png" \
-s "./results/experiment_segm-supervise_ovary/*.png" \
-i "./data_images/drosophila_ovary_slice/image/*.jpg" \
-i "./data-images/drosophila_ovary_slice/image/*.jpg" \
-o ./results/evaluation --visual
```
![vusial](docs/source/_figures/segm-visual_D03_sy04_100x.jpg)
![vusial](assets/segm-visual_D03_sy04_100x.jpg)

The previous two (un)segmentation accept [configuration file](experiments_segmentation/sample_config.yml) (YAML) by parameter `-cfg` with some extra parameters which was not passed in arguments, for instance:
```yaml
Expand Down Expand Up @@ -240,16 +240,16 @@ In general, the input is a formatted list (CSV file) of input images and annotat
1. With zone annotation, we train a classifier for centre candidate prediction. The annotation can be a CSV file with annotated centres as points, and the zone of positive examples is set uniformly as the circular neighbourhood around these points. Another way (preferable) is to use an annotated image with marked zones for positive, negative and neutral examples.
```bash
python experiments_ovary_centres/run_center_candidate_training.py -list none \
-segs "./data_images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
-centers "./data_images/drosophila_ovary_slice/center_levels/*.png" \
-segs "./data-images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data-images/drosophila_ovary_slice/image/*.jpg" \
-centers "./data-images/drosophila_ovary_slice/center_levels/*.png" \
-out ./results -n ovary
```
1. Having trained classifier we perform center prediction composed from two steps: i) center candidate clustering and ii) candidate clustering.
```bash
python experiments_ovary_centres/run_center_prediction.py -list none \
-segs "./data_images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
-segs "./data-images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data-images/drosophila_ovary_slice/image/*.jpg" \
-centers ./results/detect-centers-train_ovary/classifier_RandForest.pkl \
-out ./results -n ovary
```
Expand All @@ -260,8 +260,8 @@ In general, the input is a formatted list (CSV file) of input images and annotat
1. This is just cut out clustering in case you want to use different parameters.
```bash
python experiments_ovary_centres/run_center_clustering.py \
-segs "./data_images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data_images/drosophila_ovary_slice/image/*.jpg" \
-segs "./data-images/drosophila_ovary_slice/segm/*.png" \
-imgs "./data-images/drosophila_ovary_slice/image/*.jpg" \
-centers "./results/detect-centers-train_ovary/candidates/*.csv" \
-out ./results
```
Expand All @@ -286,7 +286,7 @@ In general, the input is a formatted list (CSV file) of input images and annotat
-out ~/Medical-drosophila/RESULTS/atlas_datasets/ovary_images/stage_3
```

![ellipse fitting](docs/source/_figures/insitu7544_ellipses.jpg)
![ellipse fitting](assets/insitu7544_ellipses.jpg)

### Region growing with a shape prior

Expand All @@ -303,12 +303,12 @@ pip install --user git+https://github.com/Borda/morph-snakes.git
```bash
python experiments_ovary_detect/run_RG2Sp_estim_shape-models.py \
-annot "~/Medical-drosophila/egg_segmentation/mask_2d_slice_complete_ind_egg/*.png" \
-out ./data_images -nb 15
-out ./data-images -nb 15
```
1. Run several segmentation techniques on each image.
```bash
python experiments_ovary_detect/run_ovary_egg-segmentation.py \
-list ./data_images/drosophila_ovary_slice/list_imgs-segm-center-points.csv \
-list ./data-images/drosophila_ovary_slice/list_imgs-segm-center-points.csv \
-out ./results -n ovary_image --nb_workers 1 \
-m ellipse_moments \
ellipse_ransac_mmt \
Expand All @@ -328,15 +328,15 @@ pip install --user git+https://github.com/Borda/morph-snakes.git
1. In the end, cut individual segmented objects comes as minimal bounding box.
```bash
python experiments_ovary_detect/run_cut_segmented_objects.py \
-annot "./data_images/drosophila_ovary_slice/annot_eggs/*.png" \
-img "./data_images/drosophila_ovary_slice/segm/*.png" \
-annot "./data-images/drosophila_ovary_slice/annot_eggs/*.png" \
-img "./data-images/drosophila_ovary_slice/segm/*.png" \
-out ./results/cut_images --padding 50
```
1. Finally, performing visualisation of segmentation results together with expert annotation.
```bash
python experiments_ovary_detect/run_export_user-annot-segm.py
```
![user-annnot](docs/source/_figures/insitu7545_user-annot-segm.jpg)
![user-annnot](assets/insitu7545_user-annot-segm.jpg)

---

Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 5 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ jobs:
- *install_pips
# DOCUMENTATION
- *make_docs
# PREVIEW
- store_artifacts:
# allows us to preview the generated html pages
path: docs/build/html/
destination: html

workflows:
version: 2
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
11 changes: 11 additions & 0 deletions data-images/drosophila_disc/list_imaginal-disks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
,path_image,path_annot
1,data-images/drosophila_disc/image/img_5.jpg,data-images/drosophila_disc/annot/img_5.png
2,data-images/drosophila_disc/image/img_6.jpg,data-images/drosophila_disc/annot/img_6.png
3,data-images/drosophila_disc/image/img_12.jpg,data-images/drosophila_disc/annot/img_12.png
4,data-images/drosophila_disc/image/img_14.jpg,data-images/drosophila_disc/annot/img_14.png
5,data-images/drosophila_disc/image/img_15.jpg,data-images/drosophila_disc/annot/img_15.png
6,data-images/drosophila_disc/image/img_19.jpg,data-images/drosophila_disc/annot/img_19.png
7,data-images/drosophila_disc/image/img_20.jpg,data-images/drosophila_disc/annot/img_20.png
8,data-images/drosophila_disc/image/img_24.jpg,data-images/drosophila_disc/annot/img_24.png
9,data-images/drosophila_disc/image/img_26.jpg,data-images/drosophila_disc/annot/img_26.png
10,data-images/drosophila_disc/image/img_43.jpg,data-images/drosophila_disc/annot/img_43.png
3 changes: 3 additions & 0 deletions data-images/drosophila_disc/list_imaginal-disks_short.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
,path_image,path_annot
1,data-images/drosophila_disc/image/img_6.jpg,data-images/drosophila_disc/annot/img_6.png
2,data-images/drosophila_disc/image/img_43.jpg,data-images/drosophila_disc/annot/img_43.png
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions data-images/drosophila_ovary_slice/list_imgs-annot-struct.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
,path_image,path_annot
1,data-images/drosophila_ovary_slice/image/insitu4174.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu4174.png
2,data-images/drosophila_ovary_slice/image/insitu4358.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu4358.png
3,data-images/drosophila_ovary_slice/image/insitu7331.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu7331.png
4,data-images/drosophila_ovary_slice/image/insitu7544.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu7544.png
5,data-images/drosophila_ovary_slice/image/insitu7545.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu7545.png
6,data-images/drosophila_ovary_slice/image/insitu4174.tif,data-images/drosophila_ovary_slice/annot_struct/insitu4174.png
7,data-images/drosophila_ovary_slice/image/insitu4358.tif,data-images/drosophila_ovary_slice/annot_struct/insitu4358.png
8,data-images/drosophila_ovary_slice/image/insitu7331.tif,data-images/drosophila_ovary_slice/annot_struct/insitu7331.png
9,data-images/drosophila_ovary_slice/image/insitu7544.tif,data-images/drosophila_ovary_slice/annot_struct/insitu7544.png
10,data-images/drosophila_ovary_slice/image/insitu7545.tif,data-images/drosophila_ovary_slice/annot_struct/insitu7545.png
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
,path_image,path_annot
1,data_images/drosophila_ovary_slice/image/insitu4174.jpg,data_images/drosophila_ovary_slice/annot_struct/insitu4174.png
2,data_images/drosophila_ovary_slice/image/insitu7545.tif,data_images/drosophila_ovary_slice/annot_struct/insitu7545.png
1,data-images/drosophila_ovary_slice/image/insitu4174.jpg,data-images/drosophila_ovary_slice/annot_struct/insitu4174.png
2,data-images/drosophila_ovary_slice/image/insitu7545.tif,data-images/drosophila_ovary_slice/annot_struct/insitu7545.png
Loading

0 comments on commit 9a98515

Please sign in to comment.