Skip to content

Commit

Permalink
Merge pull request #8 from trackmate-sc/omnipose
Browse files Browse the repository at this point in the history
Support Omnipose.
  • Loading branch information
tinevez authored Nov 6, 2023
2 parents 9b7bb11 + 7b68336 commit 12e5b26
Show file tree
Hide file tree
Showing 17 changed files with 1,133 additions and 294 deletions.
36 changes: 34 additions & 2 deletions README.md
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.
11 changes: 8 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<version>0.1.3-SNAPSHOT</version>

<name>TrackMate-Cellpose</name>
<description>TrackMate detector based on Cellpose.</description>
<description>TrackMate detector based on cellpose and omnipose.</description>
<url>https://github.com/trackmate-sc/TrackMate-Cellpose</url>
<inceptionYear>2021</inceptionYear>
<organization>
Expand Down Expand Up @@ -51,6 +51,11 @@
<url>https://imagej.net/people/ctrueden</url>
<properties><id>ctrueden</id></properties>
</contributor>
<contributor>
<name>Marie Anselmet</name>
<url>https://research.pasteur.fr/fr/member/marie-anselmet/</url>
<properties><id>manselmet</id></properties>
</contributor>
</contributors>

<mailingLists>
Expand All @@ -59,7 +64,7 @@
<archive>https://forum.image.sc/tag/trackmate</archive>
</mailingList>
</mailingLists>

<scm>
<connection>scm:git:https://github.com/trackmate-sc/TrackMate-Cellpose</connection>
<developerConnection>scm:git:[email protected]:trackmate-sc/TrackMate-Cellpose</developerConnection>
Expand All @@ -84,7 +89,7 @@
<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<TrackMate.version>7.10.2</TrackMate.version>
<TrackMate.version>7.11.1</TrackMate.version>
</properties>

<dependencies>
Expand Down
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 );
}
}
Loading

0 comments on commit 12e5b26

Please sign in to comment.