Note: This work has been done in a Linux environment. Most of what follows will work in Linux or OSX. For Windows, try using a unix shell emulator, such as that available from Janotech. Alternately, install Portable Ubuntu, which creates a virtual Ubuntu (linux) machine in Windows. Please let me know if either of these works for you - I don't use Windows much, but I'm curious.
Color Saver - a macro for ImageJ
- Download ImageJ.
- Download the ColorSaver macro, and save it the Macros folder in the ImageJ folder.
- Launch ImageJ, and open an image.
- Install the macro. Choose Plugins> Macros> Install, then navigate to the macros folder and select "Color Saver.txt"
- Click the blue dot button, and click to select pixels in the image.
R code for threshold determination
We used the R code in this file to import and plot the pixel sample data to find thresholds. Note - these are written as functions for convenience. Also, the combination of axes and plots we used may not work for you - adapt these tools as needed.
CIMG code and how to use CIMG
Our image analysis program can be used as an example - alter and modify as you need to.
CImg is all contained in a c++ header file which you can download at the the website. Alternatively, if you are using linux (ubuntu) you can install it from the repositories. Simply include the header file into you cpp file and you are good to go. You can see the inclusion statement in our program on line 1.
For writing your program you need an text editor (like gedit in linux, or Text Wrangler in OSX) or use an integrated development environment (ide) like the c++ version of eclipse. Your are probably best off using our program as an example and modifying that.
Once your program is written, you need to compile it. On ubuntu you can install the build-essentials package which will give you all the necessary compilers. On the mac you should install the Xcode package that you can download - but is also included on your mac installation cd. On windows you can either pay for visual c++ or so or install the gcc compiler package using cygwin. Alternately on Windows, install Portable Ubuntu, then you can use gedit for editing, and install the compilers by installing the build-essentials package.
Once you have gcc installed you compile the program with something like: g++ myProgramFile.cpp -o myWonderfulProgram . (On windows you may want to give the programs name the .exe extension as is customary). If the compile does not give you any error messages, than you good to go and test your program.
Shell script for batch processing
The shell script does 3 things:
- rename all the .jpg files to replace all spaces with underscores
- use the "find" command to find all .jpg files in the current directory and run the image analysis program on them using the supplied thresholds
- concatenate the individual image results into a single results file and remove the individual files
Other notes
When the shell script runs, it creates 5 images for every image in the directory:
- name.JPG (original file)
- name_lfsX.jpg (leaf mask)
- name_resX.jpg (residue mask)
- name_soilX.jpg (soil mask)
- name_xblX.jpg (borderline pixels mask)
- name_eval.jpg (false color image)
We usually inspect a few complete sets of images before using the remove command:
rm *X.jpg
to remove all but the original and evaluation images.
To remove all evaluation images, try rm *eval.jpg
When adjustments to thresholds are needed, it is helpful to compare new and old evaluation images.
To accomplish this, rename the original images using the rename command:
rename 's\*eval\*eval1\g' *.jpg
An image viewer that allows you to arrow or scroll through a whole directory of images makes reviewing these images simpler. The default image viewer in Ubuntu Linux works well. Xee would work well on OSX.
C++ source code, 10.5 KB
Plain Text, 1.6 KB
Plain Text, 3.3 KB
Plain Text, 2.1 KB