Skip to content

Commit

Permalink
Merge pull request #1 from openspim/dev
Browse files Browse the repository at this point in the history
chore: update scifio according to dependabot
  • Loading branch information
hkmoon authored Jan 3, 2024
2 parents e98c0e3 + 9335282 commit 7bc9fa2
Show file tree
Hide file tree
Showing 30 changed files with 1,555 additions and 765 deletions.
67 changes: 45 additions & 22 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<repositories>
<repository>
<id>imagej.public</id>
<url>http://maven.imagej.net/content/groups/public</url>
<url>https://maven.imagej.net/content/groups/public</url>
</repository>
<repository>
<id>local-repo</id>
Expand All @@ -45,7 +45,7 @@
<dependency>
<groupId>io.scif</groupId>
<artifactId>scifio</artifactId>
<version>0.37.3</version>
<version>0.45.0</version>
</dependency>
<dependency>
<groupId>io.scif</groupId>
Expand Down Expand Up @@ -115,18 +115,6 @@
<version>1.2</version>
</dependency>

<dependency>
<groupId>ome</groupId>
<artifactId>formats-api</artifactId>
<version>5.5.3</version>
</dependency>

<dependency>
<groupId>ome</groupId>
<artifactId>formats-bsd</artifactId>
<version>5.5.3</version>
</dependency>

<dependency>
<groupId>org.janelia.saalfeldlab</groupId>
<artifactId>n5-ij</artifactId>
Expand Down Expand Up @@ -201,7 +189,7 @@
<dependency>
<groupId>ome</groupId>
<artifactId>bioformats_package</artifactId>
<version>5.5.2</version>
<version>5.5.3</version>
</dependency>

<dependency>
Expand All @@ -210,12 +198,6 @@
<version>1.8</version>
</dependency>

<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
<version>5.6.3</version>
</dependency>

<dependency>
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer_fiji</artifactId>
Expand All @@ -228,6 +210,47 @@
<version>1.0.0-beta-16</version>
</dependency>

<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-roi</artifactId>
<version>0.12.1</version>
</dependency>

<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
<version>5.12.0</version>
</dependency>

<dependency>
<groupId>net.preibisch</groupId>
<artifactId>BigStitcher</artifactId>
<version>0.8.3</version>
</dependency>

<dependency>
<groupId>org.mastodon</groupId>
<artifactId>mastodon</artifactId>
<version>1.0.0-beta-26</version>
</dependency>

<dependency>
<groupId>org.mastodon</groupId>
<artifactId>mastodon-tracking</artifactId>
<version>1.0.0-beta-12</version>
</dependency>

<dependency>
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer-core</artifactId>
<version>10.4.3</version>
</dependency>

<dependency>
<groupId>org.mastodon</groupId>
<artifactId>mastodon-tomancak</artifactId>
<version>0.2.1</version>
</dependency>
</dependencies>

<build>
Expand All @@ -241,7 +264,7 @@
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.4-SNAPSHOT</version>
<version>8.8.3</version>
<configuration>
<vendor>Scientific Computing Facility</vendor>
<mainClass>spim.microOpenSPIM</mainClass>
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/spim/hardware/BaslerCamera.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spim.hardware;

import mmcorej.CMMCore;

/**
* Author: HongKee Moon ([email protected]), Scientific Computing Facility
* Organization: MPI-CBG Dresden
* Date: June 2023
*/
public class BaslerCamera extends Camera {
static {
Device.installFactory(new Device.Factory() {
@Override
public Device manufacture(CMMCore core, String label ) {
return new BaslerCamera(core, label);
}
}, "BaslerCamera", SPIMSetup.SPIMDevice.CAMERA1, SPIMSetup.SPIMDevice.CAMERA2);
}

public BaslerCamera(CMMCore core, String label) {
super(core, label);
}
}
8 changes: 6 additions & 2 deletions src/main/java/spim/hardware/SPIMSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void setPosition(Double x, Double y, Double z, Double t) {
getZStage().setPosition(z);

if (t != null)
getThetaStage().setPosition(t);
setAngle(t);
}

