The file is not open in imagej - imagej

I wrote the code as follows in ImageJ.
But the image window is not created in open.
I want to load all the tif files into the folder and see them.

The problem is the line setBatchMode(true);
If you delete that line, or set it to false, your script will open all the files in the folder in a way that you can see them. BatchMode allows a script to run without drawing the window and is intended for use in an automated script.
dir1 = getDirectory("Choose Source Directory");
list = getFileList(dir1);
for (i = 0; i < list.length; i++) {
showProgress(i+1,list.length);
filename = dir1 + list[i];
if(endsWith(filename, "tif"));
{
open(filename);
}
}

Related

How do I make Jenkins fileCopyOperation copy all files including those starting with a dot

I have a Jenkins pipeline that copy all my source files unfortunately it skip one file named ".DS_store" I have be unable to locate sufficient detailed documentation to figure how to include hidden files control details on what files to include. The best I could find is: https://jenkins.io/doc/pipeline/steps/file-operations/
def CopyJobs = [:]
def include = Include(Target)
// copy all folders to c:\svn\vs\... for building there
for(int i = 0; i< include.size(); i++){
def index = i
CopyJobs["CopyJob${i}"] = {
Run.dir("D:\\Svn\\vs\\")
{
def includeItem = "${include[index]}\\**"
Run.echo "CopyJobs ${index} ${includeItem}"
Run.fileOperations([
Run.fileCopyOperation(excludes: '', flattenFiles: false, includes: "${includeItem}", targetLocation: "C:\\Svn\\vs\\")
])
}
}
}
Run.parallel CopyJobs
Edit:
The puzzle has increased I assumed that the problem was the starting dot (.) but I have another file starting with dot that gets copied without problems. That is however not binary but other binaries not starting with dot gets copied ok

How to batch process ImageJ macro within a specific folder within multiple directories

I have a nested file structure where a parent folder contains multiple folders of different types of data. I am using an ImageJ macro script to batch process all of the image files within one of those folders. I currently need to process each folder separately, but I would like to batch process over the folders. I have looked up some batch processing of multiple folders, but it appears that the code is processing all folders and files within all of the folders. I only need to process one folder within each directory (all named the same). The images come from the instrument without any metadata, so the files are saved as such to separate the experiments, where all data for the experiment is contained within the parent folder. Also, I have two different scripts that I need to run, one after the other. It would be great if I could merge those, but I am don't know how to do that either.
An example of the structure is:
Experiment1/variable1/processed
Experiment1/variable2/processed
I am currently running my macro on each of the "processed" folders individually. I would like to batch each "processed" folder within each of the "variable" folders.
Any help would be greatly appreciated, I am really new to coding and am just really trying to learn and automate as much as possible.
Thank you!
Did you try the batch processing scripts you came across? Reading the batch processing example which is provided with ImageJ leads me to believe it would work for your example. If you haven't tested it, you should do so (you can put in a command like "print(list[i])" in the place of your actual macro while you test that you've got the file finding section working.
To merge two different scripts, the simplest option would be to make them individual functions. i.e.:
// function to scan folders/subfolders/files to find files with correct suffix
function processFolder(input) {
list = getFileList(input);
list = Array.sort(list);
for (i = 0; i < list.length; i++) {
if(File.isDirectory(input + File.separator + list[i]))
processFolder(input + File.separator + list[i]);
if(endsWith(list[i], suffix))
processFile(input, output, list[i]);
processOtherWay(input, output, list[i]);
}
}
function processFile(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
}
function processOtherWay(input, output, file) {
// Do the processing here by adding your own code.
// Leave the print statements until things work, then remove them.
print("Processing: " + input + File.separator + file);
print("Saving to: " + output);
}
If the goal isn't to run them on the exact same image, then again make them standalone functions, and have the folder sorting section of the script be in two parts, one for function 1, one for function 2.
You can always just take the code you have and nest it in another for loop or two.
numVariables = ;//number of folders of interest
for(i = 1; i <= numVariables; i++) //here i starts at 1 because you indicated that is the first folder of interest, but this could be any number
{
openPath = "Experiment1/variable" + i + "/processed";
files = getFileList(openPath);
for(count = 0; count < files.length; count++) //here count should start at 0 in order to index through the folder properly (otherwise it won't start at the first file in the folder)
{
//all your other code, etc.
}
}
That should just about do it I think.

