written by cail • posted in Experiment, How-To • 1,830 views 2 comments

Well, first of first, read the following introduction carefully
http://rsbweb.nih.gov/ij/developer/macro/macros.html (google cache)

There is a workshop going on right now. I sit through half of it and realized that all I need to know is what functions she used (Macros.zip). Because, I use ImageJ macro a lot (one example).

Here are my notes from her code.

  • ImageJ 2 is coming, combined effect of BioFormat, Fiji, ImageJ
  • in macro window, highlight the rows then command+r / ctrl+r will only execute part of the code, perfect for debugging
  • start from recording your own macro (menu: macro - record), and understand its code
  • nSlices for the slice number of an image stack (z stack or time lapse)
  • exist1 = File.isDirectory(pathToSaveTo + "max");
    if (exist1 != 1) {
    	File.makeDirectory(pathToSaveTo + "max");
    }
  • for (i = 1; i <= n; i ++) { // looping code}
  • for (n = 1; n <= nSlices; n ++){
    	setSlice(n); // go to slice n
    	run("Measure");
    }
  • for (n = 1; n <= nSlices; n ++) {
    	setSlice(n);
    	getStatistics(area, mean, min, max, stdev);
    	if (mean > maxMean) {
    		maxMean = mean;	//if it is larger than maxMean, then mark this slice as the new maxMean
    		frameToDup = n;
    	}
    }
  • orig = getImageID;
    
    newImage("cropped", "16-bit Black", 300, 300, nSlices);
    final = getImageID;
    
    setBatchMode(true);
    for (n = 1; n <= nSlices; n ++) {
    	selectImage(orig);
    	setSlice(n);
    	run("Copy");
    	selectImage(final);
    	setSlice(n);
    	run("Paste");
    }
    setBatchMode(false);
    
    //find the frame with the maximum intensity, go to that frame and reset brightness/contrast
    maxmax =0;
    setBatchMode(true);
    for (n = 1; n <= nSlices; n ++) {
    	setSlice(n);
    	getStatistics(area, mean, min, max);
    	if (max > maxmax) {
    		maxmax = max;
    		nofmax = n;
    	}
    }
    setBatchMode(false);
    
    // now go to slice with the maxmax and use that to reset intensities in the stack
    setSlice(nofmax);
    run("Brightness/Contrast...");
    resetMinAndMax();
    
    //convert the new stack into 8-bit, which is required for 3D volume projection
    selectImage(final);
    run("8-bit");
    //run the 3D projection viewer. Do a "record macro" to get your settings right. Make sure to enter the appropriate xy to z pixel ratio
    //for example, 200nm steps with 61nm/pixel in x,y is a ratio of 3.28
    run("3D Project...", "projection=[Brightest Point] axis=Y-Axis slice=3.28 initial=0 total=360 rotation=9 lower=1 upper=255 opacity=0 surface=100 interior=50 interpolate");
  • resetMinAndMax(), With 16-bit and 32-bit images, resets the minimum and maximum displayed pixel values (display range) to be the same as the current image's minimum and maximum pixel values. With 8-bit images, sets the display range to 0-255. With RGB images, does nothing. I usually do "Enhance Contrast", which actually will have over-expose problem, not ideal. I need to check for a 0-1000 range 16-bit image, what's the final 8-bit value will be using resetMinAndMax() - 8bit, or using "Enhance Contrast" - 8 bit

Now, you are ready to dig deeper - familiar with all built-in macro functions and use them!

100714-01.jpeg

Previous:
Next:

Leave a Reply