Last active
March 18, 2022 08:08
-
-
Save romainGuiet/4c9d795fe21df30c356efccaa4942043 to your computer and use it in GitHub Desktop.
An example ImageJ macro language script to run DiAna (images available here : https://drive.switch.ch/index.php/s/nfVRYJIic3lsfhm , supporting slides here : https://go.epfl.ch/2020-intro-diana ) #BIOP #Fiji #Coloc #DiAna
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#@File(label= "Input composite multi channel image" ) image_path | |
#@int(label= "Channel A index") channelA | |
#@int(label= "Channel A threshold", value=5) thresholdA | |
#@int(label= "Channel B index") channelB | |
#@int(label= "Channel B threshold", value=30) thresholdB | |
// make sure everything is clean | |
run("Close All"); | |
// open the user selected image | |
open(image_path); | |
// get some info bout the image : Name without Ext, directory... | |
dir = File.getParent(image_path); | |
img_noExt = File.nameWithoutExtension ; | |
dir += File.separator ; | |
// and create an output directory | |
output_dir = dir + "output_chA"+channelA+ | |
"_thA" +thresholdA + | |
"_chB" +channelB + | |
"_thB" +thresholdB + File.separator ; | |
File.makeDirectory(output_dir); | |
/* | |
* Here we start ! | |
*/ | |
// get some info bout the image : title, size, channels... | |
imageTitle = getTitle(); | |
getDimensions(width, height, channels, slices, frames); | |
// DiAna split channels anyway, but I prefer to do it myself ;) | |
run("Split Channels"); | |
// User defined channel are selected and channel Title Stored in a varaiable | |
// alternative way of doing it : | |
// imageATitle = "C"+channelA+"-"+imageTitle; | |
// imageBTitle = "C"+channelB+"-"+imageTitle; | |
selectImage("C"+channelA+"-"+imageTitle); | |
imageATitle = getTitle(); | |
selectImage("C"+channelB+"-"+imageTitle); | |
imageBTitle = getTitle(); | |
// Segmentation on each channel | |
run("DiAna_Segment", "img=["+imageATitle+"] filter=none rad=1.0 thr="+thresholdA+"-3-2000-false-false"); | |
imageALabelTitle = getTitle(); | |
// note that here we do apply a median filter | |
run("DiAna_Segment", "img=["+imageBTitle+"] filter=median rad=1.0 thr="+thresholdB+"-3-20000-false-false"); | |
imageBLabelTitle = getTitle(); | |
// this is not necessay, just scatters the images on your screen | |
// so you have something to look at while DiAna Analyse is processing | |
run("Tile"); | |
// Here we do the analysis, | |
// takes longer than the GUI (don't know why, yet ) | |
run("DiAna_Analyse", "img1="+imageATitle+ | |
" img2="+imageBTitle+ | |
" lab1="+imageALabelTitle+ | |
" lab2="+imageBLabelTitle+ | |
" adja kclosest=1 dista=0.0"); | |
// We're done with the "Image Processing" part | |
/* | |
* Now we can take care of the results | |
* | |
* DiAna overwrites the table AdjacencyResults | |
* BUT | |
* when we'll do Batch we want to keep all the resutls in 1 table | |
* | |
* Here we store the value "Dist min EdgeA-EdgeB" | |
* modify the code to get another value | |
* | |
*/ | |
selectWindow("AdjacencyResults"); | |
labels_array= Table.getColumn("Label"); | |
minEdgeDist = Table.getColumn("Dist min EdgeA-EdgeB"); | |
// tot store tha name of the image in the same table | |
// we have to prepare the array with the right length and the imageName | |
imageName_array = newArray(minEdgeDist.length); | |
// Array.fill works only with numbers, so we use a loop to fill the array | |
for (i = 0; i < imageName_array.length; i++) imageName_array[i] = imageTitle; | |
// Initiate the resutls table | |
if (!isOpen("Results.csv")) { | |
Table.create("Results.csv"); | |
Table.setColumn("Image Name", newArray(0)); | |
Table.setColumn("Label", newArray(0)); | |
Table.setColumn("Dist min EdgeA-EdgeB", newArray(0)); | |
} | |
// get image name, labels and values stored in it | |
selectWindow("Results.csv"); | |
previousImgName = Table.getColumn("Image Name"); | |
previouLabels = Table.getColumn("Label"); | |
previousValues = Table.getColumn("Dist min EdgeA-EdgeB"); | |
// concatenate arrays | |
concatNames = Array.concat(previousImgName,imageName_array); | |
concatLabels = Array.concat(previouLabels,labels_array); | |
concatValues = Array.concat(previousValues,minEdgeDist); | |
// Update the Table with the previous and new values | |
selectWindow("Results.csv"); | |
Table.setColumn("Image Name" , concatNames ); | |
Table.setColumn("Label" , concatLabels ); | |
Table.setColumn("Dist min EdgeA-EdgeB" , concatValues ); | |
// Save the Results table (with overwriting!!!) | |
// in batch it will overwrites it, but still adding new values | |
selectWindow("Results.csv"); | |
saveAs("results", output_dir+"Results.csv"); | |
// Save an output image made of the detected objects A & B (as slices) | |
run("Images to Stack", "name=resutls title=labelled use"); | |
saveAs("tiff", output_dir+img_noExt+"_results.tif"); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment