This plugin opens images specified by list of file paths as a virtual stack. It implements the File/Import/Stack From List command.
| 14 | /** This plugin opens images specified by list of file paths as a virtual stack. |
| 15 | It implements the File/Import/Stack From List command. */ |
| 16 | public class ListVirtualStack extends VirtualStack implements PlugIn { |
| 17 | private static boolean virtual; |
| 18 | private String[] list; |
| 19 | private String[] labels; |
| 20 | private int nImages; |
| 21 | private int imageWidth, imageHeight; |
| 22 | private ImagePlus imp2; |
| 23 | |
| 24 | public void run(String arg) { |
| 25 | OpenDialog od = new OpenDialog("Open Image List", arg); |
| 26 | String name = od.getFileName(); |
| 27 | if (name==null) return; |
| 28 | String dir = od.getDirectory(); |
| 29 | //IJ.log("ListVirtualStack: "+dir+" "+name); |
| 30 | list = open(dir+name); |
| 31 | if (list==null) return; |
| 32 | nImages = list.length; |
| 33 | labels = new String[nImages]; |
| 34 | //for (int i=0; i<list.length; i++) |
| 35 | // IJ.log(i+" "+list[i]); |
| 36 | if (list.length==0) { |
| 37 | IJ.error("Stack From List", "The file path list is empty"); |
| 38 | return; |
| 39 | } |
| 40 | if (!list[0].startsWith("http://")) { |
| 41 | File f = new File(list[0]); |
| 42 | if (!f.exists()) { |
| 43 | IJ.error("Stack From List", "The first file on the list does not exist:\n \n"+list[0]); |
| 44 | return; |
| 45 | } |
| 46 | } |
| 47 | ImagePlus imp = IJ.openImage(list[0]); |
| 48 | if (imp==null) return; |
| 49 | imageWidth = imp.getWidth(); |
| 50 | imageHeight = imp.getHeight(); |
| 51 | setBitDepth(imp.getBitDepth()); |
| 52 | ImageStack stack = this; |
| 53 | if (!showDialog(imp)) return; |
| 54 | if (!virtual) |
| 55 | stack = convertToRealStack(imp); |
| 56 | imp2 = new ImagePlus(name, stack); |
| 57 | imp2.setCalibration(imp.getCalibration()); |
| 58 | imp2.setFileInfo(imp.getOriginalFileInfo()); |
| 59 | imp2.show(); |
| 60 | } |
| 61 | |
| 62 | boolean showDialog(ImagePlus imp) { |
| 63 | double bytesPerPixel = 1; |
| 64 | switch (imp.getType()) { |
| 65 | case ImagePlus.GRAY16: |
| 66 | bytesPerPixel=2; break; |
| 67 | case ImagePlus.COLOR_RGB: |
| 68 | case ImagePlus.GRAY32: |
| 69 | bytesPerPixel=4; break; |
| 70 | } |
| 71 | double size = (imageWidth*imageHeight*bytesPerPixel)/(1024.0*1024.0); |
| 72 | int digits = size*getSize()<10.0?1:0; |
| 73 | String size1 = IJ.d2s(size*getSize(), digits)+" MB"; |
nothing calls this directly
no outgoing calls
no test coverage detected