|
| 1 | +package org.janelia.saalfeldlab.hotknife; |
| 2 | + |
| 3 | +import java.io.IOException; |
| 4 | +import java.io.Serializable; |
| 5 | +import java.util.ArrayList; |
| 6 | +import java.util.List; |
| 7 | +import java.util.concurrent.ExecutionException; |
| 8 | + |
| 9 | +import org.janelia.saalfeldlab.hotknife.util.Transform; |
| 10 | +import org.janelia.saalfeldlab.n5.N5FSReader; |
| 11 | +import org.janelia.saalfeldlab.n5.N5Reader; |
| 12 | +import org.kohsuke.args4j.CmdLineException; |
| 13 | +import org.kohsuke.args4j.CmdLineParser; |
| 14 | +import org.kohsuke.args4j.Option; |
| 15 | + |
| 16 | +import net.imglib2.realtransform.RealTransform; |
| 17 | + |
| 18 | +public class SparkViewDeformationFieldDifference |
| 19 | +{ |
| 20 | + /* |
| 21 | + --n5Path=/nrs/hess/data/hess_wafer_53/export/hess_wafer_53_center7.n5/ |
| 22 | + --scaleIndex=5 |
| 23 | + --n5Group=/surface-align/run_20240517_200443/pass04 |
| 24 | + --saveDir='/home/[email protected]/workspace/hot-knife/tmp' |
| 25 | + */ |
| 26 | + @SuppressWarnings("serial") |
| 27 | + public static class Options extends AbstractOptions implements Serializable { |
| 28 | + |
| 29 | + @Option(name = "--n5Path", required = true, usage = "N5 path, e.g. /nrs/hess/data/hess_wafer_53/export/hess_wafer_53_center7.n5") |
| 30 | + private String n5Path; |
| 31 | + |
| 32 | + @Option(name = "--n5Group", required = false, usage = "N5 group, e.g. /surface-align/run_20240517_200443/pass04") |
| 33 | + private String group = "/"; |
| 34 | + |
| 35 | + @Option(name = "--scaleIndex", required = true, usage = "scale index for visualization, e.g. 4 (means scale = 1.0 / 2^4)") |
| 36 | + private int transformScaleIndex; |
| 37 | + |
| 38 | + @Option(name = "-a", required = false, usage = "list of transformation fields (sorted as pairs with 'b'), e.g. -a flat_mask.s281_m206.bot4_clahe.face OR -a pass04/flat_mask.s281_m206.bot4_clahe.face") |
| 39 | + private ArrayList<String> a = new ArrayList<>(); |
| 40 | + |
| 41 | + @Option(name = "-b", required = false, usage = "list of transformation fields (sorted as pairs with 'a'), e.g. -a flat_mask.s281_m206.top4_clahe.face") |
| 42 | + private ArrayList<String> b = new ArrayList<>(); |
| 43 | + |
| 44 | + @Option(name = "-o", aliases = {"--saveDir"}, required = true, usage = "directory for saving differences in transformation fields") |
| 45 | + private String saveDir; |
| 46 | + |
| 47 | + @Option(name = "--localSparkBindAddress", required = false, usage = "specify Spark bind address as localhost") |
| 48 | + private boolean localSparkBindAddress = false; |
| 49 | + |
| 50 | + public Options(final String[] args) { |
| 51 | + |
| 52 | + final CmdLineParser parser = new CmdLineParser(this); |
| 53 | + try { |
| 54 | + parser.parseArgument(args); |
| 55 | + |
| 56 | + parsedSuccessfully = true; |
| 57 | + |
| 58 | + } catch (final CmdLineException e) { |
| 59 | + System.err.println(e.getMessage()); |
| 60 | + parser.printUsage(System.err); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + public String getN5Path() { return n5Path; } |
| 65 | + public int getScaleIndex() { return transformScaleIndex; } |
| 66 | + public String saveDir() { return saveDir; } |
| 67 | + public String getGroup() { return group; } |
| 68 | + } |
| 69 | + |
| 70 | + public static void main(final String... args) throws IOException, InterruptedException, ExecutionException |
| 71 | + { |
| 72 | + |
| 73 | + final SparkViewDeformationFieldDifference.Options options = new SparkViewDeformationFieldDifference.Options(args); |
| 74 | + if (! options.parsedSuccessfully) { |
| 75 | + throw new IllegalArgumentException("Options were not parsed successfully"); |
| 76 | + } |
| 77 | + |
| 78 | + if ( options.a.size() != options.b.size() ) |
| 79 | + throw new RuntimeException( "size of a and b not equal." ); |
| 80 | + |
| 81 | + if ( options.a.size() == 0 ) |
| 82 | + throw new RuntimeException( "a and b not specified." ); |
| 83 | + |
| 84 | + final String n5Path = options.getN5Path(); |
| 85 | + final String n5Group = options.getGroup(); |
| 86 | + final int scaleIndex = options.getScaleIndex(); |
| 87 | + final ArrayList< String > transformANames = options.a; |
| 88 | + final ArrayList< String > transformBNames = options.b; |
| 89 | + |
| 90 | + for ( int i = 0; i < options.a.size(); ++ i ) |
| 91 | + { |
| 92 | + final N5Reader n5 = new N5FSReader(n5Path); |
| 93 | + |
| 94 | + final String transformA = transformANames.get( i ); |
| 95 | + final String transformB = transformBNames.get( i ); |
| 96 | + |
| 97 | + final double[] boundsMin = n5.getAttribute(transformA, "boundsMin", double[].class); |
| 98 | + final double transformScale = n5.getAttribute(transformA, "scale", double.class); |
| 99 | + |
| 100 | + final RealTransform tA = Transform.loadScaledTransform(n5, n5Group + "/" + transformA ); |
| 101 | + final RealTransform tB = Transform.loadScaledTransform(n5, n5Group + "/" + transformB ); |
| 102 | + |
| 103 | + final RealTransform sTA = Transform.createScaledRealTransform( tA, scaleIndex ); |
| 104 | + final RealTransform sTB = Transform.createScaledRealTransform( tB, scaleIndex ); |
| 105 | + |
| 106 | + |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments