Posted by
Anderson, Charles (DNR) on
Nov 10, 2014; 5:25pm
URL: http://imagej.273.s1.nabble.com/Otolith-shape-analysis-tp5010333p5010359.html
To get you started, here is an old macro I used to segment fish images from background, crop that part of image, and save various shape measures in results. There is an extra loop to separate the largest particle -- the fish in my case-- from smaller objects. You will need to study the ImageJ/FIJI tutorial to understand converting RGB to 8 bit gray images, thresholding, analyze particles, setting which measurements are recorded, inverting images from black on white to white on black, etc..
Charles Anderson / MN DNR
// BatchFishCrop.txt 2 September 2011
// Saves name.jpg to the output directory:
// = cropped colored fish on white (or grey) background, yellow ROI
// Saves name.txt to the output directory:
// = Results, including rudimentary Feret information. WITHOUT header
// Saves name+pts.txt to the output directory:
// = Results of landmarks: area, X, Y, XStart, YStart, WITH header
// =========================================================================
// Modified 9/19/2011
// Produce *.jpg files for WildID, not *.tiff
// =========================================================================
// Setup
// =====
//setBackgroundColor(255, 255, 255); /// white background
setBackgroundColor(128, 128, 128); /// grey background
//run("Set Measurements...", "area centroid bounding feret's redirect=None decimal=2"); // No labels
run("Set Measurements...", "area centroid bounding shape feret's redirect=None decimal=2"); // No labels
indir = getDirectory("Input: select a directory");
list = getFileList(indir);
outdir = getDirectory("Output: create or select a directory");
setBatchMode(true);
start = getTime;
// Loop over input images
// ===================
for (i=0; i<list.length; i++) {
path = indir+list[i]; // ImageJ no longer tries to open Thumbs.db
open(path);
id = getTitle();
run("Duplicate...", "title=original");
run("Duplicate...", "title=enhanced");
// Produces "Red", "Green", "Blue"
run("RGB Stack");
run("Convert Stack to Images");
// Black fish 255 on white 0 invLUT
selectWindow("Blue");
setThreshold(0,254);
run("Convert to Mask"); // Black 255 fish and ground; white board.
// *** For measure board calibration here:
// Finding Nemo
// ===========
// For either board on edge or not on edge:
// Analyze Particle options:
// [show=Nothing or show=Masks; display to show results; exclude on edges; clear results;
// include holes; summarize, record starts; add to Manager; show in situ;]
//run("Analyze Particles...", "size=100-Infinity circularity=0.0-1.00 show=Masks display exclude clear record add");
run("Analyze Particles...", "size=100-Infinity circularity=0.0-1.00 show=Nothing exclude clear add");
largestarea = 0;
index = 0;
for(j=0; j < nResults; j++){
testarea = getResult("Area", j);
if(testarea > largestarea) {
largestarea = testarea;
index = j;
}
}
selectImage("original");
roiManager("Select", index);
run('Clear Outside');
run("Crop");
// Save Nemo
// =========
dotIndex = lastIndexOf(id, ".");
if (dotIndex!=-1)
name = substring(id, 0, dotIndex);
//saveAs("tiff", outdir+name+".tif");
saveAs("Jpeg", outdir+name+".jpg");
// Save Points and Nemo data (if red dots are needed to calibrate the board for projective transformation)
// =========================
saveAs("Measurements", outdir+name+".txt");
// Area, X, Y, BX, BY, Width, Height, Feret, FeretX, FeretY, FeretAngle, MinFeret [No header]
// Area, X, Y, BX, BY, Width, Height, Circ., Feret, FeretX, FeretY, FeretAngle, MinFeret, Ar, Round, Solidity, XStart, YStart //with shape
// Clean Up
// Close unneeded images
while(nImages>0) {
selectImage(nImages());
run("Close");
}
} // End looping over images
if (isOpen("ROI Manager")) {
selectWindow("ROI Manager");
run("Close");
}
if (isOpen("Results")) {
selectWindow("Results");
run("Close");
}
print(list.length);
print((getTime - start)/1000, " seconds");
setBatchMode(false);
wait(5000);
if (isOpen("Log")) {
selectWindow("Log");
run("Close");
}
// =========================================================================
________________________________________
From: ImageJ Interest Group [
[hidden email]] on behalf of Draktibo [
[hidden email]]
Sent: Saturday, November 08, 2014 1:18 PM
To:
[hidden email]
Subject: Otolith shape analysis
Hi all,
new to imageJ (and no coding/macro experience) and have some questions about
image J's potential for shape analysis.
1/ Is there any way to batch convert colour images to B & W so that i would
have a white image on a black background or vice versa?
2/ When i analyse an image, how do i set it so the measurements are of the
particular shape outline (within the image) rather than the whole image
outline?
3/ How do i go about selecting a shape outline to measure? Again is there
any way to batch measure multiple images with shape outlines or images with
white shapes on black background?
thank you in advance!
Craig.
--
View this message in context:
http://imagej.1557.x6.nabble.com/Otolith-shape-analysis-tp5010333.htmlSent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html