diff --git a/BIOP_Channel_Tools.ijm b/BIOP_Channel_Tools.ijm index daa8f2c..f9c0964 100644 --- a/BIOP_Channel_Tools.ijm +++ b/BIOP_Channel_Tools.ijm @@ -1,774 +1,775 @@ // Install the BIOP Library call("BIOP_LibInstaller.installLibrary", "BIOP"+File.separator+"BIOPLib.ijm"); // Name ActionBar bar_name = "BIOP Channel Tools"; bar_file = replace(bar_name, " ", "_")+".ijm"; bar_jar = replace(bar_name, " ", "_")+".jar"; runFrom = "jar:file:BIOP/"+bar_jar+"!/"+bar_file; ////////////////////////////////////////////////////////////////////////////////////////////// // The line below is for debugging. Place this VSI file in the ActionBar folder within Plugins ////////////////////////////////////////////////////////////////////////////////////////////// //runFrom = "/plugins/ActionBar/Debug/"+bar_file; if(isOpen(bar_name)) { run("Close AB", bar_name); } run("Action Bar",runFrom); exit(); //Start of ActionBar function toolName() { return "Channel Tools"; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // specific library function channelsLUTSelection(){ run("Make Composite", "display=Color"); getDimensions(width, height, channels, slices, frames); defaultsArray = newArray("Red","Green","Blue","Grays","Cyan","Magenta","Yellow","Fire"); names = newArray(0); types = newArray(0); defaults = newArray(0); for (i=0;i1) { Stack.setChannel(chNbr); } run(recColorTemp); } } } function brightnessAndContrastSetting(){ getDimensions(width, height, channels, slices, frames); for (i=0;i1) { Stack.setChannel(chNbr); } run("Brightness/Contrast..."); waitForUser(" Set B&C for channel "+chNbr+"\n Please set Min and Max \n and press Ok"); getMinAndMax(min, max); setData("min ch"+chNbr,min); setData("max ch"+chNbr,max); } } function brightnessAndContrastSettingApply(){ getDimensions(width, height, channels, slices, frames); for (i=0;i1) { Stack.setChannel(chNbr); } min = getData("min ch"+chNbr); max = getData("max ch"+chNbr); setMinAndMax(min, max); } } //montage options function montageOptions(){ // Get dimensions getDimensions(x,y,c,z,t); // Check if ROIS nRois = roiManager("Count"); useScale = getBoolD("Use Scalebar", true); // Scale bar position scalePos = getDataD("ScaleBar Position", "Lower Right"); // scale bar size scaleLength = getDataD("ScaleBar Length", 100); // scalebar height scaleHeight = getDataD("ScaleBar height", 5); // Which Position gets the scalebar atImage = getDataD("Scalebar At", ""); // nrows ncols mRows = getDataD("Montage Rows", "As Row"); mCols = getDataD("Montage Cols", 1); // position of composite cPos = getDataD("Channel Merge Position", "First"); isIgnore = getBoolD("Ignore LUTs except for Merged", false); advMon = getDataD("Advanced Montage", ""); // border size bSize = getDataD("Montage Border", 0); zSlices = getDataD("Z Slices", ""); // Image Legend fontSize = getDataD("Font Size", 14); chanNames = getDataD("Channel Names", ""); position = getDataD("Legend Position", "bottom left"); slice = getDataD("Legend Montage Position", 1); // ROIs isShowRois = getBoolD("Display ROIs", false); roiOrder = getDataD("ROI Order",""); roiColors = getDataD("ROI Colors",""); // border color rowChoice= newArray("As Row", "1","2", "3", "4", "5", "6"); colChoice= newArray("As Column","1", "2", "3", "4", "5", "6"); scalePoses=newArray("Lower Right", "Lower Left", "Upper Right", "Upper Left"); imgPos=newArray("First", "Last"); positions = newArray("top left", "top right", "bottom left", "bottom right"); Dialog.create("Montage Options"); Dialog.addCheckbox("Use Scalebar", useScale); Dialog.addChoice("Scalebar Position", scalePoses, scalePos); Dialog.addNumber("Scalebar Length", scaleLength, 0, 5, "um"); Dialog.addNumber("Scalebar Height", scaleHeight, 0, 5, "px"); Dialog.addString("Scalebar At Image", atImage); Dialog.addChoice("Montage Rows", rowChoice, mRows); Dialog.addChoice("Montage Columns", colChoice, mCols); Dialog.addChoice("Merged Image Position", imgPos, cPos); Dialog.addCheckbox("Ignore LUTs except for Merged", isIgnore); Dialog.addString("Advanced Montage", advMon); Dialog.addNumber("Montage Border", bSize,0,5,"px"); if (z > 1) { Dialog.addMessage("Image is Z Stack (nZ = "+z+")\nLeave blank to do all slices"); Dialog.addString("Choose slice range for MIP", zSlices); } Dialog.addMessage("Montage Lengend"); Dialog.addString("Names for the Channels", chanNames); Dialog.addNumber("Font Size", fontSize); Dialog.addChoice("Legend Position", positions, position); Dialog.addNumber("Legend At Image", slice); //ROIS if(nRois > 0) { Dialog.addMessage("There are "+nRois+" ROIs"); Dialog.addCheckbox("Show ROIs on Montage?", isShowRois); Dialog.addString("ROI Order", roiOrder); Dialog.addString("ROI Colors", roiColors); } Dialog.show(); // Scale bar position useScale = Dialog.getCheckbox(); scalePos = Dialog.getChoice(); scaleLen = Dialog.getNumber(); scaleHei = Dialog.getNumber(); atImage = Dialog.getString(); mRows = Dialog.getChoice(); mCols = Dialog.getChoice(); cPos = Dialog.getChoice(); isIgnore = Dialog.getCheckbox(); advMon = Dialog.getString(); bSize = Dialog.getNumber(); if (z > 1) { zSlices = Dialog.getString(); } else { zSlices = "None"; } chanNames= Dialog.getString(); fontSize = Dialog.getNumber(); position = Dialog.getChoice(); slice = Dialog.getNumber(); //ROIS if(nRois > 0) { isShowRois = Dialog.getCheckbox(); roiOrder = Dialog.getString(); roiColors = Dialog.getString(); } setBool("Use Scalebar", useScale); setData("ScaleBar Position", scalePos); setData("ScaleBar Length", scaleLen); setData("ScaleBar Height", scaleHei); setData("Scalebar At", atImage); setData("Montage Rows", mRows); setData("Montage Cols", mCols); setData("Channel Merge Position", cPos); setBool("Ignore LUTs except for Merged", isIgnore); setData("Advanced Montage", advMon); setData("Montage Border", bSize); setData("Z Slices", zSlices); setData("Font Size", fontSize); setData("Channel Names", chanNames); setData("Legend Position", position); setData("Legend Montage Position", slice); setBool("Display ROIs",isShowRois); setData("ROI Order",roiOrder); setData("ROI Colors",roiColors); } function montageApply(){ // Use scalebar useScale = getBoolD("Use Scalebar", true); // Scale bar position scalePos = getData("ScaleBar Position"); // scale bar size scaleLength = getData("ScaleBar Length"); // scalebar height scaleHeight = getData("ScaleBar Height"); // nrows ncols mRows = getData("Montage Rows"); mCols = getData("Montage Cols"); // position of composite cPos = getData("Channel Merge Position"); // border size bSize = getData("Montage Border"); //Ignore LUT colors and keep gray isIgnore = getBoolD("Ignore LUTs except for Merged", false); // border color bColor = getData("Montage Border Color"); advMon = getData("Advanced Montage"); atImage = getData("Scalebar At"); zSlices = getData("Z Slices"); if(scalePos == "") { showMessage("Montage Settings not set."); exit(); } ori = getTitle(); // Get LUTS Stack.getDimensions(dx,dy,dc,dz,dt); r = newArray(dc); g = newArray(dc); b = newArray(dc); for(ch=0; ch1) { run("Merge Channels...", str+"create keep"); } else { selectImage("C"+monImages[i]+"-"+name); run("Duplicate...", "title=[temp]"); } run("RGB Color"); rename("Position "+(i+1)); finalImages[i] = "Position "+(i+1); } for(i=1; i< monImages.length; i++) { // Make Montage selectImage(finalImages[i]); run("Copy"); close(); selectImage(finalImages[0]); run("Add Slice"); run("Paste"); } } else { getDimensions(x,y,c,z,t); Stack.setDisplayMode("composite"); name = getTitle(); run("Duplicate...", " duplicate channels"); name2 = getTitle(); // Make RGB run("Stack to RGB"); rgbName = getTitle(); //Split the other images selectImage(name2); run("Split Channels"); //Make each an RGB image RGBnames = newArray(c); for (i=1;i<=c; i++) { if (cPos == "First") { k = i; } else { k=c-i+1; } selectImage("C"+k+"-"+name2); if(isIgnore) { getMinAndMax(min, max); run ("Grays"); setMinAndMax(min, max); } run("RGB Color"); run("Copy"); close(); selectImage(rgbName); run("Add Slice"); run("Paste"); } // Make the RGB first or last if (cPos == "Last") { run("Reverse"); } } //Set the scale if (useScale) { if (atImage=="") { run("Scale Bar...", "width="+scaleLength+" height="+scaleHeight+" font=9 color=White background=None location=["+scalePos+"] bold hide"); } else { setSlice(parseInt(atImage)); run("Scale Bar...", "width="+scaleLength+" height="+scaleHeight+" font=9 color=White background=None location=["+scalePos+"] bold hide"); } } // If there are channel names, add them channelNames = getData("Channel Names"); fontSize = parseInt(getData("Font Size")); position = getData("Legend Position"); slice = getData("Legend Montage Position"); if(channelNames != "") { nameChannels(channelNames, fontSize, r,g,b, slice, position); } // Here we have a stack and maybe some ROIs exist in the ROI manager dealWithRois(); if(nSlices >1) { if (mRows == "As Row") { run("Make Montage...", "columns="+(c+1)+" rows=1 scale=1.0 border="+bSize+" use"); } else if (mCols == "As Column") { run("Make Montage...", "columns=1 rows="+(c+1)+" scale=1.0 border="+bSize+" use"); } else { // Assemble the stack for run("Make Montage...", "columns="+mCols+" rows="+mRows+" scale=1.0 border="+bSize+" use"); } } rename(ori+"_Montage"); selectWindow(ori+"_Montage"); } function dealWithRois() { name = getTitle(); // Right now we have the montage and we want to see if we put some ROIs in there isShowRois = getBoolD("Display ROIs", false); if (!isShowRois) return; getDimensions(x,y,c,z,t); // Work on the Rois roiOrder = split(getDataD("ROI Order" ,""),","); roiColors = split(getDataD("ROI Colors",""),","); roiWidth = getDataD("ROI Width" ,2); roiIdx = 0; for(i=0; i maxLen) { maxLen = lengthOf(stringArray[i]); largest = stringArray[i]; } } return largest; } function nameChannels(channelNames, fontSize, r,g,b, slice, position) { padding=5; // work in the right position setSlice(slice); // Width and height of the image height = getHeight(); width = getWidth(); // Find dimensions of legend // Split Channel names channels = split(channelNames, ","); setFont("SansSerif", fontSize, "bold"); largestS = getLargestString(channels); boxWidth = getStringWidth(largestS)+2*padding; boxHeight = (fontSize+1)*channels.length+2*padding; // Get the position of the legend thePos = split(position, " "); if (thePos[0] == "top") { posy = 0; } else { posy = height - boxHeight; } if (thePos[1] == "left") { posx = 0; } else { posx = width - boxWidth; } // Create a box around the fonts setColor(128,128,128); fillRect(posx, posy, boxWidth, boxHeight); // Make the text the right color textString = channels[0]; for(i=0; i Parameters