
ij.plugin.ListVirtualStack Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ij Show documentation
Show all versions of ij Show documentation
ImageJ is an open source Java image processing program inspired by NIH Image for the Macintosh.
package ij.plugin;
import ij.*;
import ij.process.*;
import ij.gui.*;
import ij.io.*;
import ij.util.Tools;
import java.awt.*;
import java.io.*;
import java.util.*;
/** This plugin opens images specified by list of file paths as a virtual stack.
It implements the File/Import/Stack From List command. */
public class ListVirtualStack extends VirtualStack implements PlugIn {
private static boolean virtual;
private String[] list;
private String[] labels;
private int nImages;
private int imageWidth, imageHeight;
private ImagePlus imp2;
public void run(String arg) {
OpenDialog od = new OpenDialog("Open Image List", arg);
String name = od.getFileName();
if (name==null) return;
String dir = od.getDirectory();
//IJ.log("ListVirtualStack: "+dir+" "+name);
list = open(dir+name);
if (list==null) return;
nImages = list.length;
labels = new String[nImages];
//for (int i=0; inImages)
throw new IllegalArgumentException("Argument out of range: "+n);
if (nImages<1) return;
for (int i=n; inImages)
throw new IllegalArgumentException("Argument out of range: "+n);
IJ.redirectErrorMessages(true);
String url = list[n-1];
ImagePlus imp = null;
if (url.length()>0)
imp = IJ.openImage(url);
if (imp!=null) {
labels[n-1] = (new File(list[n-1])).getName()+"\n"+(String)imp.getProperty("Info");
ImageProcessor ip = imp.getProcessor();
int bitDepth = getBitDepth();
if (imp.getBitDepth()!=bitDepth) {
switch (bitDepth) {
case 8: ip=ip.convertToByte(true); break;
case 16: ip=ip.convertToShort(true); break;
case 24: ip=ip.convertToRGB(); break;
case 32: ip=ip.convertToFloat(); break;
}
}
if (ip.getWidth()!=imageWidth || ip.getHeight()!=imageHeight)
ip = ip.resize(imageWidth, imageHeight);
IJ.redirectErrorMessages(false);
if (imp2!=null)
imp2.setFileInfo(imp.getOriginalFileInfo());
ip.setSliceNumber(n);
return ip;
} else {
ImageProcessor ip = null;
switch (getBitDepth()) {
case 8: ip=new ByteProcessor(imageWidth,imageHeight); break;
case 16: ip=new ShortProcessor(imageWidth,imageHeight); break;
case 24: ip=new ColorProcessor(imageWidth,imageHeight); break;
case 32: ip=new FloatProcessor(imageWidth,imageHeight); break;
}
IJ.redirectErrorMessages(false);
ip.setSliceNumber(n);
return ip;
}
}
/** Returns the number of images in this stack. */
public int getSize() {
return nImages;
}
/** Returns the name of the specified image. */
public String getSliceLabel(int n) {
if (n<1 || n>nImages)
throw new IllegalArgumentException("Argument out of range: "+n);
if (labels[n-1]!=null)
return labels[n-1];
else
return (new File(list[n-1])).getName();
}
public int getWidth() {
return imageWidth;
}
public int getHeight() {
return imageHeight;
}
@Override
public void reduce(int factor) {
if (factor<2 || nImages/factor<1)
return;
nImages = nImages/factor;
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy