Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix command line usage #43

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 45 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.scijava</groupId>
<artifactId>pom-scijava</artifactId>
<version>16.1.0</version>
<version>25.0.0</version>
<relativePath />
</parent>

Expand All @@ -31,16 +31,19 @@
</license>
</licenses>

<contributors>
<contributor>
<developers>
<developer>
<name>Florian Jug</name>
<url>www.mpi-cbg.de/jug</url>
<roles>
<role>founder</role>
<role>developer</role>
</roles>
<properties><id>fjug</id></properties>
</contributor>
</developer>
</developers>

<contributors>
<contributor>
<name>Robert Haase</name>
<url>www.mpi-cbg.de</url>
Expand Down Expand Up @@ -77,8 +80,6 @@
</ciManagement>

<properties>
<jmathplot.path>${project.basedir}/lib/jmathplot.jar</jmathplot.path>
<gurobi.path>${project.basedir}/lib/gurobi.jar</gurobi.path>
<license.licenseName>BSD_3</license.licenseName>
<license.copyrightOwners>Max-Plack Institute of Molecular Cell Biology and Genetics, Dresden</license.copyrightOwners>
</properties>
Expand Down Expand Up @@ -106,17 +107,21 @@
<groupId>net.imagej</groupId>
<artifactId>imagej-ops</artifactId>
</dependency>
<dependency>
<groupId>org.scijava</groupId>
<artifactId>scijava-common</artifactId>
</dependency>

<dependency>
<groupId>jmathplot</groupId>
<artifactId>jmathplot</artifactId>
<version>1.0</version>
<groupId>com.github.yannrichet</groupId>
<artifactId>JMathPlot</artifactId>
<version>1.0.1</version>
</dependency>

<dependency>
<groupId>gurobi</groupId>
<artifactId>gurobi</artifactId>
<version>1.0</version>
<groupId>com.gurobi</groupId>
<artifactId>gurobi-jar</artifactId>
<version>8.1.0</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -149,4 +154,32 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.jug.MoMA</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/json/org.scijava.plugin.Plugin</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 8 additions & 2 deletions src/main/java/com/jug/MoMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileFilter;

import net.imagej.ops.OpService;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
Expand Down Expand Up @@ -74,6 +75,7 @@
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;
import org.scijava.Context;

/**
* @author jug
Expand Down Expand Up @@ -338,6 +340,8 @@ public class MoMA {
public static void main( final String[] args ) {
if ( showIJ ) new ImageJ();

opService = new Context(OpService.class).service(OpService.class);

// // ===== set look and feel ========================================================================
// try {
// // Set cross-platform Java L&F (also called "Metal")
Expand Down Expand Up @@ -775,6 +779,8 @@ public static void main( final String[] args ) {
*/
public ImageJ ij;

private static OpService opService;

