/* Purpose: Multichannel images are split into individual color components with contrast of a model image applied and saved with names chosen by the user. Michael Cammer & Aram Modrek at NYU Langone Medical Center 20150303 for ImageJ 1.49o */ // Need to get contrast for each channel and apply correctly to each channel in all other images. // This requires an array of min and max for each channel. // Possible added features: // All files in a given directory operated on automatically. For instance, user sets settings on one file and all other files in same folder operated on automatically. // In this version the output files are saved in the same directory as the original image. This could be changed in later versions. // The scalebar length could be based on an if statement based on the scale in the image. This could be added later. // v102 adds contrast settings // Global variables. These remain set until the macro is reinstalled. var settingsSet = false; // Set to true after user enters settings. Prevents incorrect output. var originalName = ""; // Title of of image being processed var channels = -1; // How many color channels the image has. var LUTs = newArray("Green", "Red", "Blue", "Grays", "", ""); // LUTs in channel order; add colors per user's needs var mins = newArray(100, 100, 100, 100, 100, 100); // minimum intensity output for each channel var maxs = newArray(3000, 3000, 3000, 3000, 3000, 3000); // maximum intensity each channel var chNames = newArray("Ch1", "Ch2", "Dapi", "Trans", "", ""); // Description of channel, added to output files var ouputName = ""; // Root title for saving derived from originalName. var scalebarYesNo = false; // Should each image have a scalebar on it? var scalebarLength = 25; // If a scalebar, how long in um. var originalPath = ""; // Path of original image. var destPath = ""; // Destination directory/folder for output images. //========================================================================= macro "Set Up [F4]" { requires("1.49k"); run("Make Composite", "display=Composite"); getSettings(); run("Brightness/Contrast..."); waitForUser("Adjust contrast of each channel and then hit OK.\n Do not hit Apply."); getContrastForAllChannels(); } // end Set Up //========================================================================= // File is split into individual channels. // Each channel in its color output (with scalebar if set). // macro "Process Open File [F5]" { if (! settingsSet) exit("Please run Set Up macro first."); doProcessing(); // This is done as a function to make it each to put a for all files loop around it. } // end Main macro "Process All Files In Directory [F6]" { if (! settingsSet) exit("Please run Set Up macro first."); run("Close All"); list = getFileList(originalPath); for (i=0; i 1) || (frames > 1) || (ch != channels)) exit("Expecting multi-channel image with precisely "+channels+" channels."); // set the colors for (i=0; i< channels; i++) { Stack.setChannel(i+1); run(LUTs[i]); setMinAndMax(mins[i], maxs[i]); } original = getImageID(); // last channel is always the transmitted and it will be turned off displayChannels = ""; for (k=0; k 1) || (frames > 1)) exit("Expecting multi-channel image."); if (channels > 4) { // This is specifically for Aram to move Grays to channel 5 LUTs[4] = "Grays"; LUTs[3] = "Magenta"; } availableLUTs = getList("LUTs"); // could manually change to a shorter list Dialog.create("Settings"); Dialog.addMessage("The open image " + originalName + " has " + channels + " channels.\nChoose color for each."); for (i=0; i< channels; i++) Dialog.addChoice("Color channel "+ (i+1), availableLUTs, LUTs[i]); Dialog.addMessage("Provide a name for each channel:"); for (i=0; i< channels; i++) Dialog.addString(""+i, chNames[i]); Dialog.addCheckbox("Check for Scalebar ", scalebarYesNo); Dialog.addNumber("Scalebar size um", scalebarLength); // could add if statement before this based on image scale & change default accordingly Dialog.show(); // Get the settings from the dialogue box. for (i=0; i< channels; i++) LUTs[i] = Dialog.getChoice(); for (i=0; i< channels; i++) chNames[i] = Dialog.getString(); scalebarYesNo = Dialog.getCheckbox(); scalebarLength = Dialog.getNumber(); settingsSet = true; // Sends ok to other macros that settings have been checked by user. // set the chosen colors immediately for (i=1; i<=channels; i++) { Stack.setChannel(i); run(LUTs[i-1]); } // for i run("Channels Tool..."); Stack.setDisplayMode("composite"); } // end getSettings(); //============================================================================================== //============================================================================================== function getContrastForAllChannels() { Stack.getDimensions(width, height, channels, slices, frames); for (i=1; i<=channels; i++) { Stack.setChannel(i); getMinAndMax(mins[i-1], maxs[i-1]); } // for i } // end getContrastForAllChannels