/* v. 1.0 - Nov 28, 2006 This macro opens a list of AVI stacks, crops them, projects them, and saves out the images to a new directory. The images can then be browsed using the Browse 4d plugin, or compiled into a movie using the QT4D Writer plugin. By Jeff Hardin, Dept. of Zoology, Univ. of Wisconsin-Madison, jdhardin@wisc.edu Features to be added in the next version: preprocessing (rotation/scaling) prior to 3d projection */ macro "Batch XY Project" {convert("Tiff");} /*Following was to be used as a progress bar function, but fails when setBatchMode(true) is invoked function statusUpdate(stackNumber, totalStacks){ barWidth = 394; barHeight = 15; barX = 2; barY = 25; imageWidth = 400; imageHeight = 50; if (stackNumber < 0) { newImage("Projecting...", "RGB White", imageWidth, imageHeight, 1); makeRectangle(barX, barY, barWidth, barHeight); run("Draw"); } makeRectangle(barX, barY, barWidth*(stackNumber/totalStacks), barHeight); run("Fill"); x=5; y=20; drawString("Projecting stack " + stackNumber + " of " + totalStacks, x, y); } */ /* Following is the main function for performing the conversion. It takes format as an argument, where format is any valid ImageJ SaveAs file type argument. */ function convert(format) { requires("1.34m"); slicesPerStack = nSlices; dir1 = getDirectory("Choose Source Directory "); dir2 = getDirectory("Choose Destination Directory "); //print("dir 1 = " + dir1); //print("dir 2 = " + dir2); x = 0; y = 0; width = 0; height = 0; getSelectionBounds(x, y, width, height); close(); list = getFileList(dir1); listFinal = list; totalTIFFs = 0; //Now find the total AVIs in the directory, and populate array listFinal with the names for (i=0; i 1.0", interpolate); Dialog.addCheckbox("Generate Stereo Pairs",stereo); Dialog.addChoice("Stereo Type:", newArray("Stereo Pair", "Red-Green", "Red-Cyan")); Dialog.addNumber("Stereo Angle:",stereoAngle); Dialog.addNumber("Top focal plane:",1); Dialog.addNumber("Bottom focal plane:",slicesPerStack); Dialog.addNumber("First time point:",1); Dialog.addNumber("Last time point:",totalTIFFs); Dialog.show(); //Populate the parameters for the rotations title = Dialog.getString(); projectionMethod = Dialog.getChoice(); axisOfRotation = Dialog.getChoice(); sliceSpacing = Dialog.getNumber(); initialAngle = Dialog.getNumber(); totalAngle = Dialog.getNumber(); angleInc = Dialog.getNumber(); transparencyLower = Dialog.getNumber(); transparencyUpper = Dialog.getNumber(); opacity = Dialog.getNumber(); depthCueSurf = Dialog.getNumber(); depthCueInt = Dialog.getNumber(); interpolate = Dialog.getCheckbox(); if (interpolate) {interpolateString = " interpolate";} stereo = Dialog.getCheckbox(); stereoType = Dialog.getChoice(); stereoAngle = Dialog.getNumber(); topFocalPlane = Dialog.getNumber(); bottomFocalPlane = Dialog.getNumber(); firstTimePoint = Dialog.getNumber(); lastTimePoint = Dialog.getNumber(); if ((stereo) && (stereoType == "Stereo Pair") && (axisOfRotation == "Both")) { //beep(); showMessage("Stereo pairs can only be generated with single axis rotations."); exit(); } //incremental counter for main loop counter = 0; //suppress display of images setBatchMode(true); for (i=(firstTimePoint - 1); i 1) { setSlice(1); for (j=0; j<(topFocalPlane -1); j++) { run("Delete Slice"); } } if (bottomFocalPlane < slicesPerStack) { setSlice(nSlices); for (j=0; j<( slicesPerStack - bottomFocalPlane); j++) { run("Delete Slice"); } } makeRectangle(x, y, width, height); if (axisOfRotation == "Y-Axis") { run("Crop"); //if no stereo option selected, don't do it! if (!stereo) { run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + initialAngle + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage(myImageTitle);close(); } else {//do stereo stuff if selected run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + (initialAngle - (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Left"); selectImage(myImageTitle); run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + (initialAngle + (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Right"); selectImage(myImageTitle);close(); if (stereoType == "Stereo Pair") { run("Stack Combiner", "stack1=Left stack2=Right"); } if (stereoType == "Red-Green") { run("RGB Merge...", "red=Left green=Right blue=*None*"); } else if (stereoType == "Red-Cyan") { run("RGB Merge...", "red=Left green=Right blue=Right"); } } imagesToSave = nSlices; run("Image Sequence... ", "format=[" + format + "] name=[" + title + "] start=[" + (i*imagesToSave) + "] digits=5 save=[" + dir2 + list[i] + "]"); } else if (axisOfRotation == "X-Axis") { run("Crop"); //if no stereo option selected, don't do it! if (!stereo) { run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + initialAngle + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage(myImageTitle);close(); } else {//do stereo stuff if selected run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + (initialAngle - (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Left"); selectImage(myImageTitle); run("3D Project...", "projection=[" + projectionMethod + "] axis=" + axisOfRotation + " slice=" + sliceSpacing + " initial=" + (initialAngle + (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Right"); selectImage(myImageTitle);close(); if (stereoType == "Stereo Pair") { run("Stack Combiner", "stack1=Left stack2=Right"); } if (stereoType == "Red-Green") { run("RGB Merge...", "red=Left green=Right blue=*None*"); } else if (stereoType == "Red-Cyan") { run("RGB Merge...", "red=Left green=Right blue=Right"); } } imagesToSave = nSlices; run("Image Sequence... ", "format=[" + format + "] name=[" + title + "] start=[" + (i*imagesToSave) + "] digits=5 save=[" + dir2 + list[i] + "]"); } else { run("Crop"); //Do Y-axis projection if (!stereo){ run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "Y-Axis" + " slice=" + sliceSpacing + " initial=" + initialAngle + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage("Projections of " + myImageTitle); rename("Y-Axis"); } else { run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "Y-Axis" + " slice=" + sliceSpacing + " initial=" + (initialAngle - (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Left"); selectImage(myImageTitle); run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "Y-Axis" + " slice=" + sliceSpacing + " initial=" + (initialAngle + (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); rename("Right"); if (stereoType == "Red-Green") { run("RGB Merge...", "red=Left green=Right blue=*None*"); rename("Y-Axis"); } else if (stereoType == "Red-Cyan") { run("RGB Merge...", "red=Left green=Right blue=Right"); rename("Y-Axis"); } } //Now do X-axis projection selectImage(myImageTitle); if (!stereo){ run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "X-Axis" + " slice=" + sliceSpacing + " initial=" + initialAngle + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage("Projections of " + myImageTitle); rename("X-Axis"); selectImage(myImageTitle); close(); } else { run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "X-Axis" + " slice=" + sliceSpacing + " initial=" + (initialAngle - (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage("Projections of " + myImageTitle); rename("Left"); selectImage(myImageTitle); run("3D Project...", "projection=[" + projectionMethod + "] axis=" + "X-Axis" + " slice=" + sliceSpacing + " initial=" + (initialAngle + (stereoAngle/2)) + " total=" + totalAngle + " rotation=" + angleInc + " lower=" + transparencyLower + " upper=" + transparencyUpper + " opacity=" + opacity + " surface=" + depthCueSurf + " interior=" + depthCueInt + interpolateString); selectImage("Projections of " + myImageTitle); rename("Right"); selectImage(myImageTitle);close(); if (stereoType == "Red-Green") { run("RGB Merge...", "red=Left green=Right blue=*None*"); rename("X-Axis"); } else if (stereoType == "Red-Cyan") { run("RGB Merge...", "red=Left green=Right blue=Right"); rename("X-Axis"); } } run("Stack Combiner", "stack1=X-Axis stack2=Y-Axis"); imagesToSave = nSlices; run("Image Sequence... ", "format=[" + format + "] name=[" + title + "] start=[" + (i*imagesToSave) + "] digits=5 save=[" + dir2 + list[i] + "]"); } // } close(); } setBatchMode(false); print("Rotations complete."); }