diff --git a/AutoInstall/Line Profile Action Tool.ijm b/AutoInstall/Line Profile Action Tool.ijm new file mode 100644 index 0000000..4b271a7 --- /dev/null +++ b/AutoInstall/Line Profile Action Tool.ijm @@ -0,0 +1,148 @@ +macro "Line Profile Action Tool - CeefD8aCb8dD69CfffD00D01D02D03D04D05D06D07D10D11D12D13D14D15D16D17D20D21D22D23D24D25D26D27D28D30D31D3dD4fD5fD60D61D62D63D64D65D6fD70D71D72D73D74D75D76D77D78D7bD80D81D82D83D84D85D86D87D88D8bD8cD90D91D92D93D94D95D96D97D98D9bD9cDa0Da1Da2Da3Da4Da5Da6Da7DabDacDb0Db1Db2Db3Db4Db5Db9DbaDbbDbcDc0Dc1Dc2Dc3Dc4Dc8Dc9DcaDcbDccDd0Dd1Dd2Dd3Dd4Dd8Dd9DdaDdbDe0De1De2De3De4De5Df0Df1Df2Df3Df4Df5DffC9e8D2bCfffD7aDaaDb6CdfdD08DcfCfaaD38D54D57DfaCeefDd7De8CdadD6aCcb8D3bCdefD4cCfa9D0dCcadD5aC8dbD5dCfeeD48D50D67DfcCfbbD37D44D52D53D58DadCddfD0fD1fD2fD9aCcfcD1aCefeDafDfdCf77D41CaafD4eD79D89Da9Cbe9D0cCfeeD33D47D68DdcDeaCfddD40D46Df6CfbcD59CfffD32D49D66De9CfaaD2cD39D55D56D8dD9dDbdDf9CbbfDa8CafaD9eCfddD2dD34D7cDedCfccD1cD1dD35D3cCfffD1bD5eD7fD8fCc7aDf7C99fDe7C9f9D0bD18DfeCefeD9fDbfDdfDefCccfD1eD2eDc5Dc7Dd5CbfbD09D4bD6eCddfD3fDe6CaafD3eD4dDb7CafaD0aD8eCf99D43DcdDddDecCbe9DaeCfccD36D45D51DebDfbCccfD0eCafaD4aDdeDeeC78bD5bC99fDc6Dd6C8f8D19CdfdD29CbeaD6dCaf9D2aCf88D42CbbfD99Db8CbfaDbeCfa9D7dCe8aDf8C8bcD5cC9f9D7eCbfaDceCf99D6cCfaaD6b"{ +// macro to make line plots +// will select different colours to plot +// handles 8, 16 and 32 bit images as well as maximal 7 channels + +// version 4.1; Solved problem with x-coordinates in scaled images. +// version 4.2; Thanks to Michael Epping (mailinglist 15-05-2013) the X-scale on +// the scaled plot is also drawn corectly. +// version 4.3; The plot is now scaled depending on the channels selected by the user. +// The colour for each channel is first detected followed by selection of the +// colours by the user instead of the user has to select channel numbers. + +// Kees Straatman, University of Leicester, 19 January 2014 + + setTool("line"); + if (isOpen("ROI Manager")) { + selectWindow("ROI Manager"); + run("Close"); + } + inv = false; // To check if LUT is inverted + p = 0; //Counter for presence of plot + intensityBottom=0; + color = "black"; + getVoxelSize(vw, vh, vd, unit); + + // Check that there is a line selection + do{ + type = selectionType(); + if (type!=5){ + title="Warning"; + msg="The macro needs a line selection.\nMake a line selection and click \"OK\""; + waitForUser(title, msg); + } + wait(100); + }while(type!=5); + getLine(x1, y1, x2, y2, lineWidth); + + // Parameters for the plot + dx = (x2-x1)*vw; + dy = (y2-y1)*vh; + maxT=0; + minT=100000000; + Stack.getDimensions(width, height, channels, slices, frames); + + if (bitDepth==24){ + if (nSlices>1){ + roiManager("Add"); + run("Make Composite"); + wait(100); // Line is sometimes not transfered to the new image + setVoxelSize(vw, vh, vd, unit); + roiManager("select", 0); + //wait(100); + selectWindow("ROI Manager"); + run("Close"); + }else{ + run("Make Composite"); + } + } + + Stack.getDimensions(width, height, channels, slices, frames); // need to repeat because of creation of new composite + channel = newArray(channels); + color=newArray(channels+1); + + // to allow single channel profile in color + for (i=0; i1) Stack.setChannel(i); + getLut(reds, greens, blues); + if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==0)) color[i] = "red"; + if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==0)) color[i] = "green"; + if ((reds[i]==0)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "blue"; + if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "cyan"; + if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "magenta"; + if ((reds[i]==i)&&(greens[i]==1)&&(blues[i]==0)) color[i] = "yellow"; + if ((reds[i]==i)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "black"; + } + if (inv) run("Invert LUT"); // reset inverted image + + // Select channels to plot + if (channels > 1){ + Dialog.create("channels"); + Dialog.addMessage("Which channels do you want to plot?"); + for (i=0; i1) Stack.setChannel(i); + if(channel[i-1]==true){ + + // Plot different colours + if (p==0){ + profile=getProfile(); + Plot.create("multi Channel Plot", "Distance("+unit+")", "Intensity"); + Plot.setLimits(0,sqrt(dx*dx+dy*dy),intensityBottom,intensityTop); + p=1; + } + + // Scale the profiles for correct x-coordinates + run("Plot Profile"); + Plot.getValues(x, y); + close(); + Plot.setColor(color[i]); + Plot.add("line",x,y); + } + } + +} + diff --git a/AutoInstall/Plot_Multicolor4.3.ijm b/AutoInstall/Plot_Multicolor4.3.ijm new file mode 100644 index 0000000..784d52d --- /dev/null +++ b/AutoInstall/Plot_Multicolor4.3.ijm @@ -0,0 +1,148 @@ +// macro to make line plots +// will select different colours to plot +// handles 8, 16 and 32 bit images as well as maximal 7 channels + +// version 4.1; Solved problem with x-coordinates in scaled images. +// version 4.2; Thanks to Michael Epping (mailinglist 15-05-2013) the X-scale on +// the scaled plot is also drawn correctly. +// version 4.3; The plot is now scaled depending on the channels selected by the user. +// The colour for each channel is first detected followed by selection of the +// colours by the user instead of the user has to select channel numbers. + +// Kees Straatman, University of Leicester, 19 January 2014 + +macro plot_multicolor{ + setTool("line"); + if (isOpen("ROI Manager")) { + selectWindow("ROI Manager"); + run("Close"); + } + inv = false; // To check if LUT is inverted + p = 0; //Counter for presence of plot + intensityBottom=0; + color = "black"; + getVoxelSize(vw, vh, vd, unit); + + // Check that there is a line selection + do{ + type = selectionType(); + if (type!=5){ + title="Warning"; + msg="The macro needs a line selection.\nMake a line selection and click \"OK\""; + waitForUser(title, msg); + } + wait(100); + }while(type!=5); + getLine(x1, y1, x2, y2, lineWidth); + + // Parameters for the plot + dx = (x2-x1)*vw; + dy = (y2-y1)*vh; + maxT=0; + minT=100000000; + Stack.getDimensions(width, height, channels, slices, frames); + + if (bitDepth==24){ + if (nSlices>1){ + roiManager("Add"); + run("Make Composite"); + wait(100); // Line is sometimes not transfered to the new image + setVoxelSize(vw, vh, vd, unit); + roiManager("select", 0); + //wait(100); + selectWindow("ROI Manager"); + run("Close"); + }else{ + run("Make Composite"); + } + } + + Stack.getDimensions(width, height, channels, slices, frames); // need to repeat because of creation of new composite + channel = newArray(channels); + color=newArray(channels+1); + + // to allow single channel profile in color + for (i=0; i1) Stack.setChannel(i); + getLut(reds, greens, blues); + if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==0)) color[i] = "red"; + if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==0)) color[i] = "green"; + if ((reds[i]==0)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "blue"; + if ((reds[i]==0)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "cyan"; + if ((reds[i]==i)&&(greens[i]==0)&&(blues[i]==i)) color[i] = "magenta"; + if ((reds[i]==i)&&(greens[i]==1)&&(blues[i]==0)) color[i] = "yellow"; + if ((reds[i]==i)&&(greens[i]==i)&&(blues[i]==i)) color[i] = "gray"; + } + if (inv) run("Invert LUT"); // reset inverted image + + // Select channels to plot + if (channels > 1){ + Dialog.create("channels"); + Dialog.addMessage("Which channels do you want to plot?"); + for (i=0; i1) Stack.setChannel(i); + if(channel[i-1]==true){ + + // Plot different colours + if (p==0){ + profile=getProfile(); + Plot.create("multi Channel Plot", "Distance("+unit+")", "Intensity"); + Plot.setLimits(0,sqrt(dx*dx+dy*dy),intensityBottom,intensityTop); + p=1; + } + + // Scale the profiles for correct x-coordinates + run("Plot Profile"); + Plot.getValues(x, y); + close(); + Plot.setColor(color[i]); + Plot.add("line",x,y); + } + } + +} + diff --git a/README.md b/README.md index a9fd42b..5f2d06e 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,70 @@ To run the macro a single time open an image and via Plugins > Macros > Run... s Download and save the "Line Profile Action Tool" as described above using the name Line Profile Action Tool.txt. When you install this tool via Plugins > Macros > Install .. an icon will be added to the ImageJ/Fiji tool bar. Clicking this icon will execute the macro code. +## Auto installation of the tool during Fiji startup. +Clone repository or download code. +Copy the AutoInstall folder to the Fiji/macro directory. +Modify the StartupMacros.fiji.ijm script in the macro directory in the following way: + +Originally the sctipt contain this autostart past: +``` +macro "AutoRun" { + // run all the .ijm scripts provided in macros/AutoRun/ + autoRunDirectory = getDirectory("imagej") + "/macros/AutoRun/"; + if (File.isDirectory(autoRunDirectory)) { + list = getFileList(autoRunDirectory); + // make sure startup order is consistent + Array.sort(list); + for (i = 0; i < list.length; i++) { + if (endsWith(list[i], ".ijm")) { + runMacro(autoRunDirectory + list[i]); + } + } + } +} +``` +You can comment or delere it and replace it with this: + +``` +macro "AutoRun" { + // ----- 1) Run all .ijm scripts from macros/AutoRun/ ----- + autoRunDirectory = getDirectory("imagej") + + "macros" + File.separator + + "AutoRun" + File.separator; + + if (File.isDirectory(autoRunDirectory)) { + list = getFileList(autoRunDirectory); + Array.sort(list); // consistent order + + for (i = 0; i < list.length; i++) { + if (endsWith(list[i], ".ijm")) { + runMacro(autoRunDirectory + list[i]); + } + } + } + + // ----- 2) Install all .ijm macros from macros/AutoInstall/ ----- + autoInstallDirectory = getDirectory("imagej") + + "macros" + File.separator + + "AutoInstall" + File.separator; + + if (File.isDirectory(autoInstallDirectory)) { + installList = getFileList(autoInstallDirectory); + Array.sort(installList); + + for (i = 0; i < installList.length; i++) { + if (endsWith(installList[i], ".ijm")) { + // Only install, do NOT run + fullPath = autoInstallDirectory + installList[i]; + run("Install...", "install=[" + fullPath + "]"); + } + } + } +} +``` +Then the tool shall load on the startup. + + ## Disclaimer All the macros published on this repository can be used at your own risk. Although I did my best to ensure that they run as intended, there may be bugs, not expected use or changes to the ImageJ code that results in unexpected behaviour. If you notice a problem with any of the macros please let me know and I can try to solve the problem.