Skip to content

Commit

Permalink
Centralize ij.IJ calls in ImpUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
tferr committed Sep 19, 2024
1 parent 9ee87e6 commit 14e8c6d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/main/java/sc/fiji/snt/gui/DemoRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import sc.fiji.snt.SNTUI;
import sc.fiji.snt.Tree;
import sc.fiji.snt.gui.cmds.SpotSpineLoaderCmd;
import sc.fiji.snt.util.ImpUtils;

public class DemoRunner {

Expand Down Expand Up @@ -246,7 +247,7 @@ private Demo demo9() {
final Demo entry = new Demo(9, "Non-neuronal dividing cell (5D image)") {
@Override
public ImagePlus getImage() {
final ImagePlus imp = ij.IJ.openImage("http://wsr.imagej.net/images/mitosis.tif");
final ImagePlus imp = ImpUtils.open("http://wsr.imagej.net/images/mitosis.tif");
imp.setPosition(2, 4, 31); // k-fibers channel, mid Z-range, traced time point
return imp;
}
Expand Down Expand Up @@ -306,7 +307,7 @@ private Demo demo11() {
final Demo entry = new Demo(11, "NeuronJ dataset (2D neurites)") {
@Override
public ImagePlus getImage() {
return ij.IJ.openImage("https://github.com/morphonets/misc/raw/master/dataset-demos/NeuronJ/neurites.tif");
return ImpUtils.open("https://github.com/morphonets/misc/raw/master/dataset-demos/NeuronJ/neurites.tif");
}
@Override
public void load() {
Expand All @@ -330,7 +331,7 @@ private Demo demo12() {
final Demo entry = new Demo(12, "Spot Spine dataset (spine decorated dendrite)") {
@Override
public ImagePlus getImage() {
return ij.IJ.openImage("https://github.com/morphonets/misc/raw/master/dataset-demos/SpotSpine/SpotSpine_ImageStack_Test.tif");
return ImpUtils.open("https://github.com/morphonets/misc/raw/master/dataset-demos/SpotSpine/SpotSpine_ImageStack_Test.tif");
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sc/fiji/snt/hyperpanes/MultiDThreePanes.java
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ public static ImagePlus[] getZYXZ(final ImagePlus xy, final int frame) {
public static void main(final String[] args) {
if (ij.IJ.getInstance() == null) new ij.ImageJ();
final String path = "https://imagej.net/images/Spindly-GFP.zip";
final ImagePlus imp = ij.IJ.openImage(path);
final ImagePlus imp = sc.fiji.snt.util.ImpUtils.open(path);
for (ImagePlus view : MultiDThreePanes.getZYXZ(imp, 20)) {
view.show();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/sc/fiji/snt/plugin/SkeletonConverterCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package sc.fiji.snt.plugin;

import ij.IJ;
import ij.ImagePlus;
import ij.gui.Roi;
import net.imagej.ImageJ;
Expand All @@ -46,6 +45,7 @@
import sc.fiji.snt.gui.GuiUtils;
import sc.fiji.snt.gui.cmds.ChooseDatasetCmd;
import sc.fiji.snt.gui.cmds.CommonDynamicCmd;
import sc.fiji.snt.util.ImpUtils;
import sc.fiji.snt.util.SNTColor;

import java.io.File;
Expand Down Expand Up @@ -329,11 +329,11 @@ public void run() {
return;
}
SNTUtils.log("Loading " + maskImgFileChoice.getAbsolutePath());
chosenMaskImp = IJ.openImage(maskImgFileChoice.getAbsolutePath());
chosenMaskImp = ImpUtils.open(maskImgFileChoice);
ensureMaskImgVisibleOnAbort = true;
if (SNTUtils.fileAvailable(originalImgFileChoice)) {
SNTUtils.log("Loading " + originalImgFileChoice.getAbsolutePath());
chosenOrigImp = IJ.openImage(originalImgFileChoice.getAbsolutePath());
chosenOrigImp = ImpUtils.open(originalImgFileChoice);
} else {
isValidOrigImg = originalImgFileChoice == null || originalImgFileChoice.toString().isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import sc.fiji.snt.gui.ShollAnalysisDialog;
import sc.fiji.snt.gui.ShollAnalysisDialog.ShollPoint;
import sc.fiji.snt.gui.ShollAnalysisDialog.ShollResults;
import sc.fiji.snt.util.ImpUtils;
import sc.fiji.snt.util.PointInImage;

/**
Expand Down Expand Up @@ -105,7 +106,7 @@ public void run(final String ignoredArgument) {

if (!showDialog()) return;

imp = (impRequired) ? IJ.openImage(imgPath) : null;
imp = (impRequired) ? ImpUtils.open(imgPath) : null;
if (impRequired && imp == null || !validTracesFile(new File(tracesPath))) {
GuiUtils.errorPrompt("Invalid image or invalid Traces/(e)SWC file\n \n" +
imgPath + "\n" + tracesPath);
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/sc/fiji/snt/util/ImpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,18 @@ public static ImagePlus open(final File file) {
return open(file, null);
}

public static ImagePlus open(final String filePathOrUrl) {
return open(filePathOrUrl, null);
}

public static ImagePlus open(final File file, final String title) {
return open(file.getAbsolutePath(), title);
}

public static ImagePlus open(final String filePathOrUrl, final String title) {
final boolean redirecting = IJ.redirectingErrorMessages();
IJ.redirectErrorMessages(true);
final ImagePlus imp = IJ.openImage(file.getAbsolutePath());
final ImagePlus imp = IJ.openImage(filePathOrUrl);
if (title != null)
imp.setTitle(title);
IJ.redirectErrorMessages(redirecting);
Expand Down Expand Up @@ -293,18 +301,16 @@ public static ImagePlus demo(final String img) {
} else if (nImg.contains("dda") || nImg.contains("c4") || nImg.contains("sholl")) {
return demoImageInternal("tests/ddaC.tif", "Drosophila_ddaC_Neuron.tif");
} else if (nImg.contains("op")) {
return ij.IJ.openImage(
"https://github.com/morphonets/SNT/raw/0b3451b8e62464a270c9aab372b4f651c4cf9af7/src/test/resources/OP_1.tif");
return open("https://github.com/morphonets/SNT/raw/0b3451b8e62464a270c9aab372b4f651c4cf9af7/src/test/resources/OP_1.tif", null);
} else if (nImg.equalsIgnoreCase("rat_hippocampal_neuron") || (nImg.contains("hip") && nImg.contains("multichannel"))) {
return ij.IJ.openImage("http://wsr.imagej.net/images/Rat_Hippocampal_Neuron.zip");
return open("http://wsr.imagej.net/images/Rat_Hippocampal_Neuron.zip", null);
} else if (nImg.contains("4d") || nImg.contains("701")) {
return cil701();
} else if (nImg.contains("multipolar") || nImg.contains("810")) {
return cil810();
} else if (nImg.contains("timelapse")) {
return (!nImg.contains("binary")) ? cil701()
: ij.IJ.openImage(
"https://github.com/morphonets/misc/raw/00369266e14f1a1ff333f99f0f72ef64077270da/dataset-demos/timelapse-binary-demo.zip");
: open("https://github.com/morphonets/misc/raw/00369266e14f1a1ff333f99f0f72ef64077270da/dataset-demos/timelapse-binary-demo.zip", null);
}
throw new IllegalArgumentException("Not a recognized demoImage argument: " + img);
}
Expand Down Expand Up @@ -354,7 +360,7 @@ private static ImagePlus cil810() {
}

private static ImagePlus cil701() {
final ImagePlus imp = IJ.openImage("https://cildata.crbs.ucsd.edu/media/images/701/701.tif");
final ImagePlus imp = open("https://cildata.crbs.ucsd.edu/media/images/701/701.tif", null);
if (imp != null) {
imp.setDimensions(1, 1, imp.getNSlices());
imp.getCalibration().setUnit("um");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/sc/fiji/snt/viewer/Viewer3D.java
Original file line number Diff line number Diff line change
Expand Up @@ -2341,7 +2341,7 @@ public boolean saveSnapshot() {
// HACK: current cartesian views may not reflect sensible 'anatomical views'.
// This is the case with the Allen CCF. While this is not addressed, we can
// just save a rotated copy of the snapshot. //TODO: Handle this more properly
final ij.ImagePlus imp = ij.IJ.openImage(file.getAbsolutePath());
final ij.ImagePlus imp = sc.fiji.snt.util.ImpUtils.open(file.getAbsolutePath());
if (imp != null) {
ij.IJ.run(imp, "Rotate 90 Degrees Left", "");
ij.IJ.saveAs(imp, "PNG", file.getAbsolutePath().replace(".png", "_rotated.png"));
Expand Down

0 comments on commit 14e8c6d

Please sign in to comment.