Is there a way to "Stack Combine" 3 stacks side by side.
Image>Stacks>Tools>Combine
Supports the combination of 2 stacks, side by side. The two ways around this:
Combine the first 2 then combine the combined image to the third stack
Create a macro that does the above
run("Combine...", "stack1=STAC1_NAME stack2=STACK2_NAME");
run("Combine...", "stack1=[Combined Stacks] stack2=STACK3_NAME");
Is there another way to do this, since, for example combining 20 stacks side-by-side.
Code Snippet added/
//Specify Folders here//
output = "PATH";
combined = "PATH";
original= "PATH";
//Batch Mode for ImageJ
setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++) {
combine(original, output, combined, list[i]);
}
setBatchMode(false);
function combine(original, output, combined, filename) {
//Open Outline & Overlay for Combine Stack//
name_outline = filename + "_outline.png";
name_overlay = filename + "_overlay.png";
name_ellipse = filename + "_ellipse.png";
name_original = replace(filename, "_watershed.tif", ".tif");
open(original + name_original);
run("RGB Color");
open(output + name_overlay);
run("RGB Color");
open(output + name_outline);
run("RGB Color");
open(output + name_ellipse);
run("RGB Color");
run("Combine...", "stack1=filename stack2=name_overlay");
rename("combinedstack01");
run("Combine...", "stack1=name_outline stack2=name_ellipse");
rename("combinedstack02");
run("Combine...", "stack1=combinedstack01 stack2=combinedstack02");
saveAs("PNG", combined + filename + "_comb.png");
run("Close All");
}
According to the documentation, no:
http://imagej.net/Stack_Manipulation
http://imagej.net/Stack-slice_Manipulations
However you can easily batch process a whole stack folder with the combine method, see:
http://imagej.net/Batch_Processing
Here an example macro
E.g.(adjust the paths! - stacks are named for this script 'stack1', 'stack2',....):
input = "C:\\Users\\test\\Pictures\\combine";
open("C:\\Users\\test\\Pictures\\combine\\stack1.tif");
rename("combinedStack");
list = getFileList(input);
for (i = 1; i < list.length; i++){
open(list[i]);
title=getTitle();
run("Combine...", "stack1="+title+" stack2=combinedStack");
rename("combinedStack");
}
Related
I have tried using/altering other forum's answers and can't seem to get the code right. I am wanting to repeat entire lines 'x' number of times (x being in column U). This will be a document that I use over and over again with changing data in the lines, and just need a macro to dictate how many times the line repeats. I am a total coding novice-- any advise helps!
Use the following code that shall copy range from A:U and copy is below:
function repeatrow() {
var ss = SpreadsheetApp.getActive();
var repeattime = ss.getRange('U3').getValue();
ss.getRange('A4:U').clearContent();
var value = ss.getRange('A3:U3').getValues();
for (i = 0; i <= repeattime - 1; i++) {
ss.getRange("A" + (i + 4) + ":U" + (i + 4)).setValues(value);
};
};
after hours of trying and searching related topics, I don't get further. I am trying to create a small ImageJ script that splits channels of a picture, saves on .tif version with enhanced contrast (this part works) AND creates a histogram and saves it values as .csv (this part does not work, it doesn't save anything).
I have no idea why it doesn't work so here is my whole code.
input = getDirectory("Input directory");
output = getDirectory("Output directory");
Dialog.create("File type");
Dialog.addString("File suffix: ", ".tif", 5);
Dialog.show();
suffix = Dialog.getString();
processFolder(input);
function processFolder(input) {
list = getFileList(input);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(list[i]))
processFolder("" + input + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
}
}
function processFile(input, output, filename) {
print("Processing: " + input + filename);
open(input + filename);
run("Split Channels");
selectWindow(filename+" (blue)");
close();
selectWindow(filename+" (green)");
close();
selectWindow(filename+" (red)");
run("Histogram");
getHistogram(values, counts, 256);
saveAs("Results", output + "Histogram of " + filename + ".csv");
close();
saveAs("TIFF", output+ "processed_" + filename);
selectWindow("processed_" + filename);
close();
}
I appreciate every input. Cheers!
not sure you can save it as a csv file using the IJ macro language. However here is some code to do the same thing but save it as a txt file (this example only takes the value from 255)
getStatistics(mean, min, max, std, histogram);
white=histogram[255];
// list2 is the list of images in a for loop - adds image name to results
print(white,",", list2[j]+" smi31");
selectWindow("Log");
saveAs("txt", file1+"Result");
Hope this is helpful :-)
I have created a macro that generates results both in the log and results pages. I need a macro that saves both the results and log files into one big excel file and is organized by image name.
input=getDirectory("Choose Source Directory ");
list = getFileList(input);
for (i = 0; i < list.length; i++)
rootangle(input, list[i]);
function angle (input,filename){
open (input + filename);
setTool("angle");
for (i = 0; i < 5; i++){
waitForUser("Select Angle Points");
run("Set Measurements...", " display redirect=None decimal=3");
//run("Measure");
}
setTool("multipoint");
waitForUser("Count");
run("Set Measurements...", " display redirect=None decimal=3");
run("Measure");
}
setTool("line");
waitForUser("Measure");
run("Set Measurements...", " display redirect=None decimal=3");
run("Measure");
}
setTool("freehand");
waitForUser("Distance");
run("Set Measurements...", " display redirect=None decimal=3");
run("Measure");
}
setTool("polyline");
waitForUser("Draw");
run("Fit Spline", "straighten");
getSelectionCoordinates(x, y);
for (i=0; i<x.length; i++)
print(i+" "+x[i]+" "+y[i]);
}
dir=getDirectory("image");
name = "Results";
index = lastIndexOf(name, "\\");
if (index!=-1) name = substring(name, 0, index);
name = name + ".xls"; ///can change xls to csv, txt, etc.
saveAs("Measurements", dir+name);
close();
}
run("Clear Results");
In this macro the polyline generates many many x,y coordinates for each image that may be bulky for the excel file. These coordinates can be listed on one line in the results excel file.
Is there a way you can add manual annotation to the label in the results page?
Also, is there a way you can add pose measurement functions? Like divide the numbers by 2, etc before creating the excel file?
I wrote a macro which saves results of ROI multimeasures to the log window. Since I only wanted specific results (the highest three Raw Integrated Densities), I had my code use getResult("Column Label", row) to get the results out, manipulate them, and then print to the log using print("stuff to print"). At the end, I saved the log as a csv, which one can open in excel. Just use commas to separate
I have the following code, where I read images from directory and use ImageJ Auto Threshold plugin to segment my images.
dir = getDirectory("path");
list = getFileList(dir);
for (i=0; i<list.length; i++)
{
if (endsWith(list[i], ".tif"))
{
open(dir + list[i]);
run("8-bit");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Otsu dark");
run("Convert to Mask");
saveAs("TIFF", dir+list[i]);
close();
}
}
I would like to get the threshold value using "Otsu dark" method, and modify that value (e.g. scale it by a factor) and apply it to my images for segmentation.
In an ImageJ macro, use the getThreshold(lower,upper) and setThreshold(lower,upper) methods (here's the documentation).
Your code would look like this then:
dir = getDirectory("path");
list = getFileList(dir);
factor = 1.5;
for (i=0; i<list.length; i++)
{
if (endsWith(list[i], ".tif"))
{
open(dir + list[i]);
run("8-bit");
run("Gaussian Blur...", "sigma=2");
setAutoThreshold("Otsu dark");
getThreshold(lower,upper);
setThreshold(lower,upper*factor);
run("Convert to Mask");
saveAs("TIFF", dir+list[i]);
close();
}
}
If you plan to do more complicated things, consider using another scripting language like the ones provided by Fiji.
There are a number of questions about how to parse a URL in Python, this question is about the best or most Pythonic way to do it.
In my parsing I need 4 parts: the network location, the first part of the URL, the path and the filename and querystring parts.
http://www.somesite.com/base/first/second/third/fourth/foo.html?abc=123
should parse into:
netloc = 'www.somesite.com'
baseURL = 'base'
path = '/first/second/third/fourth/'
file = 'foo.html?abc=123'
The code below produces the correct result, but is there are better way to do this in Python?
url = "http://www.somesite.com/base/first/second/third/fourth/foo.html?abc=123"
file= url.rpartition('/')[2]
netloc = urlparse(url)[1]
pathParts = path.split('/')
baseURL = pathParts[1]
partCount = len(pathParts) - 1
path = "/"
for i in range(2, partCount):
path += pathParts[i] + "/"
print 'baseURL= ' + baseURL
print 'path= ' + path
print 'file= ' + file
print 'netloc= ' + netloc
Since your requirements on what parts you want are different from what urlparse gives you, that's as good as it's going to get. You could, however, replace this:
partCount = len(pathParts) - 1
path = "/"
for i in range(2, partCount):
path += pathParts[i] + "/"
With this:
path = '/'.join(pathParts[2:-1])
I'd be inclined to start out with urlparse. Also, you can use rsplit, and the maxsplit parameter of split and rsplit to simplify things a bit:
_, netloc, path, _, q, _ = urlparse(url)
_, base, path = path.split('/', 2) # 1st component will always be empty
path, file = path.rsplit('/', 1)
if q: file += '?' + q