Coding Phase 2.4

Hello!

Welcome back! This week, I worked on resolving the issues present in the unetdl4j repository (https://github.com/Medha-B/unetdl4j). This involved:

1. Closing issue https://github.com/Medha-B/unetdl4j/issues/2 ( Modify file path to be usable with Linux and Mac #2) after merging with the pull request https://github.com/Medha-B/unetdl4j/pull/6.

2. Closing issue https://github.com/Medha-B/unetdl4j/issues/7 (ScoreIteratorListener outputs the same line during test fold #7) after merging with the pull request https://github.com/Medha-B/unetdl4j/pull/6  (commit 69a5007).

3. Opening new issues https://github.com/Medha-B/unetdl4j/issues/8 (Untracked folders for model weights and output images #8), https://github.com/Medha-B/unetdl4j/issues/9 ( Error in TrainUnetModel for single input channel #9) and https://github.com/Medha-B/unetdl4j/issues/15 ( Completing model evaluation section in CrossVal.java #15). For pull requests corresponding to issue #8 and #9, see  https://github.com/Medha-B/unetdl4j/pull/12 and https://github.com/Medha-B/unetdl4j/pull/13. Next, I plan to resolve issue #15.

4. Making a pull request https://github.com/Medha-B/unetdl4j/pull/14 for the issue https://github.com/Medha-B/unetdl4j/issues/4 (Abstract the code to avoid repetition #4). New additions include classes PreProcess.java (for reading the input file and converting it into DataSetIterator), ImageType.java (for returning a BGR buffered image), Fitter.java (for fitting the ComputationGraph model to training model), and Inference.java (for model inference).
Thanks to Mr. Kaito Ii for helping.

To understand the running a Java project from Command Line Interface,  I implemented a small program:

package org.package;

import picocli.CommandLine; 
import picocli.CommandLine.Command; 
import picocli.CommandLine.Option; 
import picocli.CommandLine.Parameters; 
import java.io.File; import java.util.List; import java.util.concurrent.Callable; 

@Command(name = "parse", mixinStandardHelpOptions = true, description = "Get arguments from the console", version = "1.0") 

public class Parse implements Callable<Integer> { 
 @Option(names = "-r", description = "The r option") String rValue;   @Option(names = "-S", description = "The S option") String sValue;   @Option(names = "-A", description = "The A file") File aFile;   @Option(names = "--test", description = "The test option") boolean test; 
 @Parameters(description = "Positional params") List<String> positional; 

@Override 
 public Integer call() { 
    System.out.printf("-r=%s%n", rValue); 
    System.out.printf("-S=%s%n", sValue); 
    System.out.printf("-A=%s%n", aFile);  
    System.out.printf("--test=%s%n", test);
    System.out.printf("positionals=%s%n", positional)
    
    return 0; 

  } 

  public static void main(String... args) { 

    System.exit(new CommandLine(new Parse()).execute(args)); 

  } 

}

For running this, we need to configure Maven to use picocli as an external dependency in our project:

<dependency> 
     <groupId>info.picocli</groupId> 
     <artifactId>picocli</artifactId> 
     <version>4.5.0</version> 
</dependency>

After adding the dependency, I used Eclipse to export my program as a “runnable JAR file” that contains all the code in a single file.

In Eclipse, select File → Export, then Java → Runnable JAR File.

When all this is done we are ready to run the program from Command Prompt.


As a precursor to implementing XitoSBML-CUI, the next task was to write a program that would take the file path of an image as an argument from the command line and constructs an ImagePlus from a TIFF, BMP, DICOM, FITS, PGM, GIF or JPRG specified by this path, taken as an input.

For preliminary testing, I implemented the following code in Eclipse:

package org.parseImage;

import ij.ImagePlus;

public class Imager {

    public static void main(String[] args) {
String path ="C:\\Users\\Subroto\\Desktop\\outputUnet5.tif";
new ij.ImageJ();
ImagePlus img = new ImagePlus(path);
img.show();
        String title = img.getTitle();
        System.out.println(title);

    }
}

which gives the following as output:



Finally, I implemented the code for doing this by taking arguments from the command line:

package org.parseImage;

import java.util.concurrent.Callable;

import ij.ImagePlus;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "DoParse", mixinStandardHelpOptions = true, description = "Returns ImagePlus object", version = "1.0")
public class DoParse implements Callable<Integer> {
    @Option(names = "-r", description = "The r option")
    String rValue;

    @Override
    public Integer call() {
           System.out.printf("-r=%s%n", rValue);
   new ij.ImageJ();
   ImagePlus img = new ImagePlus(rValue);
   img.show();
           String title = img.getTitle();
           System.out.println(title);

   return 0;
    }

    public static void main(String... args) {
   System.exit(new CommandLine(new DoParse()).execute(args));
   }

}

Although this program worked, the ImageJ window opens for a very small fraction of time and then closes immediately. So, I modified it further to:

package org.parseImage;

import ij.ImagePlus;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "DoParse", mixinStandardHelpOptions = true, description = "Returns ImagePlus object", version = "1.0")
public class DoParse implements Runnable {
    @Option(names = "-r", description = "The r option")
String rValue;

    @Override
    public void run() {
System.out.printf("-r=%s%n", rValue);
new ij.ImageJ();
ImagePlus img = new ImagePlus(rValue);
img.show();
String name = img.getTitle();
System.out.println(name);

    }

    @SuppressWarnings("deprecation")
    public static void main(String... args) {
CommandLine.run(new DoParse(), System.err, args);

    }

}

Although the run method is deprecated, this program worked properly. Initially, I used Run Configuration -> Arguments to take argument -r:


The output looked like this:


On creating a Runnable jar file for the same and then running it from the command prompt, we get:


Note: To obtain the test images, please visit https://drive.google.com/drive/folders/1doEtWY2Jxgdpgxzo75SX4B9YE8opJ9M2?usp=sharing (https://drive.google.com/drive/folders/1doEtWY2Jxgdpgxzo75SX4B9YE8opJ9M2).
Now, I will focus on implementing XitoSBML-CUI with all items that the user should select from a dialog in the GUI version of XitoSBML as command-line options.

Until the next time...
Adeus!

References:

Comments

Popular Posts