Skip to content

Instantly share code, notes, and snippets.

@romainGuiet
Last active October 29, 2020 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainGuiet/5dfee7977e27bdf695cbf4f0b2c3cb8a to your computer and use it in GitHub Desktop.
Save romainGuiet/5dfee7977e27bdf695cbf4f0b2c3cb8a to your computer and use it in GitHub Desktop.
ij macro prototype for lazy 3D annotations reyling on ROIs interpolation. #BIOP #FIJI #Annotations #Labels
// select an image with imcomplete labelling
// with first and last slice, plus some slices in the middle where you notice changes
#@File() image_path ;
// here we clear the environment
run("Close All");
print("\\Clear");
// Open image and get some infos about your file
open( image_path );
imcomplete_label_name = getTitle();
getDimensions(width, height, channels, slices, frames);
// labkit export slices as channels ! an issue should be open
if (channels > slices) run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices="+channels+" frames=1 display=Color");
if (frames > slices) run("Stack to Hyperstack...", "order=xyczt(default) channels=1 slices="+frames+" frames=1 display=Color");
getDimensions(width, height, channels, slices, frames);
// we need to know how many label are in the stack, "stack_max"
Stack.getStatistics(stack_voxelCount, stack_mean, stack_min, stack_max, stack_stdDev);
print("######################");
print(stack_max+" labels found");
img_name = File.getName(image_path);
img_nameNoExt = File.nameWithoutExtension();
dir = File.getParent(image_path);
// make an image to store full labelling
label_slice = slices ;
newImage("CompleteLabelling", "16-bit black", width, height, label_slice);
full_label_image = getTitle();
// for each Label Value
for (i = 1; i <= stack_max; i++) {
selectImage(imcomplete_label_name);
roiManager("reset");
//set threshold
setThreshold(i, i);
//detect object in the stack
run("Analyze Particles...", "add stack");
print("--------------------------");
print("cell"+i);
print( roiManager("count") +" rois found");
// Interpolate between existing ROIs to get the missing ROIs
roiManager("Interpolate ROIs");
print( roiManager("count") +" rois after interpolation");
// Fill the ROIs in the new image
selectImage(full_label_image);
setForegroundColor(i, i, i);
roiManager("Fill");
}
resetMinAndMax();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment