Skip to content

Commit fe00770

Browse files
segwrap updated to be compatible with cellpose 0.6.5 (#31)
1 parent a308601 commit fe00770

21 files changed

+177
-297
lines changed

docs/analysis-overview.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
## ImJoy plugins
22
Most of the workflows are implemented as **ImJoy plugins**, with a simple interface to
3-
specify the different workflow parameters. We describe in a dedicated [sections] how to [**use**](imjoy-overview.md) and [**install**](imjoy-installation.md) the **Plugin engine** to run these plugins.
3+
specify the different workflow parameters. We describe in a dedicated [sections] how to [**use**](imjoy-overview.md) and [**install**](imjoy-installation.md) the **Plugin engine** to run these plugins.
44

5-
Once a plugin is installed, it will be available for later use in the ImJoy **workspace `fq-segmentation`** as explained [here](imjoy-overview.md#opening-a-workspace).
5+
Once a plugin is installed, it will be available for later use in the ImJoy **workspace `fq-segmentation`** as explained [here](imjoy-overview.md#opening-a-workspace).
66

77
!!! abstract "Quick summary for how to connect ImJoy to Jupyter engine"
8-
1. Open **anaconda terminal**.
8+
1. Open **anaconda terminal**.
99
2. **Activate environment**: `conda activate fq-segmentation`
1010
3. **Start Jupyter engine**: `imjoy --jupyter`
1111
4. **Connect** ImJoy to Jupyter Engine with 🚀 button.
@@ -15,7 +15,7 @@ We also provide **Jupyter notebooks** for these workflows, which we recommend on
1515
## Typical workflows
1616
For most purposes, the segmentation will consist of two steps. Each of these steps is described in a
1717
dedicated section. In this section you can also find a recommended workflow, which allows you to also
18-
process the test data.
18+
process the test data.
1919

2020
1. **Pre-processing** of the data: segmentation is performed on 2D images. If your images are 3D, you have to either split them, or project them into 2D images. This can be done with the [pre-processing workflow](analysis-preprocessing.md).
2121
2. **Actual segmentation** of your images. We provide different plugins to [**segment**](analysis-segmentation.md). one type of structure, e.g. nuclei or cells, or two, e.g. cells and nuclei.

docs/analysis-preprocessing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Segmentation is performed on **2D images**. This plugin allows to obtain 2D imag
55
a projection or by saving each z-plane separately. These images are typically stored in a separate folder.
66
2D images by applying a projection, and these images are typically stored in a separate folder.
77

8-
Install ImJoy plugin `PreProcess` <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/segmentation:PreProcess@stable&upgrade=1" target="_blank">** from here.**</a>
8+
Install ImJoy plugin `PreProcess` <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/fq-segmentation:PreProcess@stable&upgrade=1" target="_blank">** from here.**</a>
99

1010
## Recommended workflow
1111

docs/analysis-segmentation.md

+14-25
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
We provide different plugins for different segmentation tasks:
44

5-
* Install plugin `SegmentObjects` to segment cells OR nuclei <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/segmentation:SegmentObjects@stable&upgrade=1" target="_blank">**from here.**</a>
6-
* Install plugin `SegmentCellsNuclei` to segment cells AND nuclei <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/segmentation:SegmentCellsNuclei@stable&upgrade=1" target="_blank">**from here.**</a>
5+
* Install plugin `SegmentObjects` to segment cells OR nuclei <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/fq-segmentation:SegmentObjects@stable&upgrade=1" target="_blank">**from here.**</a>
6+
* Install plugin `SegmentCellsNuclei` to segment cells AND nuclei <a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/fq-segmentation:SegmentCellsNuclei@stable&upgrade=1" target="_blank">**from here.**</a>
77

88
## General behavior
99

@@ -21,32 +21,18 @@ By defining the `Input subfolder` to be `segmentation-input`, the analysis will
2121

2222
### Results
2323

24-
Results will be saved in the specified folder. For each image the following files, results files with different suffices are created:
24+
Results will be saved in the specified folder. For each image the following files, results files with different prefixes are created:
2525

26-
* `..._flow`: these are the predicted distance maps of CellPose. They are an intermediate result, and
26+
* `flow_ ...`: these are the predicted distance maps of CellPose. They are an intermediate result, and
2727
not needed for most end-users.
28-
* `..._mask`: these contain the actual segmentation results. Each segmented object is a filled
28+
* `mask_ ...`: these contain the actual segmentation results. Each segmented object is a filled
2929
object with a constant pixel value. If the images were resized during segmentation, the mask is scaled
3030
back up to the original image size. The actually obtained (smaller) mask is saved under the name `mask__rescale_...`.
31-
* `..._segmentation`: summary plot showing the input image, the predicted distance map, and the segmented
31+
* `seg_...`: summary plot showing the input image, the predicted distance map, and the segmented
3232
objects. This plot is also shown in the interface.
3333

3434
![segmentation__nuclei](img/segmentation__nuclei.png)
3535

36-
### Resizing to speed up prediction
37-
38-
Segmentation speed depends on the image size. In our experience, resizing the images
39-
can lead to a substantial speed-up. In case you resize the images, we implemented a post-processing
40-
routine that will resize the predicted masks back to the original image size.
41-
42-
Resizing can be specified in two ways
43-
44-
1. **Scaling factor** recommended]: simply add an integer value. The actual image size will then be divided by this factor
45-
to obtain the new size, i.e. a value of 2 will resize an image 512x512 to 256x256.
46-
2. **New size**: you can directly define the new size of the image, e.g. 256x256. Please note that this size
47-
will be applied to all images, independly of their size. This option is hence not suitable if your data-sets
48-
contain differently sized images.
49-
5036
## Recommended workflow
5137

5238
The default settings of the plugins allow to quickly perform the recommended workflow. You only have
@@ -70,12 +56,13 @@ to paste your data folder.
7056
`Path DATA` | str | | Full path to folder containing data to be segmented.
7157
`Input subfolder` | str | | Name of the subfolder containing the images that should be segmented.
7258
`Path SAVE` | str | | Several options exist. See dedicated section [below](analysis-general-behavior.md#specify-folder-to-save-your-data) for more details.
73-
`Object name` | str | `nuclei` | How the object is called.
7459
`String channel` | str | `dapi` | Unique identifier to identify channel.
75-
`String img ext` | str | `.png` | File extension of images that should be segmented.
76-
`Size object` | int | 50 | Typical size of a cell (in resized image).
60+
`Object name` | str | `nuclei` | How the object is called.
7761
`Cellpose model` | str | `nuclei` | Cellpose model for segmentation: `cyto` or `nuclei`. Note that for dense nuclei, the cytoplasmic model might work better.
78-
`New size` | str | 512, 512 | String to specify new size of image. No resizing if empty.
62+
`Object diameter` | int | 50 | Typical diameter of the object. Better to be set a bit to small.
63+
`Net Average` | Bool | False | Can improve segmentation accuracy, but is slower (Runs the 4 built-in networks and averages them).
64+
`Resample` | Bool | False | Gives more accurate boundaries, but can be very slow (Runs dynamics at original image size).
65+
`String img ext` | str | `.png` | File extension of images that should be segmented.
7966

8067
2. Pressing on the plugin name `SegmentObjects` will start the segmentation.
8168
When using CellPose for the first time, the models for nuclear and cytoplasmic segmentations are downloaded.
@@ -106,7 +93,9 @@ to paste your data folder.
10693
`String img ext` | str | `.png` | File extension of images that should be segmented.
10794
`Size CELLS` | int | 100 | Typical size of a cell (in resized image).
10895
`Size NUCLEI` | int | 50 | Typical size of a nucleus (in resized image).
109-
`New size` | str | 512, 512 | String to specify new size of image. No resizing if empty.
96+
`Net Average` | Bool | False | Can improve segmentation accuracy, but is slower (Runs the 4 built-in networks and averages them).
97+
`Resample` | Bool | False | Gives more accurate boundaries, but can be very slow (Runs dynamics at original image size).
98+
`String img ext` | str | `.png` | File extension of images that should be segmented.
11099

111100
2. Pressing on the plugin name `SegmentCellsNuclei` will start the segmentation.
112101
When using CellPose for the first time, the models for nuclear and cytoplasmic segmentations are downloaded.

docs/contact.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Reporting bugs
22

3-
If you encounter a bug, best is to create a [**GitHub issue**](https://github.com/fish-quant/segmentation/issues). This would allow other users to see
3+
If you encounter a bug, best is to create a [**GitHub issue**](https://github.com/fish-quant/fq-segmentation/issues). This would allow other users to see
44
reported bugs and proposed solutions. If possible, please provide the following information
55

66
1. **How** can the bug be produced?
0 Bytes
Loading

docs/img/imjoy-segment-objects-ui.png

0 Bytes
Loading

docs/workflows-distance-objects.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To **calculate these images** for all masks in a folder, you can use either
3434

3535
* **Jupyter notebook**: notebooks\distance-closest-object.ipynb
3636
* **ImJoy plugin**: `ObjectDist`, which you
37-
<a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/segmentation:ObjectDist@stable&upgrade=1" target="_blank">**install from here.**</a>
37+
<a href="https://imjoy.io/#/app?w=fq-segmentation&plugin=fish-quant/fq-segmentation:ObjectDist@stable&upgrade=1" target="_blank">**install from here.**</a>
3838

3939
In either case, the following **parameters** have to be specified
4040

docs/workflows-overview.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
Here we provide a description of less frequently used workflows.
33

4-
* [**Split multi-channel images**](workflows-fiji-split-channels.md) to obain single-channel images for analysis.
4+
* [**Split multi-channel images**](workflows-fiji-split-channels.md) to obain single-channel images for analysis.
55
* [**Calculate distance to objects**](workflows-distance-objects.md) to calculate images summarizing which object is closest to each pixel.
6-
* [**Convert segmentation results in FQ outlines**](workflows-create-fq-outlines.md) that can be used by the older Matlab version of FISH-quant.
6+
* [**Convert segmentation results in FQ outlines**](workflows-create-fq-outlines.md) that can be used by the older Matlab version of FISH-quant.
77

88
Each workflow is documented in a dedicated section.

imjoy-plugins/ObjectDist.imjoy.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
"name": "ObjectDist",
88
"type": "native-python",
9-
"version": "0.1.5",
9+
"version": "0.2.0",
1010
"description": "Pre-process 3D images to obtain 2D images for segmentation.",
1111
"tags": ["stable","dev"],
1212
"ui": [
@@ -28,7 +28,7 @@
2828
"permissions": [],
2929
"requirements": {
3030
"dev": [""],
31-
"stable":["pip: -U git+https://github.com/fish-quant/segmentation@master"]
31+
"stable":["pip: -U git+https://github.com/fish-quant/fq-segmentation@master"]
3232
},
3333
"dependencies": []
3434
}

imjoy-plugins/PreProcess.imjoy.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "PreProcess",
99
"type": "native-python",
10-
"version": "0.1.7",
10+
"version": "0.2.0",
1111
"description": "Pre-process 3D images to obtain 2D images for segmentation.",
1212
"tags": ["stable","dev"],
1313
"ui": [
@@ -29,7 +29,7 @@
2929
"permissions": [],
3030
"requirements": {
3131
"dev": [""],
32-
"stable":["pip: -U git+https://github.com/fish-quant/segmentation@master"]
32+
"stable":["pip: -U git+https://github.com/fish-quant/fq-segmentation@master"]
3333
},
3434
"dependencies": []
3535
}

imjoy-plugins/SegmentCellsNuclei.imjoy.html

+24-29
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "SegmentCellsNuclei",
99
"type": "native-python",
10-
"version": "0.1.11",
10+
"version": "0.2.0",
1111
"description": "Segment cells AND nuclei.",
1212
"tags": ["stable","dev"],
1313
"ui": [
@@ -16,9 +16,10 @@
1616
"<span style='font-weight: 550; color:#666362'>Path SAVE</span>: {id: 'path_save', type: 'string', placeholder: 'segmentation-input˃˃segmentation-results'}",
1717
"<span style='font-weight: 550; color:#666362'>String CELLS</span>: {id: 'str_cyto', type: 'string', placeholder: 'cy3'}",
1818
"<span style='font-weight: 550; color:#666362'>String NUCLEI</span>: {id: 'str_nuclei', type: 'string', placeholder: 'dapi'}",
19-
"<span style='font-weight: 550; color:#666362'>Scaling factor/New size:</span>: {id: 'new_size', type: 'string', placeholder: '2'}",
20-
"<span style='font-weight: 550; color:#666362'>Size CELLS</span>: {id: 'size_cells', type: 'number', placeholder: 100}",
21-
"<span style='font-weight: 550; color:#666362'>Size NUCLEI</span>: {id: 'size_nuclei', type: 'number', placeholder: 50}",
19+
"<span style='font-weight: 550; color:#666362'>Size CELLS</span>: {id: 'size_cells', type: 'number', placeholder: 200}",
20+
"<span style='font-weight: 550; color:#666362'>Size NUCLEI</span>: {id: 'size_nuclei', type: 'number', placeholder: 100}",
21+
"<span style='font-weight: 550; color:#666362'>Net Average</span>: {id: 'net_avg', type: 'choose', options: ['false', 'true'], placeholder: 'false'}",
22+
"<span style='font-weight: 550; color:#666362'>Resample</span>: {id: 'resample', type: 'choose', options: ['false', 'true'], placeholder: 'false'}",
2223
"<span style='font-weight: 550; color:#666362'>String img ext</span>: {id: 'img_ext', type: 'string', placeholder: '.png'}"
2324
],
2425
"cover": "",
@@ -31,10 +32,10 @@
3132
"permissions": [],
3233
"requirements": {
3334
"dev": [""],
34-
"stable":["pip: -U git+https://github.com/fish-quant/segmentation@master"]
35+
"stable":["pip: -U git+https://github.com/fish-quant/fq-segmentation@master"]
3536
},
3637
"dependencies": [],
37-
"cover": "https://fish-quant.github.io/segmentation/img/segmentation__cells.png"
38+
"cover": "https://fish-quant.github.io/fq-segmentation/img/segmentation__cells.png"
3839
}
3940
</config>
4041

@@ -66,28 +67,10 @@
6667
# Get path for debugging
6768
if api.TAG == 'dev':
6869
if path_scan == 'paste-path-to-data':
69-
path_scan = r'D:\Documents\data-test\fish-quant\fq-imjoy-demo\analysis\segmentation-input'
70+
path_scan = r'D:\Work\Documents\data-test\fish-quant\fq-imjoy-demo\analysis\segmentation-input'
7071

7172
# >>> CHECK INPUT PARAMETERS
7273

73-
74-
# >> Check new size
75-
new_size_str = ctx.config.new_size
76-
77-
if len(new_size_str) == 0:
78-
new_size = ()
79-
80-
else:
81-
if new_size_str.count(',') == 0:
82-
new_size = (int(new_size_str),)
83-
84-
elif new_size_str.count(',') == 1:
85-
new_size = tuple(int(x) for x in new_size_str.split(','))
86-
87-
else:
88-
api.alert('String to define new size has to contain one or zero \",\" to separate the new dimensions in XY.')
89-
return
90-
9174
# >> Path containing the data
9275
if path_scan == 'paste-path-to-data':
9376
api.alert('Path containing data to be processed has to be specified.')
@@ -117,16 +100,28 @@
117100
else:
118101
path_save = Path(path_save)
119102

103+
# >> Interpret boolean parameters
104+
if ctx.config.resample == 'true':
105+
resample = True
106+
else:
107+
resample = False
108+
109+
if ctx.config.net_avg == 'true':
110+
net_avg = True
111+
else:
112+
net_avg = False
113+
120114

121115
# >>>> Call pre-processing function
122116
api.showStatus('Performing segmentation ... see log for details')
123117
utils_cellpose.segment_cells_nuclei_indiv(
124118
path_scan=path_scan,
125-
strings=(ctx.config.str_cyto, ctx.config.str_nuclei),
119+
str_channels=(ctx.config.str_cyto, ctx.config.str_nuclei),
126120
img_ext=ctx.config.img_ext,
127-
new_size=new_size,
128-
sizes=(ctx.config.size_cells, ctx.config.size_nuclei),
129-
models=('cyto','nuclei'),
121+
model_types=('cyto','nuclei'),
122+
diameters=(ctx.config.size_cells, ctx.config.size_nuclei),
123+
net_avg=net_avg,
124+
resample=resample,
130125
path_save=path_save,
131126
input_subfolder=input_subfolder,
132127
callback_log=api.log,

0 commit comments

Comments
 (0)