Skip to content

Code_Snippets

CellDynamics edited this page Dec 19, 2017 · 8 revisions

Code snippets

Vectorize image

  1. Scan binary image and produce outlines
ImagePlus ip = IJ.openImage("/home/Tests/239/shape1.tif");
TrackOutlineLocal track = new TrackOutlineLocal(ip.getProcessor(), 0).get(0); // get first outline
Outline outlineOrg = track.getOutlines(STEPS, false);

ROIs

  1. Save outlines as images (in one image)
RoiSaver.saveRois(tmpdir + "reo.tif", 512, 512, 
   outlineOrg.asList(), Color.GREEN, 
   outlineSh.asList(), Color.RED,
   null, null);

FormatConverter

  1. Save Outline to csv file
CsvWritter csv = new CsvWritter(Paths.get(tmpdir, "outlineOrg.csv"), FormatConverter.headerEcmmOutline);
FormatConverter.saveOutline(outlineOrg, csv);
csv.close();

Debug

Use QuimP.SUPER_DEBUG to enable additional (usually time consuming) debug:

if (QuimP.SUPER_DEBUG) { // save intermediate results
      LOGGER.debug("Saving intermediate results");
      String tmpdir = System.getProperty("java.io.tmpdir") + File.separator;
      IJ.saveAsTiff(new ImagePlus("", fg1), tmpdir + "fg1_QuimP.tif");
      IJ.saveAsTiff(new ImagePlus("", bg1), tmpdir + "bg1_QuimP.tif");
    }

Then, in e.g. runner code set:

  static {
    System.setProperty("logback.configurationFile", "quimp-logback.xml");
    System.setProperty("quimpconfig.superDebug", "true");
  }

or in runner configuration in Eclipse:

-ea
-Dlogback.configurationFile=quimp-logback.xml
-Dquimpconfig.superDebug=true

Copy file patterns

try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(input, "*.maQP")) {
  dirStream.forEach(path -> LOGGER.debug(path.toString()));
}

Create temp folders

@Rule
public MyTemporaryFolder folder = new MyTemporaryFolder();
@Test
public void testQconf2paQp2Qconf() throws Exception {
  Path target = folder.getRoot().toPath();
}
// to prevent deleting tmp folder override after()
class MyTemporaryFolder extends TemporaryFolder {
  @Override
  protected void after() {
    // comment to block deleting - for testing
    // super.after();
  }
}

Disable random selection of first node

QuimP selects first node randomly, this often happens when new Shape is created because of used algorithm that starts from fake head and then remove it. To block this for tests use:

Field f = Shape.class.getDeclaredField("threshold");
f.setAccessible(true);
f.setDouble(Shape.class, 1.0);

QuimP home page is here

QuimP Wiki pages

Developer zone

Clone this wiki locally