Skip to content

Commit

Permalink
Temporary OIR fix (related to ome/bioformats#4205)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKiaru committed Jul 2, 2024
1 parent 35dc43b commit ec8888f
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/main/java/ch/epfl/biop/kheops/KheopsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public static SourcesInfo getSourcesFromFile(String path,int tileX,
.readerPoolSize(nParallelJobs)
.splitRGBChannels(splitRGB)
.positionConvention(position_convention)
.cornerPositionConvention()
.context(context)
);
}
Expand Down
29 changes: 25 additions & 4 deletions src/main/java/ch/epfl/biop/kheops/command/KheopsBatchCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import ch.epfl.biop.kheops.ometiff.OMETiffExporter;
import ij.IJ;
import loci.common.DebugTools;
import loci.formats.FormatException;
import loci.formats.IFormatReader;
import loci.formats.in.OIRReader;
import loci.formats.meta.IMetadata;
import org.apache.commons.io.FilenameUtils;
import org.scijava.Context;
Expand Down Expand Up @@ -145,10 +147,29 @@ public void run() {
IJ.log("Processing " + input_path);
String fileName = input_path.getName();

KheopsHelper.SourcesInfo sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), tileSize, tileSize, 1,
1, false, "CORNER", context);
final KheopsHelper.SourcesInfo sourcesInfo;

if (FilenameUtils.isExtension(input_path.getAbsolutePath(),"oir")) {
// We need to read one full plane, otherwise the reader is too bad
// I unfortunately need to initialize a reader to get the size
System.out.println("OIR File detected! Reading full plane.");
OIRReader r = new OIRReader();
try {
r.setId(input_path.getAbsolutePath());
sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), r.getSizeX(), r.getSizeY(), 1,
1, false, "CORNER", context);
} catch (FormatException | IOException e) {
throw new RuntimeException(e);
}
} else {
sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), tileSize, tileSize, 1,
1, false, "CORNER", context);

}

int nSeriesOriginal = sourcesInfo.idToSources.keySet().size();

Expand Down
33 changes: 30 additions & 3 deletions src/main/java/ch/epfl/biop/kheops/command/KheopsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import ch.epfl.biop.kheops.ometiff.OMETiffExporter;
import ij.IJ;
import loci.common.DebugTools;
import loci.formats.FormatException;
import loci.formats.IFormatReader;
import loci.formats.in.OIRReader;
import loci.formats.meta.IMetadata;
import org.apache.commons.io.FilenameUtils;
import org.scijava.Context;
Expand Down Expand Up @@ -110,7 +112,7 @@ public void run() {
String fileName = input_path.getName();

//--------------------
int tileSize = 512;
int tileSize = 1024;
int nThreads = Math.max(1,Runtime.getRuntime().availableProcessors()-1);

File parent_dir = new File(input_path.getParent());
Expand All @@ -125,10 +127,35 @@ public void run() {

int numberOfBlocksComputedInAdvance = 64;

KheopsHelper.SourcesInfo sourcesInfo =
/*KheopsHelper.SourcesInfo sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), tileSize, tileSize, numberOfBlocksComputedInAdvance,
nThreads,false, "CORNER", context);
nThreads,false, "CORNER", context);*/
//String fileName = input_path.getName();

final KheopsHelper.SourcesInfo sourcesInfo;

if (FilenameUtils.isExtension(input_path.getAbsolutePath(),"oir")) {
// We need to read one full plane, otherwise the reader is too bad
// I unfortunately need to initialize a reader to get the size
System.out.println("OIR File detected! Reading full plane.");
OIRReader r = new OIRReader();
try {
r.setId(input_path.getAbsolutePath());
sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), r.getSizeX(), r.getSizeY(), 6,
1, false, "CORNER", context);
} catch (FormatException | IOException e) {
throw new RuntimeException(e);
}
} else {
sourcesInfo =
KheopsHelper
.getSourcesFromFile(input_path.getAbsolutePath(), tileSize, tileSize, numberOfBlocksComputedInAdvance,
1, false, "CORNER", context);

}

int nSeriesOriginal = sourcesInfo.idToSources.keySet().size();

Expand Down
30 changes: 25 additions & 5 deletions src/test/java/DemoExport.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,27 @@
*/
import ch.epfl.biop.kheops.ometiff.OMETiffExporter;
import loci.common.DebugTools;
import net.imagej.ImageJ;
import net.imglib2.FinalInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.position.FunctionRandomAccessible;
import net.imglib2.type.numeric.ARGBType;
import net.imglib2.view.Views;
import org.scijava.task.TaskService;

import java.time.Duration;
import java.time.Instant;

public class DemoExport {

public static void main( String[] args )
{
ImageJ ij = new ImageJ();
ij.ui().showUI();
int sizeInPixelX = 512;
int sizeInPixelY = 512;
int tileSize = 512;
int nT = 512;
final FunctionRandomAccessible<ARGBType> checkerboard = new FunctionRandomAccessible<>(
2,
(location, value) -> {
Expand All @@ -49,20 +57,32 @@ public static void main( String[] args )

try {
//String path = "C:\\Users\\nicol\\Desktop\\ometiff\\ntest-" + sizeInPixelX + "x"+sizeInPixelY+"px-" + tileSize + "tile.ome.tiff";
String path = "C:\\kheops\\ntest-" + sizeInPixelX + "x"+sizeInPixelY+"px-" + tileSize + "tile.ome.tiff";
String path = "C:\\kheops\\test_x-" + sizeInPixelX + "_y-"+sizeInPixelY+"_tile-" + tileSize + "_nT-"+nT+".ome.tiff";
System.out.println("Saving "+path);
OMETiffExporter.builder()
.putXYZRAI(img)
.putXYZRAI(0,1,img)
.defineMetaData("Image")

Instant start = Instant.now();

OMETiffExporter.OMETiffExporterBuilder.Data.DataBuilder dataBuilder = OMETiffExporter.builder();

for (int t = 0;t<nT;t++) {
dataBuilder.putXYZRAI(0,t,img);
}

dataBuilder.defineMetaData("Image")
.imageName("Bob")
.voxelPhysicalSizeMicrometer(10,10,2)
.pixelsTimeIncrementInS(0.35)
.defineWriteOptions()
.tileSize(tileSize,tileSize)
.monitor(ij.get(TaskService.class))
.savePath(path)
.create()
.export();

Instant end = Instant.now();

System.out.println("Export time (ms) \t"+Duration.between(start,end).toMillis());

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit ec8888f

Please sign in to comment.