Project

General

Profile

Files » MRI_NDPI_Tools.txt

Volker Baecker, 01/26/2012 03:27 PM

 
/**
* MRI NDPI Tools
*
* written 2011 by Volker Baecker (INSERM) at Montpellier RIO Imaging (www.mri.cnrs.fr)
*/

var helpURL = "http://dev.mri.cnrs.fr/wiki/imagej-macros/NDPI_Tools"
var rows =1;
var columns = 4;
var lowerThreshold = 0;
var upperThreshold = 249;

macro "Unused Tool - C037" { }

macro "MRI Skin Tools Help Action Tool -C000T4b12?"{
run('URL...', 'url='+helpURL);
}

macro "Convert NDPI Images Action Tool - C000T4b12c" {
print ("Convert NDPI Images started");
dir = getDirectory("Choose a Directory");
files = getFileList(dir);
first = true;
nrOfImages = lengthOf(files);
for (i=0; i<nrOfImages; i++) {
file = files[i];
path = dir + file;
if (endsWith(file, ".ndpi")) {
if (first) {
print("Reading dimensions of available images, please wait...");
first = false;
resolutions = call("loci.formats.in.NDPIReader.getResolutionString", path);
Dialog.create("Select a resolution");
choices = split(resolutions, "\n");
Dialog.addChoice("resolution", choices, choices[2]);
Dialog.show();
resolution = Dialog.getChoice();
components = split(resolution, ":");
resolutionIndex = components[0];
}
out = dir + "tif";
if (!File.exists(out)) {
File.makeDirectory(out);
}
print("\\Update:converting image " + (i+1) + "/" + nrOfImages);
res = call("loci.formats.in.NDPIExporter.exportAsTif", path, out, resolutionIndex);
}
}
print ("Convert NDPI Images finished");
}

macro "Select cuts Action Tool - C000T4b12s" {
width = getWidth();
height = getHeight();
deltaX = height / (2*rows);
deltaY = width / (2*columns);
roiManager("Reset");
run("8-bit");
setThreshold(lowerThreshold,upperThreshold);
for (row = 1; row<=rows; row++) {
for (column=1; column<=columns; column++) {
y = ((2 * row) - 1) * deltaX;
x = ((2*column) -1) * deltaY;
v = getPixel(x,y);
print("v="+v);
while(v>upperThreshold || v<lowerThreshold) {
x--;
v = getPixel(x,y);
print("left");
}
print("x="+x+", y="+y);
doWand(x, y);
roiManager("Add");
}
}
resetThreshold();
}

macro "Select cuts Action Tool Options" {
Dialog.create("Select cuts tool options");
Dialog.addNumber("rows", rows);
Dialog.addNumber("columns", columns);
Dialog.show();
rows = Dialog.getNumber();
columns= Dialog.getNumber();
}

macro "Export Selections Action Tool - C000T4b12e" {
dir = getInfo("image.directory");
file = getInfo("image.filename");
path = dir+file;
outPath = dir + "cut/";
if (!File.exists(outPath)) {
File.makeDirectory(outPath);
}
comp = split(file, ".");
titleWithoutExt = comp[0];
ext = comp[1];
numberOfROIs = roiManager("count");
for (i=0; i<numberOfROIs; i++) {
roiManager("Select", i);
title = titleWithoutExt + "-" + (i+1) + ext;
run("Duplicate...", "title=" + title);
run("Select None");
saveAs("Tiff", outPath + title);
close();
}
}
(2-2/2)