Batch save all opened files in GIMP .xcf

I have a series of manually edited images and layers in GIMP, each set is in a single tab. All want to save all of them into different .xcf's.
I am aware of some scripts to export them as images (like this one), but I want to save them as .xcf, not export the images. Moreover, I would like to have them in a single folder, so that I can load them all in the future.
Is there any script to do this?
You can save all projects using this code bellow
dirname = “Path of file”
path = “File name”
imgs = gimp.image_list();
num = 0;
for img in imgs:
for layer in img.layers:
fullpath = os.path.join(path, dirname+str(num)+'.xcf');
pdb.gimp_xcf_save(0, img, layer, fullpath, fullpath);
num += 1;
Or, if you can install complete plugin in https://github.com/Tushn/GIMP-Plugins/blob/master/src/saveproject.py
Instructions for install in https://github.com/Tushn/GIMP-Plugins
If you want open all file, so it’s enough that you mark all xcf in directory and enter in GIMP (click right buttom mouse, case your GIMP is not default file).

7zip takes forever to extract

Compressing a set of folders using 7zip, like this:
def list = ["dir1", "dir2", "dir3"]
for (int i = 0; i < list.size(); i++) {
def dir = list.get(i);
bat "7z a %cd%\\artifacts\\${dir}.zip %cd%\\src\\${dir}\\obj\\*"
}
Then copy over the zips to a shared drive and extract them remotely using:
def list_a = ["dir1", "dir2", "dir3"]
for (int i = 0; i < list_a.size(); i++) {
def dir = list_a.get(i);
bat "copy %cd%\\artifacts\\${dir}.zip \\\\shared_drive\"
bat "7z x \\\\shared_drive\\\${dir}.zip -o\\\\shared_drive\\\${dir} -y" //This step with extraction, takes a very long time for folders with a lot of files in it ( as compared using the GUI (right click and extract on the folder)
bat "del /Q \\\\shared_drive\\\${dir}.zip"
}
I am retaining the folder structure while extracting.
Is there a way in which i can fasten the extraction process to the speed that i get while using the graphical interface with the mouse?
I wouldn't expect a difference between CLI and GUI. There's one common pitfall in your setup, though: extracting an archive from network to the same network drive can be very slow.
It will be better to completely avoid the intermediate step of copying the archive to the share. If %cd% is a local drive in your setup, then this will do:
def list_a = ["dir1", "dir2", "dir3"]
for (int i = 0; i < list_a.size(); i++) {
def dir = list_a.get(i);
bat "7z x %cd%\\artifacts\\${dir}.zip -o\\\\shared_drive\\\${dir} -y" //This step with extraction, takes a very long time for folders with a lot of files in it ( as compared using the GUI (right click and extract on the folder)
}
Otherwise, it may be worth copying the archive to a local drive first, and extract it then.

Calculating surface and storing as Excel file

I'm new to imageJ and I am trying to analyze several images:
I have a code that can analyze color threshold for a set of images in a directory and store them separately:
input = "/m_3/ImageJ/test_folder/";
output = "/m_3/ImageJ/finished2/";
function action(input, output, filename) {
open(input + filename);
run("Set Scale...", "distance=872 known=9 pixel=1 unit=cm");
run("Color Threshold...");
// Color Thresholder 1.48v
// Autogenerated macro, single images only!
.
.
.
// Colour Thresholding-------------
saveAs("Jpeg", output + filename);
close();
}
setBatchMode(true);
list = getFileList(input);
for (i = 0; i < list.length; i++)
action(input, output, list[i]);
setBatchMode(false);
Now I want to calculate the area of the newly saved images and this should work with the function measure..
run("Measure");
How can I store the calculations in .xls or .csv -files?
Is it also possible to calculate the area of all the files in one directory and store the results in just one .xls or .csv -file?
Have a look at the explanation how to apply a common operation to a complete directory on the Fiji wiki. You can open each of the newly save images, set a threshold, measure, and close each image as follows:
open("/path/to/your/image.jpg");
setAutoThreshold("Default");
run("Measure");
close();
and paste that code into the Process Folder template (Templates > IJ1 Macro > Process Folder) of the script editor.
The results table can afterwards be saved as an .xls file via File > Save As... or:
saveAs("Results", "/path/to/your/file.xls");

Resources