This macro (see the entire code at the end of this post) starts by chopping a stack into a user defined number of parts. In my test .tiff file i have been chopping, I start with 2 channels and 2 slices per channel (to simplify everything). This creates 16 new, open image windows with unique names that can be sorted numerically (the original Tiff is closed). In the second part of this macro, I create an ordered list of these image titles. I have put in place several print functions to see what is going wrong (you can ignore those). What is strange is imag1 and imag2 are the correct 2 images to concatenate as confirmed by the print function but the Run concatenate actually chooses two different images to concatenate ignoring the original value of imag1 and imag2! I don’t understand why those values are not working once they are placed in the “Run Concatenate” function.
Test file I am using if anyone wants to try it out: MEG122820.lif - Series016-TESTFILE.tif (7.7 MB)
list = getList(“image.titles”);
print(“Image windows (not sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
Array.sort(list);
if (list.length==0)
print(“No image windows are open”);
else {
print(“Image windows (sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
}
imag1 = list[0];
imag2 = list[1];
print(“first 2”);
print (imag1);
print (imag2);
run(“Concatenate…”, " title=[Concatenated Stack] image1=[imag1] image2=[imag2] image3=[-- None --]");
list = getList(“image.titles”);
print(“Image windows (not sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
Array.sort(list);
print(“Image windows (sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
Sample image and/or code:
n = getNumber(“How many divisions (e.g., 2 means quarters)?”, 2);
width = getWidth();
height = getHeight();
tileWidth = width / n;
tileHeight = height / n;
Stack.setPosition(1, 1, 1);
getDimensions(w, h, channels, slices, frames);
Stack.getPosition(channel, slice, frame);
print("Position (before): “+channel+”, “+slice+”, "+frame);
Stack.setPosition(channels, slices, frames);
Stack.getPosition(channel, slice, frame);
print("Position (after): “+channel+”, “+slice+”, "+frame);
Stack.setPosition(1, 1, 1);
for (a=1; a<=channels; a++) {
for (b=1; b<=slices; b++) {
Stack.setChannel(a);
wait(50);
Stack.setSlice(b);
wait(50);
width = getWidth();
height = getHeight();
tileWidth = width / n;
tileHeight = height / n;
id = getImageID();
title = getTitle();
getLocationAndSize(locX, locY, sizeW, sizeH);
i=1;
for (y = 0; y < n; y++) {
offsetY = y * height / n;
for (x = 0; x < n; x++) {
offsetX = x * width / n;
selectImage(id);
call(“ij.gui.ImageWindow.setNextLocation”, locX + offsetX, locY + offsetY);
tileTitle = “[” + x + “,” + y + “]” + a + “_” + b + title;
run(“Duplicate…”, “title=” + tileTitle);
makeRectangle(offsetX, offsetY, tileWidth, tileHeight);
run(“Crop”);
rename(tileTitle);
i++;
}
}
selectImage(id);
}
}
close();
list = getList(“image.titles”);
print(“Image windows (not sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
Array.sort(list);
if (list.length==0)
print(“No image windows are open”);
else {
print(“Image windows (sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
}
imag1 = list[0];
imag2 = list[1];
print(“first 2”);
print (imag1);
print (imag2);
run(“Concatenate…”, " title=[Concatenated Stack] image1=[[0,0]1_1MEG122820.lif - Series016-TESTFILE.tif] image2=[[0,0]1_1MEG122820.lif - Series016-TESTFILE.tif] image3=[-- None --]");
list = getList(“image.titles”);
print(“Image windows (not sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
Array.sort(list);
print(“Image windows (sorted):”);
for (i=0; i<list.length; i++) {
print(list[i]);
}
- Upload an original image file here directly or share via a link to a file-sharing site (such as Dropbox) – (make sure however that you are allowed to share the image data publicly under the conditions of this forum).
- Share a minimal working example of your macro code.
Background
- What is the image about? Provide some background and/or a description of the image. Try to avoid field-specific “jargon”.
Analysis goals
- What information are you interested in getting from this image?
Challenges
- What stops you from proceeding?
- What have you tried already?
- Have you found any related forum topics? If so, cross-link them.
- What software packages and/or plugins have you tried?