ImageJ
From NoskeWiki
Contents |
About
ImageJ is an open source java-based image processing program designed for analysis of various microscope data. ImageJ is powerful in that it allows you to write your own simple plugins as .java files - many plugins have been written (see list) - most of these .jar files you can simply drag into the "plugins" directory. Due to it's open source nature, many people have also "built" or taken from ImageJ, including the program "CellProfiler" (Carpenter et al 2006 [1]) and others listed here.
For image segmentation, Figi is useful - it's basically ImageJ with a large number of plugins and segmentation tools already built in.
Pros:
- Free and popular among light microscope users and already installed on many computers.
- Appears to be powerful; has quite a few filters image processing algorithms and filters
- Can record macros and write plugins
- Can read and write all popular image formats: .tif, .jpg, .bmp etc.
- Can make multiple selections using [t] and save selection as .roi files.
- Can perform many type of analysis on selections
Cons:
- Not a particularly nice or intuitive interface
- Drawing tools quite crude - and selection based only - although can at least move selections
- Does not open .mrc format (not without TomoJ plugin), although does open stacks of tif
- Support isn't very well organized
- Had trouble compiling plugins
- Surprisingly buggy
Installation
You can download the latest stable version of ImageJ here and installation is as simple as running the .exe (on Windows) or copying the ImageJ folder into the Applications directory (on Mac).
Nucleus Separation Example
In light microscopy, biologists often stain the DNA in the cell nuclei with DAPI to help see the Nucleus. On the Fiji website there is a very nice article on how to count and isolate these nucleus. The full article is here: Nuclei Watershed Separation, and below are the key points from this article with a few optional steps added courtesy of Alex Perez:
- Install Fiji and open your DAPI stained image:
- optional - if your image looks washed out (i.e. it has low contrast): select (menubar) > Process > Enhance Contrast, then whatever value gives good contrast (try 2%).
- optional - if your image looks highly speckled: select Noise > Despeckle, and maybe even run a second time or consider binning by 2 (Image > Scale then halve the image size).
- Gaussian blur - select Process > Image > Gaussian Blur with sigma 2-3. TIP: The median filter is another good one to try
- Threshold - select Image > Adjust > Threshold, turn the checkbox for "dark background" on, adjusting the levels to select the boundaries as close as possible (try ~100 to 255) then click Apply which should give you white Nuclei and a black background.
- 8-bit - depending on your image it may need to be converted to 3-bit by going: Image > Type > 8-bit
- optional - if you find your Nuclei are a bit large you can erode them by going: Process > Binary > Erode or chose Dilate instead to make bigger.
- Invert - select Edit > Invert. NOTE: In their instructions they want you to leave the Nuclei black, but in *most* cases Watershed wants white object hence we need to invert.
- optional - if you notice some holes in your nucleus run: Process > Binary > Fill Holes. NOTE: Careful with this one as it might fill larger areas than you intend.
- Watershed - select Process > Binary > Watershed. This process should identify roughly round objects and split apart the touching nuclei. NOTE: If you find lines are drawn across your background hit undo (Edit > Undo), invert the image and retry.
- Analyze - select Analyze > Analyze Particles. Tick all of the checkboxes except "include holes" and "in situ Show" and set show to "Outline". Where it says size you should enter "20-Infinity" to ensure that tiny regions (less than 20 pixels) are not included. Click okay and in the ROI manager it will allow you to delete certain regions of interest. When you close the "Results" panel it will prompt you to save the results of sizes to a xls file.
Once you've done this a few times and are happy with all your parameters and results you can then create a Macro to apply these steps automatically to a series of files. There are instructions on how to record and apply instructions are here: How to apply a common operation to a complete directory. The basic steps are:
- Click Plugin > Macro > Record.
- Perform all your actions (see above).
- Save the file as "output.tif" in desired directory.
- In the Macro Recorder window change the name to "Macro_DAPI_Watershed.ijm", click "Create" then save this file to disk.
- Close the "Recorder", open a new image and click "Run" in the "Macro_DAPI_Watershed.ijm" to test it works.
At this stage you'll notice it overwrites exactly the same files, so you'll want to adapt your ".ijm" macro file to automatically process a whole directory of files and save each to a different file name. To do this modify your code so it looks like this:
input = "/Users/yourusername/Desktop/images/in/"; // |- be sure to change these two paths to output = "/Users/yourusername/Desktop/images/out/"; // | to match your own directory names setBatchMode(true); list = getFileList(input); for (i = 0; i < list.length; i++) DAPI_nuclei_threshold(input, output, list[i]); setBatchMode(false); function DAPI_nuclei_threshold(input, output, filename) { open (input + filename); // this //-- Here are the lines you recorded: run("Enhance Contrast", "saturated=2"); run("Gaussian Blur...", "sigma=3"); setAutoThreshold("Default dark"); //run("Threshold..."); setThreshold(100, 255); run("Convert to Mask"); run("Erode"); run("Fill Holes"); run("8-bit"); //run("Invert"); run("Watershed"); //-- Uncomment these next few lines to save xls files too: //run("Analyze Particles...", "size=20-Infinity circularity=0.00-1.00 show=Nothing exclude clear record"); //saveAs("Results", output + filename + ".xls"); saveAs("Tiff", output + filename); close(); }
Running this code should process all files in your "in" directory into the "out" directory you specified. To run this Macro at a later time open Fiji then select Plugins > Marcos > Run.. then select your .ijm file.... or alternatively you can execute a Macro from the command line. On Mac OSX the command will look like this:
/Applications/Fiji.app/Contents/MacOS/fiji-macosx /Users/anoske/Desktop/images/Macro_DAPI_Watershed.ijm
In Alex's project this came in useful because he wanted to convert a 3D dataset from IMOD in MRC file format. While Fiji can open MRC files, not all its functions apply over 3D and it can't save MRC, so instead Alex used scripts to save the MRC to tifs, run the Image J macro, then joined all these new tifs back into a new MRC. In the final steps he then generate IMOD contours and surface meshes over the various boundaries. The unix commands for this were:
cd /Users/yourusername/Desktop/images/in/ # goes to your "in" directory imod2tif vol.mrc vol # converts MRC to a series of tifs called "vol.000.tif, vol.001.tif" etc ###... RUN MACRO HERE (macro will take the images in the "in" folder and save them to the "out" folder) cd ../out/ # changes directory to your "out" folder tif2mrc *tif vol_new.mrc # inputs all the processed tif in the "out" folder and turns them into one MRC imodauto -f 1 vol_new.mrc vol.mod # will trace contours around all the black regions and save this to an new IMOD model file "vol.mod" imodmesh -p 10 vol.mod vol.mod # all contours which overlap by over 90% get meshed into the same surface imodsortsurf -s vol.mod vol_split.mod # will sort contours and split all surfaces into different objects with different colors imodmesh -p 10 vol_split.mod vol_split.mod # re-meshes the "split object" version of our .mod file 3dmod ../in/vol.mrc vol_split.mod # opens this .mod file over the MRC file in 3dmod so we can see how well contours fit over original data 3dmod ../in/vol.mrc vol_new.mrc vol.mod # (optional) use this line to flip between the original and processed MRC files
Particle Analysis Example
A tall, slightly effeminate friend of mine had an interesting problem where he wanted to mark up alveoli inside the lungs of a developing mouse embryo imaged with a light microscope. Apparently there are tens of these things, and many on top of each other; therefore making it difficult for automatic segmentation.
Instead I suggested marking them up manually by drawing circles, and using the following steps:
- Open the image file. (eg: File >> Open Samples >> Embryos)
- NOTE: Use [+] and [-] to zoom in and out.
- Click: Analyze >> Set Scale and set the number of pixels / um (tick global).
- (Optional) Add a scale bar by going: Analyze >> Tools >> Scale Bar (but be careful not to obscure image).
- Hit save - for .tif files at least it appears to save the scale.
- Select the "ellipse tool" (second from left) and draw the first circle.
- Click: Edit >> Selection >> Add to Manager) and the "ROI manager" will open.
- Toggle the "Show All" button on the ROI manager.
- Continue to draw all circles and add with [t] one at a time.
- NOTE: Holding shift you can make perfect circle, but be careful it also can make multiple circles in the same selection.
- Click: Analyze >> Set Measurements and select desired properties (in this case only area is important).
- Hold shift and select all the circles in the ROI manager and click "Measure"
- Save this out output [ctrl+s] as an .xls file.
- Within Excel you can determine the radius using the formula =SQRT(B2/PI()) and estimate the volume as =4/3*PI()*POWER(C3,3) .
- With ALL the circles still selected click "Save" in the ROI manager (so you can come back to it later) to save the "RoiSet" as a .zip file.
- NOTE: By default it will only try to save the current selection (shown in yellow) as a .roi file.
To reopen this you simple start ImageJ, then open the image file, then open the "RoiSet" .zip file. It also looks like you might also be able to batch process a number of these using: Plugins >> Analyze >> Batch Measure, but I haven't figured this out yet.
Links
| Acknowledgements: Alex Perez from NCMIR for finding and testing the Nucleus separation instructions |
