Skip to content

Commit

Permalink
Add command line option to apply raw tile stitching parameters to dec…
Browse files Browse the repository at this point in the history
…onvolved tiles (#38)

* added parameters for flatfield images
* fixed the default correction images paths
* use same style
* add option to apply raw tile stitching parameters to deconvolved tiles
* update file naming for new version
* add ability to use json specifying tif inputs

Co-authored-by: Cristian Goina <[email protected]>
  • Loading branch information
davidackerman and Cristian Goina authored Apr 5, 2022
1 parent e578943 commit e118564
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
53 changes: 51 additions & 2 deletions src/main/java/org/janelia/stitching/StitchingArguments.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package org.janelia.stitching;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -10,6 +16,10 @@
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

/**
* Command line arguments parser for a stitching job.
*
Expand Down Expand Up @@ -104,11 +114,15 @@ public static enum RematchingMode implements Serializable
@Option(name = "--fusestage", required = false,
usage = "Allow fusing tiles using their stage coordinates (when there is no '-final' suffix in the tile configuration filename), i.e. when exporting initial tile configuration.")
private boolean allowFusingStage = false;

@Option(name = "--applyRawStitchingToDecon", required = false,
usage = "Apply stitching parameters obtained from raw tiles to deconvolved tiles.")
private boolean applyRawStitchingToDecon = false;


private boolean parsedSuccessfully = false;

public StitchingArguments( final String[] args ) throws IllegalArgumentException
public StitchingArguments( final String[] args ) throws IllegalArgumentException, IOException
{
final CmdLineParser parser = new CmdLineParser( this );
try {
Expand Down Expand Up @@ -139,7 +153,40 @@ else if ( rematchingModeStr.equalsIgnoreCase( "incremental" ) )
for ( int i = 0; i < inputTileConfigurations.size(); ++i )
if ( !CloudURI.isCloudURI( inputTileConfigurations.get( i ) ) )
inputTileConfigurations.set( i, Paths.get( inputTileConfigurations.get( i ) ).toAbsolutePath().toString() );


if ( applyRawStitchingToDecon )
{
for ( int channel = 0; channel < inputTileConfigurations.size(); channel++ )
{
// need to replace eg. /base/path/tiles.n5/488nm/Tile.tif with /base/path/matlab_decon/Tile.tif
String inputTileConfiguration = inputTileConfigurations.get( channel );
JsonArray jsonArray = (JsonArray) new JsonParser().parse( new FileReader( inputTileConfiguration ) );
JsonObject firstTile = (JsonObject) jsonArray.get( 0 );
File firstTileFile = new File( firstTile.get( "file" ).toString() );
String parentDir = firstTileFile.getParent();
String greatGrandparentDirectory = firstTileFile.getParentFile().getParentFile().getParent();

String content = new String( Files.readAllBytes( Paths.get( inputTileConfiguration ) ), StandardCharsets.UTF_8);
content = content.replaceAll( ".tif", "_decon.tif" );
String outputTileConfiguration;
if ( inputTileConfiguration.contains( "-n5-final.json" ) )
{
content = content.replaceAll( parentDir, greatGrandparentDirectory + "/matlab_decon" );
outputTileConfiguration = inputTileConfiguration.replace( "-n5-final.json", "-rawToDecon-final.json" );
}
else
{ // then it contains references to tifs not n5s
content = content.replaceAll( parentDir, parentDir + "/matlab_decon" );
if ( inputTileConfiguration.contains( "final.json" ) )
outputTileConfiguration = inputTileConfiguration.replace( "-final.json", "-rawToDecon-final.json" );
else
outputTileConfiguration = inputTileConfiguration.replace( ".json", "-rawToDecon.json" );
}
Files.write( Paths.get( outputTileConfiguration ), content.getBytes( StandardCharsets.UTF_8 ) );
inputTileConfigurations.set(channel, outputTileConfiguration);
}
}

if (correctionImagesPaths != null && correctionImagesPaths.size() > 0)
{
if (correctionImagesPaths.size() != inputTileConfigurations.size())
Expand Down Expand Up @@ -189,6 +236,8 @@ public long[] maxCoord()

public boolean stitchOnly() { return stitchOnly; }
public boolean fuseOnly() { return fuseOnly; }

public boolean applyRawStitchingToDecon() { return applyRawStitchingToDecon; }

public RematchingMode rematchingMode() { return rematchingMode; }

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/janelia/stitching/StitchingSpark.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.janelia.stitching;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
Expand All @@ -19,7 +20,7 @@

public class StitchingSpark implements Serializable, AutoCloseable
{
public static void main( final String[] args )
public static void main( final String[] args ) throws IllegalArgumentException, IOException
{
final StitchingArguments stitchingArgs = new StitchingArguments( args );
if ( !stitchingArgs.parsedSuccessfully() )
Expand Down

0 comments on commit e118564

Please sign in to comment.