// This macro implements the Image>HyperStacks>New HyperStack command. defaults = "8-bit Color 300 200 3 10 5 1"; if (is("applet")) prefs = split(defaults); else prefs = split(call("ij.Prefs.get", "hyperstack.new", defaults)); if(prefs.length<8) prefs = split(defaults); type = prefs[0]; mode = prefs[1]; width = parseInt(prefs[2]); height = parseInt(prefs[3]); c = parseInt(prefs[4]); z = parseInt(prefs[5]); t = parseInt(prefs[6]); label = parseInt(prefs[7]); title = "HyperStack"; Dialog.create("HyperStack"); Dialog.addString("Title:", title); Dialog.addChoice("Type:", newArray("8-bit", "16-bit", "32-bit", "RGB"), type); Dialog.addChoice("Display Mode:", newArray("Composite", "Color", "Grayscale"), mode); Dialog.addNumber("Width:", width); Dialog.addNumber("Height:", height); Dialog.addNumber("Channels (c):", c); Dialog.addNumber("Slices (z):", z); Dialog.addNumber("Frames (t):", t); Dialog.addCheckbox("Label Images", label); Dialog.show; title = Dialog.getString(); type = Dialog.getChoice(); mode = Dialog.getChoice(); width = Dialog.getNumber; height = Dialog.getNumber; c = Dialog.getNumber; z = Dialog.getNumber; t = Dialog.getNumber; label = Dialog.getCheckbox; batch = is("Batch Mode"); if (!batch) setBatchMode(true); if (label) type2 = type + " ramp"; else type2 = type + " black"; newImage(title, type2, width, height, c*z*t); run("Properties...", "channels="+c+" slices="+z+" frames="+t); showStatus(""); channel=1; slice=1; frame=1; setFont("SansSerif", 24); if (label) { yloc = 30; for (i=1; i<=nSlices; i++) { showProgress(i, nSlices); setSlice(i); setColor(0, 0, 0); fillRect(0, 0, width, yloc); fillRect(0, yloc+15, width, height-(yloc+15)); setColor(255, 255, 255); drawString("c="+pad(channel)+", z="+pad(slice)+", t="+pad(frame), 5, yloc); //setMetadata("slice", "c="+pad(channel)+", z="+pad(slice)+", t="+pad(frame)); if (i<=c) { setFont("SansSerif", 12, "antialiased"); msg = "Press shift-z (Image>HyperStacks>Channels)\n"+ "to open the \"Channels\" window, which will\n"+ "allow you switch to composite color mode\n"+ "and to enable/disable channels.\n"; drawString(msg, 25, 80); setFont("SansSerif", 24); } channel++; if (channel>c) { channel = 1; slice++; if (slice>z) { slice = 1; frame++; if (frame>t) frame = 1; } } } } setSlice(1); if (c>1 && bitDepth!=24) run("Make Composite", "display="+mode); setOption("OpenAsHyperStack", true); if (!batch) setBatchMode(false); prefs = type+" "+mode+" "+width+" "+height+" "+c+" "+z+" "+t+" "+label; if (!is("applet")) call("ij.Prefs.set", "hyperstack.new", prefs); exit; function pad(n) { str = toString(n); while (lengthOf(str)<3) str = "0" + str; return str; }