private List< Img< FloatType >> rawChannelImgs;
private Img< FloatType > imgRaw;
private Img< FloatType > imgTemp;
Expand Down Expand Up @@ -1550,7 +1556,7 @@ private void findGrowthLines() {
final IntervalView< FloatType > ivFrame = Views.hyperSlice( imgTemp, 2, frameIdx );

// Find maxima per image row (per frame)
frameWellCenters = new Loops< FloatType, List< Point >>().forEachHyperslice( ivFrame, 1, FindLocalMaxima.class);
frameWellCenters = new Loops< FloatType, List< Point >>().forEachHyperslice( ivFrame, 1, FindLocalMaxima.class, opService);

// Delete detected points that are too lateral
for ( int y = 0; y < frameWellCenters.size(); y++ ) {
Expand Down Expand Up @@ -1942,7 +1948,7 @@ private void autodetectBottomOffset() {
maxs[ 0 ] = xDimLen / 2 + GL_OFFSET_LATERAL / 3; // we use the fact that we know that the GL is in the center of the image given to us
final RandomAccessibleInterval<FloatType> centralArea = Views.interval( getImgTemp(), mins, maxs );
final List< FloatType > rowTimeAverages = new Loops< FloatType, FloatType >()
.forEachHyperslice( centralArea, 1, SumOfRai.class);
.forEachHyperslice( centralArea, 1, SumOfRai.class, opService);

// compute average of lower half averages
float lowerHalfAvg = 0;
Expand Down
77 changes: 37 additions & 40 deletions src/main/java/com/jug/loops/Loops.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import java.util.ArrayList;
import java.util.List;

import net.imagej.ImageJ;
import net.imagej.ops.Op;
import net.imagej.ops.OpService;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.type.Type;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.view.Views;

/**
Expand All @@ -22,25 +23,23 @@ public class Loops<IMG_T extends Type< IMG_T >, INNER_RET_T> {
* given UnaryOperation.
* @param rai - <code>RandomAccessibleInterval</code> to be hypersliced.
* @param d - dimension along which the hyperslices will be created.
* @param op - the UnaryOperation<IterableInterval<IMG_T>,INNER_RET_T> instance
* to be called for each hyperslice. Results will be added to List and finally returned.
* @param type - instance of the INNER_RET_T.
* @param opClass - the class of the Op to be called for each hyperslice.
* Results will be added to List and finally returned.
* @param opService - the OpService instance to be used to call the Op
* @return a List of all the individual return values.
*/
public List<INNER_RET_T> forEachHyperslice(
RandomAccessibleInterval<IMG_T> rai, int d,
Class<? extends Op> opClass) {

final ImageJ ij = new ImageJ();

ArrayList<INNER_RET_T> ret = new ArrayList<INNER_RET_T>((int)rai.dimension(d));

for (long i=0; i<rai.dimension(d); i++) {
INNER_RET_T r = (INNER_RET_T) ij.op().run(opClass, Views.hyperSlice(rai, d, i));
ret.add(r);
}

return ret;
RandomAccessibleInterval<FloatType> rai, int d,
Class<? extends Op> opClass, final OpService opService) {

ArrayList<INNER_RET_T> ret = new ArrayList<>((int)rai.dimension(d));

for (long i=0; i<rai.dimension(d); i++) {
INNER_RET_T r = (INNER_RET_T) opService.run(opClass, Views.hyperSlice(rai, d, i));
ret.add(r);
}

return ret;
}

/** Slices given <code>RandomAccessibleInterval</code> along given dimension and hands those to a
Expand All @@ -50,31 +49,29 @@ public List<INNER_RET_T> forEachHyperslice(
* used to locate the same places in the original <code>RandomAccessibleInterval</code>.
* @param rai - <code>RandomAccessibleInterval</code> to be hypersliced.
* @param d - dimension along which the hyperslices will be created.
* @param op - the UnaryOperation<IterableInterval<IMG_T>,INNER_RET_T> instance
* to be called for each hyperslice. Results will be added to List and finally returned.
* @param type - instance of the INNER_RET_T.
* @param opClass - the class of the Op to be called for each hyperslice.
* Results will be added to List and finally returned.
* @param opService - the OpService instance to be used to call the Op
* @return a List of all the individual return values.
*/
public List<INNER_RET_T> forEachIntervalSlice(
RandomAccessibleInterval<IMG_T> rai, int d,
Class<? extends Op> opClass) {

final ImageJ ij = new ImageJ();

ArrayList<INNER_RET_T> ret = new ArrayList<INNER_RET_T>((int)rai.dimension(d));

final int n = rai.numDimensions();
long[] min = new long[n];
rai.min( min );
long[] max = new long[n];
rai.max( max );
for (long i=0; i<rai.dimension(d); i++) {
min[ d ] = i;
max[ d ] = i;
INNER_RET_T r = (INNER_RET_T) ij.op().run(opClass, Views.interval(rai, min, max));
ret.add(r);
}

return ret;
RandomAccessibleInterval<IMG_T> rai, int d,
Class<? extends Op> opClass, final OpService opService) {

ArrayList<INNER_RET_T> ret = new ArrayList<>((int)rai.dimension(d));

final int n = rai.numDimensions();
long[] min = new long[n];
rai.min( min );
long[] max = new long[n];
rai.max( max );
for (long i=0; i<rai.dimension(d); i++) {
min[ d ] = i;
max[ d ] = i;
INNER_RET_T r = (INNER_RET_T) opService.run(opClass, Views.interval(rai, min, max));
ret.add(r);
}

return ret;
}
}