// Title of the tool: Multi-Channels Image and Stack Helper // First version: 18/01/2011 update 12/03/2013 // Description: allows a non-destructive contrast adjustment on 8 or 16 bit images, stacks, composite images // and hyperstacks. It permits to optimise the visualisation by fitting the LUT to the 24 bit screen mode, and // to edit some RGB documents for presentations and papers. // Author : Gilles Carpentier // Faculte des Sciences et Technologie, // Universite Paris Est Creteil Val de Marne, France. var composite=0, globalBitDepth=0, MinContrast=0,MaxContrast=0,minUser=0,maxUser=0; var depthSampling=newArray ("8","10","12","15","16"); var contrastOptions = newArray ("8 bit sampling \(0-255\)","10 bit sampling \(0-1023\)","12 bit sampling \(0-4095\)","15 bit sampling \(0-32767\)","16 bit sampling \(0-65535\)", "min->max all channels", "min->max each channel"); var chosenContratsOption ="min->max all channels", rgbOption=0; var checkList=newArray; var channelOrder="xyzct",channelOrderChoices=newArray("xyczt(default)","xyctz","xyzct","xyztc","xytcz","xytzc"),Zchoice=1, tChoice=1, nbSlice=1, nbChannel=4, nbz=1, nbt=1, totSlices=0; var ColorAvailable=newArray ("Grays","Red","Green","Blue","Cyan","Yellow","Magenta"),ColorChs=newArray("Red","Green","Blue","Grays"); var depthChoices=newArray ("Unchange","Bit Depth"), depthChoice="Unchange"; var checkList2=newArray, depthChoice2="Unchange"; var methodProj="Max Intensity", methodProjs=newArray ("Max Intensity","Sum Slices","Average Intensity","Standard Deviation","Min Intensity","Median"); var errorNetMessage ="Error: "; var urllist = "http://image.bio.methods.free.fr/ij/ijupdatetest/ListOfMacros.txt";// to check the internet access var onlinedoclink = "http://image.bio.methods.free.fr/ImageJ/?Multi-Channels-Image-and-Stack.html"; var demoimagelink1 = "http://image.bio.methods.free.fr/ij/ijmacro/Composit/NiceCells.tif.zip"; var demoimagelink2 = "http://image.bio.methods.free.fr/ij/ijmacro/Composit/NiceCompositZ-RGP-Stack-s.tif.zip"; var demoimagelink3 = "http://image.bio.methods.free.fr/ij/ijmacro/Composit/HistoMuscle-4Channels.tif.zip"; var demoimagename1 = "NiceCells.tif"; var demoimagename2 = "NiceCompositZ-RGP-Stack-s.tif"; var demoimagename3 = "HistoMuscle-4Channels.tif"; // ------- // var xx = requires146i (); // check version at install time function requires146i() {requires("1.46i"); return 0;} var dCmds = newMenu("Stacks Menu Tool",newArray ("Multi-Channels Stack From Single Channel Files","Stack to Hyperstack")); macro "Stacks Menu Tool - Ca9bD16D2eD55DcaDd2C548D4bDafCfffD00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D11D12D13D14D15D20D21D22D23D30D31D32D33D40D41D4cD5cD6cD77D78D7cD87D88D8cD97D98D9cDbeDbfDceDcfDdcDddDdeDdfDebDecDedDeeDefDfaDfbDfcDfdDfeDffC317D3dD54Dc9CccdD51DcdC87aDb5DbaC316D4dD5dD62D6bD6dD76D7bD7dD86D8bD8dD96D9bD9dDa7Da8DacDbdDd3Dd4Dd5Dd6Dd7Dd8CbacD57D58D59D73D83D93Da3Db3Dc3Dc5Dc6Dc7Dc8DccDf1Df2Df3Df4Df5Df6Df7Df8Df9C87aD17D18D19D1aD1bD1cD1dD1eD72D82D92Da2Db2Dc2De2De3De4De5De6De7De8C538D2fD34D37D38D39D3aD3bD3cD3fD43D47D48D49D4aD4fD5fD6fD74D79D7fD84D89D8fD94D99D9fDa4Db4De1CeeeDf0C98bD27D28D29D2aD2bD2cD60D70D71D80D81D90D91Da0Da1Db0Db1Db6Db7Db8DbcDc0Dc1Dd0Dd1De0C206D56DcbDe9Ca9bD2dC659D52D67D68C427D61CeeeD25D3eD4eD5aD5eD6aD6eD75D7aD7eD85D8aD8eD95D9aD9eDa5DeaCfffD24D50C105D44D66C648D65C327Da6DdbCdcdDc4C316D26D5bDaaDaeDb9DdaCbacD1fD42C86aD53C437D35D45D63C206D64D69Dbb"{ cmd = getArgument(); if (cmd!="-" && cmd == "Multi-Channels Stack From Single Channel Files") run("Merge Channels..."); if (cmd!="-" && cmd == "Stack to Hyperstack") stacksToHyperStacks (); } macro "Make Composite Action Tool - C036D7cC33fD79C03aD7bCfffD09D0aD0bD0cD0dD0eD0fD1aD1bD1cD1dD1eD1fD22D23D24D25D26D2aD2bD2cD2dD2eD2fD32D33D3dD3eD3fD42D4dD4eD4fD52D5dD5eD5fD62D66D9aD9dDa0Da1Da2DadDb0Db1Db2DbdDc0Dc1Dc2DcdDd0Dd1Dd2Dd3Dd4Dd5Dd9DdaDdbDdcDddDe0De1De2De3De4De5Df0Df1Df2Df3Df4Df5Df6C070D84CddfD9eDaeDbeDceDdeDe9C7f7DabCf00D81C55fD8eDf7C308D78C1f1D6cCeffDa6CdfdD53D63Da3Db3Cf00D00D01D02D03D04D05D06D07D10D20D30D40D50D60D70C44fDa7C00fD8fD9fDafDbfDcfDdfDefDf8Df9DfaDfbDfcDfdDfeDffC0f0D49CddfDeaDebDecDedCafaD55Cf66D08D27D67D71C66fD89D8aD8dCfbbD12D13D14D15C972D37CfffDa9CfdeD96Cd20D83C33fD7aD7dD7eC048Dc7C0f0D44D45D4bD54D64Da4Db4DbbC9f9Dc4Cf33D17C66fD98Da8Dd8Cd96D73C2f2D4cCfffD6aD6dD6eD6fD99Dd6De6CefdD59C44fD7fDd7De7De8C1f1D5cDb5CbfbD34D65CaafDeeCfddD21D31D41D51D61C6f6D5bDc5DcaDcbCfefD69C046Db7C090D47C7f7D9bCf11D82C00eD88C1f1DacDbcC0f0D46D4aCbeaD95C5f6Dc6CfeeD90D91D92Cb20D85C068Dc8C9f9D35D3aD3bCf44D18D28Cf89D76C3f3Db9CefeD56D5aCdebD93CfffDaaDc3C064D8cC080D48C7f7D6bC169D8bC1f1D9cCbfbDa5DccCb95D75Cf01D86C9f9D36Cf88D11C3f3Db6CdfdD43CfffD19D29C950D38C0c0D74C9f8D39Cf11D80C43fD97C5f6Dc9Cf34D68Cf99D72C3f3DbaCcfcD3cCe43D58C066Db8Cb15D77C406D87C0f0D94Ce65D57CfbbD16"{ imageID= getImageID(); run("Make Composite", "display=Grayscale"); if (isOpen("Channels")) { selectWindow("Channels"); run("Close"); } if (isOpen (imageID)) selectImage (imageID); // if (! is("composite")) run("Make Composite", "display=Grayscale"); setColorForChannels (imageID); if (!is("Batch Mode")) setBatchMode(true); if (isOpen (imageID)) selectImage (imageID); run("Make Composite", "display=Composite"); imageID= getImageID(); getDimensions(w, h, channels, slices, frames); for (i=0; i 1) Stack.setChannel(i+1); if (ColorChs[i] == "Red") run("Red"); if (ColorChs[i] == "Green") run("Green"); if (ColorChs[i] == "Blue") run("Blue"); if (ColorChs[i] == "Cyan") run("Cyan"); if (ColorChs[i] == "Yellow") run("Yellow"); if (ColorChs[i] == "Magenta") run("Magenta"); if (ColorChs[i] == "Grays") run("Grays"); } run("Channels Tool... "); setBatchMode("exit and display"); } var aCmds = newMenu("Adjust Channel Levels Menu Tool",newArray ("8 bit sampling \(0-255\)","10 bit sampling \(0-1023\)","12 bit sampling \(0-4095\)","15 bit sampling \(0-32767\)","16 bit sampling \(0-65535\)","min->max all channels","min->max each channel","between two set values","-","RGB Option")); macro "Adjust Channel Levels Menu Tool - C666Dc9Dd9De9Df9C00fDb0Db1Db2Db3Db4Dc0Dc1Dc2Dc3Dc4Dd0Dd1Dd2Dd3Dd4De0De1De2De3De4Df0Df1Df2Df3Df4C1f0D64C0bfD0bD1bD2bD3cD3dD3eD3fC777Da8Dc8Dd8De8Df8C23fDa0Da1Da2Cfe0D49CfffD9fCf00D14D24C04fD7cC5f0D93C1cfD4eD4fCf0dD79Cf0fD56D57D58D59D66D76D86D96D97D98Ccf3D06CfffD5bD5cD5dD5eD5fD6dD6eD6fD8bD8cD8dD8eD8fDcbDccDcfDdbDdcDddDdeDdfDebDecDedDeeDefDfbDfcDfdDfeDffCf00D00D01D02D03D04D10D11D12D13D20D21D22D23D30D31D32D33D34D40D41D42D43D44C3f0D73D83C0cfD0cD0dD0eD0fD1cD1dD1eD1fD2cD2dD2eD2fC14eDa4Ce0fD65Cff0D09D16D17D18D19D26D27D28D29D36D37D38D39C05fDbeC7e7D3aC9bfDbcCf0eD75CfafD7aCfc3D45C575Db9C2f0D50D51D52C787Da7C26fD9dCff0D47D48C05fD7eC896Db6C1cfD4dCf0eD69D77D87D88D99Cff1D46C4f0D70D71D72D80D81D82D94C888Dd7De7Df5Df7C59fDacC18fDabC6d9D0aCbdfDbfC887Da6CfafD6aCeeeDdaDeaDfaC2f0D53D63D74D84C787Db5C23fDa3C5f0D90D91D92C0cfD4cCf0eD78D89Cdf2D08Cf0fD67D68C16fDbdC8e7D1aD2aCacfD7fCf0eD85Cf9fD5aCdedDaaC686Db8C3f0D60D61D62C887Dc5Dc7Dd5De5C37fD9cC05fD7dC7bfDafCff2D15D25C6afDaeC0bfD3bC8e8D4aCeefDceC997Dc6Dd6De6Df6CfafD8aD9aCfeeDcaC1f0D54Ce1fD55C879Da5Cdf5D05C766Da9C19fD7bCff1D35C5afDbbCaffD9bC0dfD4bCcf3D07CaefD6bCf1dD95CefdDbaC797Db7C59fD9eC7afDadCeffDcdC8afD6c"{ cmd = getArgument(); if (cmd!="-" && cmd == "8 bit sampling \(0-255\)") { chosenContratsOption = "8 bit sampling \(0-255\)"; setLUTsHisto (); } if (cmd!="-" && cmd == "10 bit sampling \(0-1023\)") { chosenContratsOption = "10 bit sampling \(0-1023\)"; setLUTsHisto (); } if (cmd!="-" && cmd == "12 bit sampling \(0-4095\)") { chosenContratsOption = "12 bit sampling \(0-4095\)"; setLUTsHisto (); } if (cmd!="-" && cmd == "15 bit sampling \(0-32767\)") { chosenContratsOption = "15 bit sampling \(0-32767\)"; setLUTsHisto (); } if (cmd!="-" && cmd == "16 bit sampling \(0-65535\)") { chosenContratsOption = "16 bit sampling \(0-65535\)"; setLUTsHisto (); } if (cmd!="-" && cmd == "min->max all channels") { chosenContratsOption = "min->max all channels"; setLUTsHisto (); } if (cmd!="-" && cmd == "min->max each channel") { chosenContratsOption = "min->max each channel"; setLUTsHisto (); } if (cmd!="-" && cmd == "between two set values") { chosenContratsOption = "between two set values"; setLUTsHisto (); } if (cmd!="-" && cmd == "RGB Option") { RGBChoice (); } } macro "Adjust Min and Max Action Tool - C33bD4fD5fD6fD7fD8fD9fCfffD11D12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eD21D22D23D24D25D26D27D28D29D2aD2bD2cD2dD31D32D33D34D35D36D37D38D39D3aD3bD3cD41D42D43D44D45D46D47D48D49D4aD51D52D53D54D61D62D71D72D81D82D83D84D85D86D91D92D93D94D95D96D98D99D9aD9bD9cDa1Da2Da3Da4Da7Da8Da9DaaDabDacDadDaeDb1Db2Db3Db6Db7Db8Db9DbaDbbDbcDbdDbeDc1Dc2Dc5Dc6Dc7Dc8Dc9DcaDcbDccDcdDceDd1Dd4Dd5Dd6Dd7Dd8Dd9DdaDdbDdcDddDdeDe3De4De5De6De7De8De9DeaDebDecDedDeeDf2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdCbbbD0fD1fD97DcfDdfDefC44bDafCccdD88C22fD59D77CcccD01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eDb5CbbbD10D20D30D40D50D60D70D80D90Da0Db0Dc0Dd0De0CeeeDa5Db4Dc3Dc4Dd2C00fD4dD4eD5aD5dD5eD64D65D66D67D68D69D6cD6dD6eD78D7bD7cD7dD7eD8dD8eCcccD00CaaaD2fDffCccfD4bC22fD8cCfffD87C00dD79C44fD58CdddD2eD3dDe1De2Df1DfeCaafD74D8aCddfD89C33fD9eCeefD73C55bD3fCccdD3eC99fD56D63D75CccfD9dC00eD7aC88fD8bCddfD55C55bD4cCdddDa6Dd3CaaaDf0C00dD5bD6aD6bC66fD57D76C77bDbfC00fD5c"{ run("Color Balance..."); } macro "Z Projection Action Tool - C00aD37D62CfffD00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D13D14D15D16D17D1fD20D23D24D25D2fD30D33D34D3aD3fD40D43D4fD50D57D5fD60D66D67D6aD6bD6fD70D74D75D76D77D7fD80D81D83D84D85D86D87D88D8fD90D91D92D93D94D95D96D97D98D99D9aD9fDa0Da1Da2Da3Da4Da5Da6Da7Da8Da9DafDb0Db1Db2Db3Db4Db5Db6Db7Db8Db9DbfDc0Dc1Dc2Dc3Dc4Dc5Dc6Dc7Dc8Dc9DcfDd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9DdcDdfDe0De1De2De3De4De5De6De7De8De9DeaDebDecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC88eD31D41D51D61D9eC44cD7bD7cCcdfD56DdeC22cD2cD49D59D69CbbeD3eD44C66dDcbCfffD11D12D26D7eD82D89D8eD9bDbaC00bD2bDbcC9aeD21D73C55dD4bD5dD64D7dD9dCdefDcaC33cD8cCccfD18D19D1eD2eD5aD6cDaaC78dD4dDabC00bD38D45D72C99eD1bC55dD22D5cDbdCddfD1aD35D4aC33cD32D36D42D8bCbceD9cC77dD27C11bD3dD55CaaeD5eD6eD71D78DadDceCeefD3bD65DbeDdaDddC44cD4cD5bDcdC88dD58D68DccC00aD28D46D54D63C55dD79D8dCddfD8aC22cD29D52C77dD2dD53D6dCeefDacDdbC88dD3cD48C99eD47DaeCccfD2aC12cD39C67dDbbC99eD1cD1dCddfD4eD7a"{ Stack.getDimensions(widthS, heightS, channelsS, slicesS, framesS); run("Z Project...", "projection=&methodProj"); } macro "Remove Current Channel Action Tool - Ca11D4eCeeeD54Db2CbbbD44D64Db4CfffD00D01D02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eD0fD10D11D12D13D14D15D16D17D18D19D1aD20D23D24D25D26D27D28D29D35D36D37D38D46D47D48D4cD50D58D60D61D62D70D71D72D73D7bD7cD80D81D82D83D8cD90D91Da8Db6Db7Db8DbcDc4Dc5Dc6Dc7Dc8Dd0Dd1Dd2Dd3Dd4Dd5Dd6Dd7Dd8Dd9De0De1De2De3De4De5De6De7De8De9DeaDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffCb55D5eCfeeD8bCebbDa9Cc33D6bCeeeD22D42D6fDafDc0CcccD7eCaaaDb0CfffD39CeedD66Da3Cc11D9aCeeeD7dD8dD9fCccbD33Cc66D2fCfffD21D34D74Da7Dc9CdddD77Cd33DdcCdddD30D53D78D84D96Dc3Cb99D88CfffD3dDcdCeddD1fD3cCc11D5aCbbbD31D32D85D86D93Da2Da5Dc1Cd55D9cCeccD49Cb44D79CcccD45D55D63D6eD9eDb1Db3CbbbD40D52D56D75D76D97Dc2CfffDa0CeeeD7fD8fD92D95Db5Cc22DdeCcccD41D67D8eD94Da1Da6Cc66D8aCeddDebDefCc44DacCd99DbfCeeeD5fCb11D4aCc55DcfCeccD4bDdaCc44D1dCabaD87Cc22D2bCd66DddDdfDeeCdddD43D51D57D65Da4Cc33D6cD99DcaCd99D4fD59DbdCc11D2cD6aD89Cd55DabCeccDbbCb44DceCc32D69D9bCa99D68Cd44DcbCdaaD4dCfeeD1bDccCb11D5dCb55DaeCecbDb9Cc33D3aD3bCc11DbaCb99D98Cb11D2eCb44D3eCd22DdbCd77D1cDecCb11DadCc55D5bD5cCd22DaaCc65D1eCeccD2aCc44D2dD3fCc88D6dCd44DedCdaaD7aCc99D9dCb11Dbe"{ Stack.getPosition(channel, slice, frame); Stack.getDimensions(width, height, channels, slices, frames); if (channels <= 1) exit ("This function requires at least 2 channels"); showMessageWithCancel ("The channel "+ channel + " will be removed. Continue ?" ); run("Delete Slice", "delete=channel"); run("Make Composite"); imageID = getImageID(); run("Channels Tool... "); selectImage(imageID); } var dCmds = newMenu("On Line Documentation & Demo Menu Tool",newArray ("Open On Line Documentation","Download 3 Single-Channel Images","Download a 3 Channels Stack","Download a 4 Channels Stack","Download a 4D Stack","-","About this Toolset \(off line\)", "Version and Update Information")); macro "On Line Documentation & Demo Menu Tool - C000D89D8dD96D9dDa5Da6Db3Db4Db5Db6DbdC06fD12D13D14D15D16D17D18D19D1aD1bD1cD1dD1eC0f3D32D33D34D35D36D37D38D39D3aD3bD3cD3dD3eD3fCeeeD80C444DbeDcfC73fD01Cfd0D42D43D44D45D46D47D48D49D4aD4bD4cD4dD4eCfffD7cD7fD8fD91D98Dc1DceDd1Dd3DdeDdfDe0De1De2De3De4De5De6De7De8De9DeaDebDecDedDeeDefDf0Df1Df2Df3Df4Df5Df6Df7Df8Df9DfaDfbDfcDfdDfeDffC222C0feD22D23D24D25D26D27D28D29D2aD2bD2cD2dD2eC888D88CfffD71D90DcbDd0Dd2Dd4Dd5Dd6DdcCf74D50CcccD9fCbbbD97Da0Dc2C000Da4Db2C06fD11D1fC0f4D31CeeeD70D75D81D84D92D93Dc0Dc8Dd7DdaDdbCf40D51D52D53D54D55D56D57D58D59D5aD5bD5cD5dD5eD5fCa7fD00Cfd0D41D4fC444D95DbaDc9C0ffD21D2fC4f6D30CfffD7bCf88D62D63D64D65D6bD6cCeeeD72D73D74DabDbbDccDd8Cf89D6dC666Da7C84fD02D03D04D05D06D07D08D09D0aD0bD0cD0dD0eC333D86D87D8aD99D9cDb9DbcCaaaD8eDa1Dc3Dc4Dc5Dc6CeddD76Cf89D61D66D6aD6eD6fC222DadDcdC48fD10Cfd4D40C4ffD20CaaaDacDcaDddCfaaD60C555Da2C73fD0fC333D9bDa3Da9Db1C999D7dCdddD7aD83Da8Dc7CbbbDb8C111D9aDb7CaaaD8bCf99D67D68D69C777D8cDaaCdeeD82D85C999DafCdddDd9C766D79C555DaeC999D78CcccD7eD94C888D9eC777DbfC666Db0Ca99D77"{ cmd = getArgument(); if (cmd!="-" && cmd == "Open On Line Documentation") { doc (); } if (cmd!="-" && cmd == "Download 3 Single-Channel Images") { if (!is("Batch Mode")) setBatchMode(true); OpenImageLink(demoimagelink1,demoimagename1,1); run("Stack to Images"); setBatchMode("exit and display"); } if (cmd!="-" && cmd == "Download a 3 Channels Stack") { OpenImageLink(demoimagelink1,demoimagename1,1); } if (cmd!="-" && cmd == "Download a 4 Channels Stack") { OpenImageLink(demoimagelink3,demoimagename3,1); } if (cmd!="-" && cmd == "Download a 4D Stack") { OpenImageLink(demoimagelink2,demoimagename2,1); } if (cmd!="-" && cmd == "About this Toolset \(off line\)") { aboutTheTools (); } if (cmd!="-" && cmd == "Version and Update Information") { VersionInfos (); } } //macro "Version and Update Infos Action Tool - CcccD5fD6fD7fD8fD9fC78bD17D19D2aD33D37D3bD42D4cD75D95DceDd5Dd9De6Df7Df9CddeDa3C36bD27D28D3aD57D58D59D66D76D77D86D87Da7Db8Dd6De8De9CeeeD00D01D02D04D06D07D08D09D0bD0dD0fD10D11D12D14D1bD1dD1fD20D21D22D2dD30D31D32D40D46D47D48D49D50D5bD60D70D71D72D74D7dD80D81D82D84D8dD90D91D92D94D9dDa0Da1Da2Da4Db0Db1DbbDc0Dc1Dc6Dc7Dc8Dc9Dd0Dd1Dd2De0De1De2DedDf0Df1Df2Df4DfbDfdDffC8beD3cD3dD4dD5aD6aD79D7aD7bD85D8bD9aDaaDc3Dc4Dd3Dd4CeeeD03D05D0aD0cD0eD13D15D1cD1eD23D2eD3eD4aD55D6cD73D7cD7eD83D8cD8eD93D9cD9eDb5DcaDdeDe3DeeDf3Df5DfcDfeC559D18D26D34D35D36D41D51D61DafDbfDcfDdaDdbDddDeaDf8CcddD2fD5cD6dD6eDabDb2Db4Dc2DefC99bD16D24D39D45D54D56D64D65Da5DacDb6DbcDcbDd7DecDfaCdefD67D8aC59dD29D2bD68D69D78D88D96D97D98D99Da6Da8Da9Db9De5De7CacdD1aD2cD38D4bD4eD5dD5eD6bD89D9bDb3DbaDc5Dd8De4Df6C348D25D43D44Db7DccDdcDebCcccD3fD4fDdf" { // VersionInfos (); //} // menu popup giving acces to the original (full) functions of ImageJ (click right) var pmCmds = newMenu("Popup Menu", newArray("Stack to Hyperstack...","Channels Tool...","Z Project...","Delete Slice","Convert to RGB","-", "About this Toolset" )); macro "Popup Menu" { cmd = getArgument(); if (cmd !="-" && cmd =="Stack to Hyperstack...") {run("Stack to Hyperstack...");} if (cmd !="-" && cmd =="Channels Tool...") {run("Channels Tool... ");} if (cmd !="-" && cmd =="Z Project...") {run("Z Project...");} if (cmd !="-" && cmd =="Delete Slice") {run("Delete Slice");} if (cmd!="-" && cmd == "Convert to RGB") {run("Stack to RGB");} if (cmd !="-" && cmd =="About this Toolset") {aboutTheTools ();} } function stacksToHyperStacks () { if (nbChannel > nSlices) nbChannel=nSlices; totSlices = (nbz * nbChannel) * nbt; first=0; if (nbSlice != nbChannel) { while (totSlices != nSlices || first <1) { Dialog.create("Dimension Specifying"); if (totSlices != nSlices && totSlices > nbChannel) Dialog.addMessage("! Slice number of the current stack is not compatible with these settings\n"); Dialog.addNumber("Channel number ?", nbChannel); if (Zchoice ==1) Dialog.addNumber("z steps number ?", nbz); if (tChoice ==1) Dialog.addNumber("t steps number ?", nbt); Dialog.addChoice("Order of dimensions", channelOrderChoices, channelOrder); Dialog.show(); nbChannel =Dialog.getNumber(); if (Zchoice ==1) nbz=Dialog.getNumber(); if (tChoice ==1) nbt=Dialog.getNumber(); channelOrder=Dialog.getChoice(); totSlices = (nbz * nbChannel) * nbt; first ++; } } run("Stack to Hyperstack...", "order=&channelOrder channels=&nbChannel slices=&nbz frames=&nbt display=Grayscale"); } function RGBChoice () { getDimensions(w, h, channels, slices, frames); Dialog.create("RGB Option"); Dialog.addCheckbox("Generate an RGB document", rgbOption); Dialog.show(); rgbOption=Dialog.getCheckbox(); if ((!is("composite") && !is("hyperstack")) && rgbOption == 1) {rgbOption = 0; showMessage ("RGB Document option doesn't work for this kind of image");} } function setLUTsHisto () { if (!is("Batch Mode")) setBatchMode(true); imageID = getImageID(); if (bitDepth() == 24) {exit ("This function doesn't work with 24 bit RGB encoded images"); statut =0;} if (chosenContratsOption == "between two set values") contrastSettings2(); if (chosenContratsOption == "min->max each channel") contrastSettings(); getMinAndMaxForContrast (); if ((chosenContratsOption != "min->max each channel") && (chosenContratsOption != "between two set values")) globalAdjustContrastLevels (imageID); setBatchMode("exit and display"); } function contrastSettings () { setOption("ExpandableArrays", true); getDimensions(w, h, channels, slices, frames); Dialog.create("Min\/Max Each Channel Visual Contrast Adjustment"); if (channels >1) { Dialog.addMessage("Select the channel\(s\) to be optimized"); if (lengthOf(checkList) != channels) var checkList=newArray(channels); //resize for (i=0; i1) { for (i=0; i1) { Dialog.addMessage("Select the channel\(s\) to be optimized"); if (lengthOf(checkList2) != channels) var checkList2=newArray(channels); //resize for (i=0; i1) { for (i=0; imax all channels") { if (nSlices>1) { Stack.getStatistics(voxelCount, mean, min, max, stdDev); } else { getRawStatistics(nPixels, mean, min, max, std, histogram); } MinContrast=min; MaxContrast=max; } if (chosenContratsOption == "min->max each channel" || chosenContratsOption =="between two set values") { getDimensions(w, h, channels, slices, frames); if (channels <= 1) { // proceed as "min->max all channels" if (nSlices>1) { Stack.getStatistics(voxelCount, mean, min, max, stdDev); } else { getRawStatistics(nPixels, mean, min, max, std, histogram); } MinContrast=min; MaxContrast=max; for (h=1; h<=frames; h++) { if (frames >1) Stack.setFrame(h); for (i=1; i<=slices; i++) { if (slices >1) Stack.setSlice(i); if (chosenContratsOption == "min->max each channel") setMinAndMax(MinContrast, MaxContrast); if (chosenContratsOption == "between two set values") setMinAndMax(minUser, maxUser); } } } if (nSlices>1 && channels > 1) { Stack.getPosition(channel, slice, frame); // duplicate to batch nameOfStack=getTitle(); idOfStack=getImageID(); Stack.getDimensions(widthS, heightS, channelsS, slicesS, framesS); stringChannel="1-"+channelsS; stringSlices="1-"+slicesS; run("Duplicate...", "title=["+nameOfStack+"] duplicate channels=&stringChannel slices=&stringSlices"); call("ij.ImagePlus.setDefault16bitRange", 0); idOfStack2=getImageID(); selectImage (idOfStack); close(); selectImage (idOfStack2); nbchanneltotreat=0; if (chosenContratsOption == "min->max each channel") { for (a=0; a< lengthOf(checkList);a++) { if (checkList[a]==1) nbchanneltotreat ++; } if (depthChoice == depthChoices[1]) nbchanneltotreat=channelsS; } if (chosenContratsOption == "between two set values") { for (a=0; a< lengthOf(checkList2);a++) { if (checkList2[a]==1) nbchanneltotreat ++; } if (depthChoice2 == depthChoices[1]) nbchanneltotreat=channelsS; } statutMax=slicesS*framesS*nbchanneltotreat; currentStatut=0; for (j=1; j<=channels; j++) { showProgress(currentStatut/statutMax); if (chosenContratsOption == "min->max each channel") testChek= checkList[j-1]; if (chosenContratsOption == "between two set values") testChek= checkList2[j-1]; if (testChek == 1) { // cheklist2 pour min/max manuel Stack.setChannel(j); if (chosenContratsOption == "min->max each channel") { compt=0; miniChannel = newArray (slices * frames); maxiChannel = newArray (slices * frames); for (h=1; h<=frames; h++) { Stack.setFrame(h); for (i=1; i<=slices; i++) { Stack.setSlice(i); getStatistics(area, mean, min, max, std, histogram); miniChannel[compt]=min; maxiChannel[compt]=max; compt ++; } } Array.getStatistics(miniChannel, min, max, mean, stdDev); MinContrast = min; Array.getStatistics(maxiChannel, min, max, mean, stdDev); MaxContrast = max; } for (h=1; h<=frames; h++) { Stack.setFrame(h); for (i=1; i<=slices; i++) { Stack.setSlice(i); if (chosenContratsOption == "min->max each channel") {setMinAndMax(MinContrast, MaxContrast);} if (chosenContratsOption == "between two set values") {setMinAndMax(minUser, maxUser);} currentStatut ++; showProgress(currentStatut/statutMax); } } } else { Stack.setChannel(j); for (h=1; h<=frames; h++) { Stack.setFrame(h); for (i=1; i<=slices; i++) { Stack.setSlice(i); testDepth=0; if (depthChoice == depthChoices[1]) testDepth=1; if (depthChoice2 == depthChoices[1]) testDepth=1; if (testDepth==1) { if (bitDepth() == 8) {setMinAndMax(0, 255);currentStatut ++;showProgress(currentStatut/statutMax);} if (bitDepth() == 16) {setMinAndMax(0, 65535);currentStatut ++;showProgress(currentStatut/statutMax);} } } } } } if (is("composite") ) { Stack.getDisplayMode(mode); Stack.setDisplayMode("color"); Stack.setDisplayMode(mode); Stack.setPosition(channel, slice, frame); } } else { getRawStatistics(nPixels, mean, min, max, std, histogram); MinContrast=min; MaxContrast=max; } if (rgbOption == 1) run("Stack to RGB"); //makeRGB (); } } function globalAdjustContrastLevels (imageID) { if (isOpen (imageID)) selectImage (imageID); n = getSliceNumber(); if (is("hyperstack")) Stack.getPosition(channel, slice, frame); nbSlices=nSlices; // duplicate to batch nameOfStack=getTitle(); idOfStack=getImageID(); Stack.getDimensions(widthS, heightS, channelsS, slicesS, framesS); stringChannel="1-"+channelsS; stringSlices="1-"+slicesS; run("Duplicate...", "title=["+nameOfStack+"] duplicate channels=&stringChannel slices=&stringSlices"); call("ij.ImagePlus.setDefault16bitRange", 0); idOfStack2=getImageID(); selectImage (idOfStack); close(); selectImage (idOfStack2); statutMax=nbSlices; currentStatut=0; for (i=0; i0) { if (channels < lengthOf(ColorChs)) { ColorChs= Array.slice(ColorChs, 0, channels); } else { if (channels > lengthOf(ColorChs)) ColorChs=newArray(channels); //resize } for (i=0; i0) { for (i=0; i0) exit("You need an internet access to run this function."); } function doc () { netTest (); showMessageWithCancel ("A notice is avaible on line. Open it with your default web browser?"); run("URL...", "url=["+onlinedoclink +"]"); } function aboutTheTools () { requires("1.46i"); about="-------------------- \"Multi-Channels Image and Stack Helper\" ----------------------\n"; about= about+"This set of tools allows a fast and simple multi-dimentionnal level adjusting.\n"; about= about+"\nThis toolset proposes a regroupment of ImageJ functions useful to make some easy image \n"; about= about+"and multidimensional stacks visualisations. It also proposes some automatic level adjustment \n"; about= about+"options, and some convenient editing functionalities, especially for documents with a bit \n"; about= about+"depth greater than 8.\n"; about= about+"------------------------------------------------------------------------------\n"; about= about+"Installation: the tools file has to be stored in the \"ImageJ/macros/toolset\" repertory \n"; about= about+"------------------------------------------------------------------------------\n"; about= about+"Short documentation:\n\n"; about= about+"-\"Stack Menu\" tool allows to open stacks as hyperstacks (multidimensional stacks) and\n"; about= about+" to make composite images from single channel images."; about= about+" The \"Stack to Hyperstack...\" \n functions of ImageJ are available by click right menu.\n\n"; about= about+"-\"Make Composite\" tool converts stacks and hyperstacks into composite (multi channels) \n"; about= about+" images and hyperstacks, allowing the choice of the color affected to each channel. The \n"; about= about+" \"Channels Tool\" of ImageJ is available by click right menu.\n\n"; about= about+"-\"Adjust Channel Levels Menu\" tool allows several automatic level adjustments according to \n"; about= about+" different bit depths (8, 10, 12, 15 and 16). It also permits an optimization of the channel \n"; about= about+" LUTs between the minimum and the maximum of all channels, between the minimum \n"; about= about+" and the maximum of each channel or between two set values.\n"; about= about+"-\"Adjust Min and Max\" tool opens the \"Color Balance\" setting ImageJ window.\n\n"; about= about+"-\"Z Projection\" provides a Z projection according to the maximum intensity of a stack. The\n"; about= about+" full z projection options of ImageJ are available from the \"Z Project\" click right menu.\n\n"; about= about+"-\"Remove Current Channel\" allows to remove the active channel. The full options of ImageJ\n"; about= about+" to remove slices are available from the \"Delete Slice\" click right menu.\n\n"; about= about+"-\"Online Documentation and Demo\" tool bar menu provides internet resources like\n"; about= about+" documentation, sample images and updates.\n"; about=about + "\n------------------------------------------------------------------------------"; about=about +"\nAuthor : Gilles Carpentier"+"\nFaculte des Sciences et Technologies"+"\nUniversite Paris Est Creteil Val de Marne, France."; about=about + "\n------------------------------------------------------------------------------\n"; // from PrintToTextWindow macro available at the http://rsbweb.nih.gov/ij/macros/PrintToTextWindow.txt // author: Wayne Rasband title1 = "Infos for the \"16 bit Stacks Helper\""; title2 = "["+title1+"]"; f = title2; if (isOpen(title1)) { print(f, "\\Update:"); // clears the window print(f, about); selectWindow (title1); } else { run("New... ", "name="+title2+" type=[Text File] width=80 height=16"); print(f, about); } } function OpenImageLink(link,name,question) { // Check if already downloaded. demoimalocation = getDirectory("startup"); fildestination = demoimalocation+ "Downloaded Demo Images/" + name; if (File.exists(fildestination)) { if (question ==1 ) showMessageWithCancel ("The \"" + name + "\" has already been downloaded. Open it?"); open(fildestination); } else { netTest (); showMessageWithCancel ("ImageJ will download a demo image. Continue?"); run("URL...", "url=["+link+"]"); imageid = getImageID(); nomdimage = getTitle; // Create a repertory in ImageJ folder. ImaDemo = demoimalocation+"Downloaded Demo Images"+File.separator; File.makeDirectory(ImaDemo); if (!File.exists(ImaDemo)) exit("Unable to create directory, something wrong in the ImageJ folder"); selectWindow(nomdimage); save(""+ImaDemo+""+ nomdimage +""); } } // -------------------*** Additionnal code for on line update resources ***----------------------------- //Developer info //Kind:Toolset //Title:"Multi-Channels Image and Stack Helper" //Version:1.0.b //Date: 03 December 2013 //Origin:NIH //NotUpdateThisFile //End info function VersionInfos () { // variables for on line update resources beginsign="//Developer info";endsign="//End info"; kind="toolsets/"; urlrep="http://image.bio.methods.free.fr/ij/ijmacro/Composit/"; name="Multi-Channels Image and Stack Helper.txt"; namedev="Multi-Channels Image and Stack Helper.txt"; favoritefoldername= "Macros"; version=versionMessage(); if (indexOf(version, "install it?" ) > 0 ) { macrotext=getdistantmacro (namedev,urlrep);macrolocal=""; macropath=getDirectory("macros")+kind+namedev; if (File.exists(macropath)) {macrolocal=File.openAsString(macropath);} if (macrotext != macrolocal) { //perfom the installation Dialog.create("New version installation option"); Dialog.addMessage(version); Dialog.addCheckbox("Install a Plugin Shortcut?", 0); Dialog.addMessage("(This option provides a shortcut in the plugins menu of ImageJ, making easier\nthe next use of the new installed version)."); Dialog.show(); plugin= Dialog.getCheckbox(); f= File.open(macropath); print (f,macrotext); File.close(f); if (plugin ==1) {InstallPluginsStarter(namedev);} message="The installation of the "+giveDevInfo (macrotext,1)+ " "+ giveDevInfo (macrotext,2)+ "is completed."; message=message+ " Do you want to run it?"; showMessageWithCancel(message); run("Install...", "install=["+macropath+"]"); } } else {showMessage (version); // comment without installation available} } function versionMessage() { version=""; if (getDirectory("startup") == 0) exit ("Unable to find the startup directory, something wrong in the ImageJ folder"); if (getDirectory("macros") == 0) exit ("Unable to find the macros directory, something wrong in the ImageJ folder"); MacroPath=getDirectory("macros");thismacropath=MacroPath+kind+name; if (! File.exists(thismacropath)) exit ("This macro has to be recorded under the name of \"" +name+"\"\ninto the \"macros/"+kind+"\" folder of ImageJ."); macrotext=File.openAsString(thismacropath); macrotextdistant=getdistantmacro (namedev,urlrep); version="";macrolocal=""; version=version + "\n \nThis version of the " + giveDevInfo (macrotext,1) + " " + giveDevInfo (macrotext,2); version=version + "is provided by the " + giveDevInfo (macrotext,5)+ " web site."; version=version + "\nVersion number: " + giveDevInfo (macrotext,3)+ " - " + giveDevInfo (macrotext,4) +"."; if (macrotextdistant !="" ) { new=giveDevInfo (macrotextdistant,3);old=giveDevInfo (macrotext,3); if (new > old) { macropath=getDirectory("macros")+kind+namedev; if (File.exists(macropath)) {macrolocal=File.openAsString(macropath);} if (macrotextdistant != macrolocal) { update="\n \nA new version "+new+ " is available on the " +giveDevInfo (macrotextdistant,5)+ " web site: "; update=update+ "\n \nDo you want to install it?"; } else { update ="\n \nThe latest "+new+" version called \"" +namedev+ "\" provided by \nthe "+giveDevInfo (macrotextdistant,5) +" web site has already be installed"; update = update+ " in the \"" +kind+ "\" repertory \nof ImageJ."; } } else { update="No new version available."; } version=version +"\n" + update ; } return version; } function giveDevInfo (text,n) { lines=split(text,"\n"); if ( (indexOf(text, beginsign)<0) || (indexOf(text, endsign)<0) ) exit ("Not upgradable macro code."); for (i=0; lines[i] != endsign; i ++) {} for (j=i; lines[j] != beginsign; j --) {} infotext=newArray(i-j-1); for (i=0; i < infotext.length; i ++) {infotext[i]=lines[i+j+1];} info=infotext[n-1]; signature=":"; cut = indexOf(info, signature); info = substring(info,(cut+lengthOf(signature)),lengthOf(info)); return info; } // Function giving the content of a distant macro (name) located at the distant repertory (urlrep). function getdistantmacro (name,urlrep) { macrotextnih=""; erNetMessage ="Error: "; testlink = "/ij/macros/Arrays.txt"; if (indexOf (File.openUrlAsString(testlink), erNetMessage) < 0) { distantmacrolink = urlrep + name; if (indexOf(distantmacrolink, " ") > -1) { while (indexOf(distantmacrolink, " ") > -1) { distantmacrolink=substring(distantmacrolink, 0, (indexOf(distantmacrolink, " ")))+"%20"+substring(distantmacrolink, (indexOf(distantmacrolink, " ")+1),lengthOf(distantmacrolink) ); } } showStatus("Internet link..."); macrotextnih =File.openUrlAsString(distantmacrolink); showStatus(""); } else { showMessage ("No internet connection to looks for new version.");} return macrotextnih; } function InstallPluginsStarter(macroname) { // from MacroPluginShortcutsTool.txt codestarter = "run\(\"Install...\", \"install=[\"+getDirectory(\"macros\")+\""+kind+ macroname + "\]\"\);"; if (getDirectory("plugins") == "") exit ("Unable to find the Plugins directory; something wrong in the ImageJ folder."); if (endsWith(macroname, ".txt") || endsWith(macroname, ".ijm")) pluginname = substring(macroname, 0, (lengthOf(macroname)-4)); StarterDir = getDirectory("plugins")+favoritefoldername+File.separator; File.makeDirectory(StarterDir); if (!File.exists(StarterDir)) exit ("Unable to create "+favoritefoldername+" Macros directory, something wrong in the ImageJ folder."); starterplugin = StarterDir + pluginname +"_ .ijm"; f= File.open(StarterDir + pluginname +"_ .ijm"); print (f,codestarter); File.close(f); showMessage ("The plugin shortcut \"" +pluginname+ "\" will be available after\nImageJ restarting, in the \"Plugins->" + favoritefoldername + "\" menu."); } // *** End of additionnal code for on line update ressources ***