/**
Expand Down Expand Up @@ -237,7 +237,11 @@ public Vector3D getPosition() {
}

public double getAngle() {
return getThetaStage().getPosition();
return getThetaStage() == null ? 0d : getThetaStage().getPosition();
}

public void setAngle(double r) {
if (getThetaStage() != null) getThetaStage().setPosition(r);
}

public CMMCore getCore() {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/spim/hardware/TSICam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package spim.hardware;

import mmcorej.CMMCore;

/**
* Author: HongKee Moon ([email protected]), Scientific Computing Facility
* Organization: MPI-CBG Dresden
* Date: May 2023
*/
public class TSICam extends Camera {
static {
Device.installFactory(new Device.Factory() {
@Override
public Device manufacture(CMMCore core, String label ) {
return new TSICam(core, label);
}
}, "TSICam", SPIMSetup.SPIMDevice.CAMERA1, SPIMSetup.SPIMDevice.CAMERA2);
}

public TSICam(CMMCore core, String label) {
super(core, label);
}
}
122 changes: 104 additions & 18 deletions src/main/java/spim/io/BDVMicroManagerStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import mpicbg.spim.data.sequence.Tile;
import mpicbg.spim.data.sequence.TimePoint;
import mpicbg.spim.data.sequence.TimePoints;
import net.haesleinhuepf.clij.clearcl.ClearCLBuffer;
import net.haesleinhuepf.clijx.CLIJx;
import net.imglib2.Cursor;
import net.imglib2.FinalDimensions;
import net.imglib2.RandomAccessibleInterval;
Expand Down Expand Up @@ -114,6 +116,7 @@ public class BDVMicroManagerStorage implements Storage {
private final int timesteps_;
private int angles_;
private int channels_;
private boolean fusionChannel_;

int width;
int height;
Expand All @@ -133,13 +136,14 @@ public class BDVMicroManagerStorage implements Storage {
private Map< Integer, ExportMipmapInfo > perSetupExportMipmapInfo = new HashMap< Integer, ExportMipmapInfo >();
private ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();

public BDVMicroManagerStorage(DefaultDatastore store, String directory, String prefix, int channels, int timeSeqs, boolean newDataSet) throws IOException {
public BDVMicroManagerStorage(DefaultDatastore store, String directory, String prefix, int channels, int timeSeqs, boolean newDataSet, boolean fusionChannel) throws IOException {
store_ = store;
dir_ = directory;
prefix_ = prefix;

store_.setSavePath(dir_);
store_.setName(new File(dir_).getName());
fusionChannel_ = fusionChannel;
isDatasetWritable_ = newDataSet;

// Must be informed of events before traditional consumers, so that we
Expand Down Expand Up @@ -298,6 +302,10 @@ public void freeze() throws IOException {
e.printStackTrace();
}
}

if(reader != null) {
reader.close();
}
}

private void saveXml(String n5FilePath, int numTimepoints) throws SpimDataException {
Expand Down Expand Up @@ -409,7 +417,9 @@ public void putImage(Image image) throws IOException {
final int time = coords.getT();
final int angle = coords.getP();

final int setupId = channel + angle * channels;
final int setupId = (fusionChannel_ ? channel / 2 : channel) + angle * (fusionChannel_ ? channels / 2 : channels);

// System.out.println("SetupID: " + setupId);

String dataset = BdvN5Format.getPathName(setupId, time, 0);

Expand Down Expand Up @@ -463,6 +473,7 @@ public void putImage(Image image) throws IOException {
writer.setAttribute( pathName, DATA_TYPE_KEY, bytesPerPixel == 1 ? DataType.UINT8 : DataType.UINT16 );

final double pixelSizeUm = image.getMetadata().getPixelSizeUm();
final double binning = image.getMetadata().getBinning();
final double zStepSize = image.getMetadata().getUserData().getDouble("Z-Step-um", 1);

String punit = "µm";
Expand All @@ -472,17 +483,22 @@ public void putImage(Image image) throws IOException {

final BasicViewSetup setup = new BasicViewSetup( setupId, "" + (setupId), size, voxelSize );
setup.setAttribute( new Angle( angle ) );
setup.setAttribute( new Channel( channel ) );
setup.setAttribute( new Channel( fusionChannel_ ? channel / 2 : channel ) );
setup.setAttribute( new Illumination( 0 ) );
setup.setAttribute( new Tile( 0 ) );
setups.put( setupId, setup );

final ExportMipmapInfo autoMipmapSettings = ProposeMipmaps.proposeMipmaps( new BasicViewSetup( 0, "", size, voxelSize ) );
perSetupExportMipmapInfo.put(setupId, autoMipmapSettings );

double zUnit = 1.524d;
if (pixelSizeUm != 0d) {
zUnit = zStepSize / pixelSizeUm;
}

// create SourceTransform from the images calibration
final AffineTransform3D sourceTransform = new AffineTransform3D();
sourceTransform.set( 1.0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, 9.378, 0 );
sourceTransform.set( 1.0, 0, 0, 0, 0, 1.0, 0, 0, 0, 0, zUnit, 0 );

registrations.add( new ViewRegistration( time, setupId, sourceTransform ) );

Expand Down Expand Up @@ -517,29 +533,99 @@ public void putImage(Image image) throws IOException {
RandomAccessibleInterval source;

if(!amLoading_) {
if (bytesPerPixel == 1) {
final Img rai = ImageJFunctions.<UnsignedByteType>wrap(new ImagePlus("t=" + time + "/angle=" + angle, imageStacks[channel]));
source = Views.zeroMin(rai);
} else {
final Img rai = ImageJFunctions.<UnsignedShortType>wrap(new ImagePlus("t=" + time + "/angle=" + angle, imageStacks[channel]));
source = Views.zeroMin(rai);
if(!fusionChannel_) {
if (bytesPerPixel == 1) {
final Img rai = ImageJFunctions.<UnsignedByteType>wrap(new ImagePlus("t=" + time + "/angle=" + angle, imageStacks[channel]));
source = Views.zeroMin(rai);
} else {
final Img rai = ImageJFunctions.<UnsignedShortType>wrap(new ImagePlus("t=" + time + "/angle=" + angle, imageStacks[channel]));
source = Views.zeroMin(rai);
}

if (writer != null) {
try {
N5Utils.saveBlock(source, writer, dataset, gridPosition, exec);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}

if (writer != null) {
System.out.println(coords.getC() + "/" + channels);

if(fusionChannel_ && coords.getC() % 2 == 1)
{
int nChannels = coords.getC();
for(int i = 0; i < 2; i++) {
CLIJx clijx = CLIJx.getInstance();
ClearCLBuffer gpu_input1 = clijx.push(new ImagePlus("gpu_input", imageStacks[nChannels]));
ClearCLBuffer gpu_input2 = clijx.push(new ImagePlus("gpu_input", imageStacks[nChannels - 1]));

// create an image with correct size and type on GPU for output
ClearCLBuffer gpu_output = clijx.create(gpu_input1);

clijx.maximumImages(gpu_input1, gpu_input2, gpu_output);

ClearCLBuffer background_substrackted_image = clijx.create(gpu_input1);
float sigma1x = 1.0f;
float sigma1y = 1.0f;
float sigma1z = 1.0f;
float sigma2x = 5.0f;
float sigma2y = 5.0f;
float sigma2z = 5.0f;
clijx.differenceOfGaussian3D(gpu_output, background_substrackted_image, sigma1x, sigma1y, sigma1z, sigma2x, sigma2y, sigma2z);

// uncomment the below if you want to see the result
ImagePlus imp_output = clijx.pull(gpu_output);
imp_output.setTitle("t=" + time + "/angle=" + angle);
// imp_output.getProcessor().resetMinAndMax();
// imp_output.show();

// clean up memory on the GPU
gpu_input1.close();
gpu_input2.close();
gpu_output.close();
background_substrackted_image.close();

if (bytesPerPixel == 1) {
final Img rai = ImageJFunctions.<UnsignedByteType>wrap(imp_output);
source = Views.zeroMin(rai);
} else {
final Img rai = ImageJFunctions.<UnsignedShortType>wrap(imp_output);
source = Views.zeroMin(rai);
}

if (writer != null) {
try {
N5Utils.saveBlock(source, writer, dataset, gridPosition, exec);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
if(coords.getC() == channels - 1) {
// Save SpimData format for N5 storage
// System.out.println("xml Saved - t:" + time);
try {
N5Utils.saveBlock(source, writer, dataset, gridPosition, exec);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} catch (Exception e) {
saveXml(dir_ + "/" + prefix_ + ".n5", time + 1);
} catch (SpimDataException e) {
e.printStackTrace();
}
}
}

if(coords.getC() == image.getMetadata().getUserData().getInteger("Channels", 1) - 1)
if(coords.getC() == image.getMetadata().getUserData().getInteger("Channels", 1) - 1) {
timeFinished_.put(time, true);
}
}

if (!coordsToFilename_.containsKey(coords)) {
Expand Down
Loading

0 comments on commit 7bc9fa2

Please sign in to comment.