Skip to content

Instantly share code, notes, and snippets.

@omsai
Created March 9, 2012 00:55
Show Gist options
  • Save omsai/2004402 to your computer and use it in GitHub Desktop.
Save omsai/2004402 to your computer and use it in GitHub Desktop.
ImageJ line profile signal length over time
/*
Calculate specimen width in pixels using a line profile
Requires:
- Single channel image stack
- Line profile drawn on image
Algorithm:
- Assumes a single signal level threashold
- Checks each line profile pixel intensity from the left for start
- Checks each line profile pixel intensity from the right for end
- Difference is specimen width
- Result units is pixels (i.e. uncalibrated)
Pariksheet Nanda <pariksheet.nanda@gmail.com>
*/
macro "Line Measure" {
SIGNAL_THRESHOLD = 160
requires("1.42j"); // Array
// remember the original hyperstack
id = getImageID();
// we need to know only how many frames there are
getDimensions(dummy, dummy, dummy, slices, dummy);
lengths = newArray(slices);
// Results window
run("Clear Results");
// for each slice...
for (slice = 1; slice <= slices; slice++) {
// select the slice
selectImage(id);
Stack.setPosition(1, slice, 1);
// get plot data
value = getProfile();
positions = lengthOf(value);
// find data start position from left
x1 = 0;
while ( x1 < positions && value[x1] < SIGNAL_THRESHOLD) {
x1++;
}
//write("Data start at line pixel: " + x1);
// find data start position from left
x2 = positions - 1;
while (x2 >= 0 && value[x2] < SIGNAL_THRESHOLD) {
x2--;
}
//write("Data ends at line pixel: " + x2);
// calculate and record line length
length = x2 - x1;
setResult("Pixels", slice - 1, length);
lengths[slice - 1] = length;
} // for
// Results window
updateResults();
// Plot profile
Plot.create("Profile of signal length", "Slice", "Length", lengths);
} // macro
/*
References:
- Introduction to Macros
http://fiji.sc/wiki/index.php/Introduction_into_Macro_Programming
- Built-in Macro functions
http://rsb.info.nih.gov/ij/developer/macro/functions.html
- Example of getProfile()
http://rsb.info.nih.gov/ij/macros/GetProfileExample.txt
- Example of Arrays
http://rsb.info.nih.gov/ij/macros/examples/ArrayFunctions.txt
- Example of setResults()
http://rsb.info.nih.gov/ij/macros/SineCosineTable.txt
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment