Fiji error: "No images file selected" when using a macro that calls the plugin 'Average Images' - plugins

I would like to create a macro with Fiji, that then I would run by using matlab.
I would like to average 3 images by using the Plugins>Stacks>Average Images.
I used first Plugins>Macro>Record... to get an idea what to use. Here is the result:
run("Average Images", "add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame0_pvar-8bit_combined.tif add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame1_pvar-8bit_combined.tif add=D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\Measurement._cb_frame2_pvar-8bit_combined.tif");
saveAs("Tiff", "D:\\Corinne\\diabetes_paper_meas\\2013_01_29\\Measurement.007_cb\\test.tif");
However, even when I run this macro I got an error: No images file selected. However, in Fiji you do not need to open any images to run the plugin but you add the files through a window interface...
So of course, since just running the macro is not working I get the same error when I use the following macro:
file = getArgument;
if (file=="") exit ("No argument!");
setBatchMode(true);
file_vasc = file;
file_vasc_frame_0 = file;
file_vasc_frame_1 = replace(file, "\\_frame0_pvar-8bit_combined.tif", "_frame1_pvar-8bit_combined.tif");
file_vasc_frame_2 = replace(file, "\\_frame0_pvar-8bit_combined.tif", "_frame2_pvar-8bit_combined.tif");
run("Average Images", "add=file_vasc_frame_0 add=file_vasc_frame_1 add=file_vasc_frame_2");
file_vasc_out = replace(file, "frame0_pvar-8bit_combined.tif", "_vasc_averaged.tif");
saveAs("Tiff", file_vasc_out);
Somebody has an idea what should I do?
Thanks

The Average Images plugin is using dialogs in a non-standard way and therefore is not scriptable: when running the plugin in Fiji with the macro recorder active (Plugins>Macros>Record... and then Plugins>Stacks>Average Images), you will see Fiji complain as soon as you add a second file to the list:
Duplicate keyword:
Command: "Average images"
Keyword: "add"
Value: /path/to/your/file
Add an underscore to the corresponding label in the dialog to make the first word unique.
This clearly is a bug in the plugin (it makes multiple use of the same OpenDialog thereby recording duplicate keywords in the macro recorder). You can report it via Help>Report a bug, however I fear that this plugin is not actively maintained at the moment.
In any case, there is a simple alternate way to average images in ImageJ without requiring this plugin, using the Image>Stacks>Images to Stack and Image>Stacks>Z Project... commands:
setBatchMode(true);
open("/path/to/first-image.tif");
open("/path/to/second-image.tif");
run("Images to Stack", "name=stack title=[]");
run("Z Project...");
saveAs("Tiff", "/path/to/new-file-name.tif");

Related

Error handling in Sublime Text Plugin API

I'm creating my first sublime plugin to be used internally and was wondering if there's a way to stop the plugin from executing and display an error message on screen like an alert?
I took a look at view#show_popup() but this didn't render for me. Below is how I attempted to show it:
if "WebContent" in subdirectories:
directory = ROOT_DIR + "/WebContent"
elif "Content" in subdirectories:
directory = ROOT_DIR + "/Content"
else:
self.view.show_popup('Directory not found', location=-1)
Working Principle:
The plugin takes some data from one view and then pastes them in another view. The plugin has two TextCommands. One command takes the data from the first view, opens a new view and then executes the 2nd command on the new view. The above snippet is in the 2nd command.
I was unable to find any resources to help with show_popup() or any other error handling.
Does any one have possible ideas?
view.show_popup() is for showing things like hover popups next to the cursor; it's used for things like the built in functionality for going to references/definitions for functions:
While you could in theory use this for error messages, it may not be the sort of user experience that anyone would expect.
Your code above is technically valid, but since the content is expected to be minihtml it may be hard to see because as just a single string all you're going to see is just the text (i.e. you have no font style, padding, etc):
Perhaps more importantly, when location is -1, the popup appears at the point in the buffer closest to the first cursor position, so depending on your circumstance it may be appearing in a place you don't expect, and then vanishing away before you can scroll to see it, etc.
What you want here is sublime.error_message(); given a string, it will display that string in a dialog for the user to interact with, and it also logs the error into the Sublime console as well so that there's an additional trace.

MONAILABEL Slicer plugin | pelvis segmentation in MRI

I want to segment pelvic in MRI from the SMIR dataset using the MONAILABEL plugin. I have read relatively a lot about this plugin. However, I can’t perform the segmentation well enough yet.
These are the steps I take to do so:
connecting the server using the anaconda prompt
enabling the plugin in Slicer and loading one image
labeling the pelvis manually using the paint button in the scribbles part and the updating
click “submit label”
and then repeating the process for some other images while the network is being trained.
After the training process, I actually could not see anything when opening the mask files.
I also encounter these two errors:
" AssertionError: Not a valid Label "
" TypeError: object of type ‘NoneType’ has no len() "
Is it the correct way of using MONAI or am I missing something?
Which aspects should I take into account before starting the process?
I would appreciate your help and suggestions.
Thank you

Writing string to specific dir using chaquopy 4.0.0

I am trying a proof of concept here:
Using Chaquopy 4.0.0 (I use python 2.7.15), I am trying to write a string to file in a specific folder (getFilesDir()) using Python, then reading in via Android.
To check whether the file was written, I am checking for the file's length (see code below).
I am expecting to get any length latger than 0 (to verify that the file indeed has been written to the specific location), but I keep getting 0.
Any help would be greatly appreciated!!
main.py:
import os.path
save_path = "/data/user/0/$packageName/files/"
name_of_file = raw_input("test")
completeName = os.path.join(save_path, name_of_file+".txt")
file1 = open(completeName, "w")
toFile = raw_input("testAsWell")
file1.write(toFile)
file1.close()
OnCreate:
if (! Python.isStarted()) {
Python.start(new AndroidPlatform(this));
File file = new File(getFilesDir(), "test.txt");
Log.e("TEST", String.valueOf(file.length()));
}```
It's not clear whether you've based your app on the console example, so I'll give an answer for both cases.
If you have based your app on the console example, then the code in onCreate will run before the code in main.py, and the file won't exist the first time you start the activity. It should exist the second time: if it still doesn't, try using the Android Studio file explorer to see what's in the files directory.
If you haven't based your app on the console example, then you'll need to execute main.py manually, like this:
Python.getInstance().getModule("main");
Also, without the input UI which the console example provides, you won't be able to read anything from stdin. So you'll need to do one of the following:
Base your app on the console example; or
Replace the raw_input calls with a hard-coded file name and content; or
Create a normal Android UI with a text box or something, and get input from the user that way.

problems with prefs.get and set ImageJ Macro

I'm trying to write a macro to save preferences and read them after closing and reopening ImageJ.
The saving works, but the macro isn't reading the file. Moreover when I try to use one of these two lines an error occurs that the variable "Prefs" is unknown.
int myNumber = Prefs.get("my.persistent.number", 0);
Prefs.savePreferences();
What am I doing wrong? please help me :-)
The ImageJ macro language itself does not support storing custom preferences. (Only the set of built-in options (accessible via Edit > Options in the menu) can be saved, restored and adjusted.) You need to resort to calling the Java class via call("ij.Prefs.get", "my.persistent.number", "0");.
The following ImageJ macro works in an up-to-date Fiji/ImageJ installation:
myNumber = call("ij.Prefs.get", "my.persistent.number", "0");
print(myNumber);
call("ij.Prefs.set", "my.persistent.number", 3);
In the first run, it prints 0; every following run will print 3; after restarting Fiji, it will print 3 again. In case it does not work for you even after updating to the newest version, please report a bug via Help > Report a bug, which will also submit essential information about your installation to the developers to help them fix the issue.
Using one of the many scripting languages however, you can access the ij.Prefs java class directly, as you are trying to do it. Just do not forget to import the class before using it. This is an example Javascript:
importClass(Packages.ij.Prefs);
myNumber = Prefs.get("my.persistent.number", 0);
Prefs.set("my.persistent.number", myNumber);
Hope that helps.

How to combine several PNG images as layers in a single XCF image?

I have several PNG images, which I need to combine as individual layers in a new GIMP XCF image. I need to perform this task many times, so a script based solution would be best.
So far i tried to play around with the batch mode of GIMP, but failed miserably.
Instead of script-fu, which uses Scheme, I'd recommend using the GIMP-Python binding for this, since it is far easier to manipulate files and listings.
If you check filters->Python->Console you will b dropped into an interactive mode - at the bottom of it, there will be a "Browse" button which lets you select any of GIMP's procedures in its API and paste it directly in this console.
There is as an API call to "load a file as a layer" - pdb.gimp_file_load_layer -
this however, brings the image to memory, but do not add it to the image - you have to call
pdb.gimp_image_insert_layer afterwards
You can type this directly in the interactive console, or,check one of my other GIMP-related answers, or some resource on GIMP-Python on the web to convert it to a plug-in, which won't require pasting this code each time you want to perform the task:
def open_images_as_layers(img, image_file_list):
for image_name in image_file_list:
layer = pdb.gimp_file_load_layer(image_name)
pdb.gimp_image_insert_layer(img, layer, None, 0)
img = gimp.image_list()[0]
image_list = "temp1.png temp2.png temp3.png"
open_images_as_layers(img, image_list.split())
The second to last line img = ... picks a needed reference to an open image
in GIMP - you could also create a new image using pdb calls if you'd prefer
(example bellow).
The file list is a hardcoded space separated string in the snippet above,
but you can create the file list in any of the ways allowed by Python.
For example, to get all the ".png" file names in a
c:\Documents and Settings\My user\Pictures folder, you could do:
from glob import glob
image_list = glob("c:/Documents and Settings/My user/Pictures/*png")
To create an image programatically:
img = gimp.Image(1024, 768)
pdb.gimp_display_new(img)