import ij.*; import ij.process.*; import ij.gui.*; import java.awt.*; import ij.plugin.*; /*The purpose of this plugin is to combine six stacks of images representing the different faces of a 3D object. A GUI will also be provided to allow the user to perform manipulations on the pictures. Specifications for use: 1) Six stacks of pictures of equal width,height and stack size should be used for the plugin to work optimally 2) Each of the six files must be named with the following convention : -_top _bottom _left _right _front _back */ public class Combine_Stacks implements PlugIn { ImageStack newone; public void run(String arg) { if(AllSame()==true){ try{ int maxheight=MaxHeight(); int maxwidth=MaxWidth(); newone=ImageMaker(maxwidth,maxheight); new ImagePlus("Combined Stacks", newone).show(); } catch(IllegalArgumentException e){ return; } } } /* The AllSame function is an error checking function that will ensure that all the specifications listed above are met. */ public boolean AllSame(){ if(WindowManager.getWindowCount()!=6){ IJ.showMessage("This plugin requires six stacks to be opened"); return (false); } int[] idlist=WindowManager.getIDList(); ImagePlus images=WindowManager.getImage(idlist[0]); ImagePlus comimages; for (int i=0;i<6;i++){ comimages=WindowManager.getImage(idlist[i]); if(images.getStackSize()!=comimages.getStackSize()){ IJ.showMessage("Stack sizes for all images must be the same"); return(false); } } for (int i=0;i<6;i++){ images=WindowManager.getImage(idlist[i]); for(int j=0;j<6;j++){ comimages=WindowManager.getImage(idlist[j]); if(images.getTitle()==comimages.getTitle()&&j!=i){ IJ.showMessage("All filenames must be unique"); return(false); } } } return(true); }//AllSame public int MaxHeight(){ int[] idlist=WindowManager.getIDList(); int max=0; int tempmax; for (int i=0;i<6;i++){ ImagePlus images=WindowManager.getImage(idlist[i]); tempmax=images.getHeight(); if(tempmax>max) max=images.getHeight(); } return(max); } public int MaxWidth(){ int[] idlist=WindowManager.getIDList(); int max=0; int tempmax; for (int i=0;i<6;i++){ ImagePlus images=WindowManager.getImage(idlist[i]); tempmax=images.getWidth(); if(tempmax>max) max=images.getWidth(); } return(max); } /* The PositionTitle takes in a picture and finds whether the picture is top,bottom,left...etc. */ public String PositionTitle( ImagePlus workpic){ String pictitle= new String(); int index; int index2; String[] titles={ "top","bottom","left","right","front","back"}; boolean found=false; pictitle=workpic.getTitle(); index=pictitle.indexOf('_'); index2=pictitle.indexOf('.'); index++; pictitle=pictitle.substring(index,index2); return pictitle; } /* The ImageMaker function will take the width and height of the stacks and combine the stacks into one stack. This function was inspired by the Stack_Combiner.java plugin written by Wayne Rasaband. */ public ImageStack ImageMaker(int width, int height ){ ImagePlus image=WindowManager.getCurrentImage(); int stacksize=image.getStackSize(); ImageStack combinedstack=new ImageStack(3*width,4*height); String title=new String(); int[] ids=WindowManager.getIDList(); ImageStack [] stacksofpics = new ImageStack[6]; try{ for(int i=0;i<6;i++) { title=PositionTitle(image=WindowManager.getImage(ids[i])); if(title.equals("top")) stacksofpics[5]=image.getStack(); if(title.equals("bottom")) stacksofpics[4]=image.getStack(); if(title.equals("left")) stacksofpics[2]=image.getStack(); if(title.equals("right")) stacksofpics[3]=image.getStack(); if(title.equals("front")) stacksofpics[0]=image.getStack(); if(title.equals("back")) stacksofpics[1]=image.getStack(); } ImageProcessor ip = stacksofpics[0].getProcessor(1); ImageProcessor newone; for( int j=0;j_top,_bottom ....etc."); } return combinedstack; }//ImageMaker }//Combine_Stacks