-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from trackmate-sc/omnipose
Support Omnipose.
- Loading branch information
Showing
17 changed files
with
1,133 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,37 @@ | ||
[![Build Status](https://github.com/trackmate-sc/TrackMate-Cellpose/actions/workflows/build.yml/badge.svg)](https://github.com/trackmate-sc/TrackMate-Cellpose/actions/workflows/build.yml) | ||
|
||
# TrackMate-Cellpose | ||
# Omnipose integration in TrackMate. | ||
|
||
Tentative Cellpose integration in TrackMate. | ||
The Omnipose integration in TrackMate works roughly as the Cellpose integration one. | ||
It requires Omnipose to be installed on your system and working independently. This page gives installation details and advices at how to use the omnipose integration in TrackMate. | ||
|
||
## Omnipose | ||
Omnipose is a segmentation algorithm based on Deep-Learning techniques, and inspired from the Cellpose architecture. Omnipose is well suited for bacterial cell segmentation, and achieves remarkable performances on mixed bacterial cultures, antibiotic-treated cells and cells of elongated or branched morphology. | ||
|
||
If you use the Omnipose TrackMate module for your research, please also cite the Omnipose paper: | ||
[Cutler, K.J., Stringer, C., Lo, T.W. et al. Omnipose: a high-precision morphology-independent solution for bacterial cell segmentation. Nat Methods 19, 1438–1448 (2022)](https://www.nature.com/articles/s41592-022-01639-4). | ||
|
||
|
||
|
||
## Example | ||
https://github.com/marieanselmet/TrackMate-Omnipose/assets/32811540/3c2365c9-8d1b-4057-b4d1-2939e4e2b818 | ||
|
||
*E. Coli, Marie Anselmet and Rodrigo Arias Cartin, Barras lab, Institut Pasteur* | ||
|
||
|
||
## Omnipose installation | ||
|
||
This code works with the Omnipose version 0.3.6. It doesn't work with the last version of Omnipose. | ||
|
||
To install Omnipose, you can refer directly to the installation guide provided on the [Omnipose repository](https://github.com/kevinjohncutler/omnipose#how-to-install-omnipose). | ||
|
||
An example Windows installation working on GPU: | ||
``` | ||
conda create -n omnipose | ||
conda activate omnipose | ||
conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.8 -c pytorch -c nvidia | ||
pip install omnipose==0.3.6 | ||
pip install cellpose-omni==0.7.3 | ||
``` | ||
|
||
The default models *bact_phase_omni* and *bact_fluor_omni* are stored in the cellpose pretrained models folder. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
src/main/java/fiji/plugin/trackmate/cellpose/AbstractCellposeSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
package fiji.plugin.trackmate.cellpose; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public abstract class AbstractCellposeSettings | ||
{ | ||
|
||
/** | ||
* Interface for enums that represent a pretrained or a custom model in | ||
* cellpose or omnipose. | ||
*/ | ||
public interface PretrainedModel | ||
{ | ||
|
||
/** | ||
* Returns <code>true</code> if this model is a custom model. | ||
* | ||
* @return <code>true</code> if this model is a custom model. | ||
*/ | ||
boolean isCustom(); | ||
|
||
/** | ||
* Returns the name of this pretrained model, or its path if it is a | ||
* custom model. | ||
* | ||
* @return the model name or path. | ||
*/ | ||
String getPath(); | ||
|
||
} | ||
|
||
public final String executablePath; | ||
|
||
public final int chan; | ||
|
||
public final int chan2; | ||
|
||
public final String customModelPath; | ||
|
||
public final double diameter; | ||
|
||
public final boolean useGPU; | ||
|
||
public final boolean simplifyContours; | ||
|
||
private final PretrainedModel model; | ||
|
||
protected AbstractCellposeSettings( | ||
final String executablePath, | ||
final PretrainedModel model, | ||
final String customModelPath, | ||
final int chan, | ||
final int chan2, | ||
final double diameter, | ||
final boolean useGPU, | ||
final boolean simplifyContours ) | ||
{ | ||
this.executablePath = executablePath; | ||
this.model = model; | ||
this.chan = chan; | ||
this.chan2 = chan2; | ||
this.customModelPath = customModelPath; | ||
this.diameter = diameter; | ||
this.useGPU = useGPU; | ||
this.simplifyContours = simplifyContours; | ||
} | ||
|
||
/** | ||
* Returns the executable name of the cellpose or omnipose command. For | ||
* cellpose, it's simply 'cellpose'. | ||
* | ||
* @return the executable name. | ||
*/ | ||
public abstract String getExecutableName(); | ||
|
||
public List< String > toCmdLine( final String imagesDir ) | ||
{ | ||
final List< String > cmd = new ArrayList<>(); | ||
|
||
/* | ||
* First decide whether we are calling Cellpose from python, or directly | ||
* the Cellpose executable. We check the last part of the path to check | ||
* whether this is python or cellpose. | ||
*/ | ||
final String[] split = executablePath.replace( "\\", "/" ).split( "/" ); | ||
final String lastItem = split[ split.length - 1 ]; | ||
if ( lastItem.toLowerCase().startsWith( "python" ) ) | ||
{ | ||
// Calling Cellpose from python. | ||
cmd.add( executablePath ); | ||
cmd.add( "-m" ); | ||
cmd.add( getExecutableName() ); | ||
} | ||
else | ||
{ | ||
// Calling Cellpose executable. | ||
cmd.add( executablePath ); | ||
} | ||
|
||
/* | ||
* Cellpose command line arguments. | ||
*/ | ||
|
||
// Target dir. | ||
cmd.add( "--dir" ); | ||
cmd.add( imagesDir ); | ||
|
||
// First channel. | ||
cmd.add( "--chan" ); | ||
cmd.add( "" + chan ); | ||
|
||
// Second channel. | ||
if ( chan2 >= 0 ) | ||
{ | ||
cmd.add( "--chan2" ); | ||
cmd.add( "" + chan2 ); | ||
} | ||
|
||
// GPU. | ||
if ( useGPU ) | ||
cmd.add( "--use_gpu" ); | ||
|
||
// Diameter. | ||
cmd.add( "--diameter" ); | ||
cmd.add( ( diameter > 0 ) ? "" + diameter : "0" ); | ||
|
||
// Model. | ||
cmd.add( "--pretrained_model" ); | ||
if ( model.isCustom() ) | ||
cmd.add( customModelPath ); | ||
else | ||
cmd.add( model.getPath() ); | ||
|
||
// Export results as PNG. | ||
cmd.add( "--save_png" ); | ||
|
||
// Do not save Numpy files. | ||
cmd.add( "--no_npy" ); | ||
|
||
return Collections.unmodifiableList( cmd ); | ||
} | ||
} |
Oops, something went wrong.