I am trying to batch convert 200+ raw .img files using a batch script in ImageJ. My script:
//-----------Code starts here---------------------
dir1 = getDirectory("path/source");
dir2 = getDirectory("path/target");
list = getFileList(dir1);
setBatchMode(true);
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
if(endsWith(list[i],".IMG"))
run("Raw...", open=["+dir1+list[i]+"] image=[16-bit Unsigned] width=2048 height=2048 offset=359 number=1 gap=0");
else
open(dir1+list[i]);
saveAs(format, dir2+list[i]);
close();
}
However, when I try running it I get the following error:
I am not sure why however, as I do have a ; closing the line...
The error message is misleading, because you're missing a quotation mark (") at the beginning of your second parameter to run():
run("Raw...", "open=["+dir1+list[i]+"] image=[16-bit Unsigned] width=2048 height=2048 offset=359 number=1 gap=0");
The < and > characters in the error message are indicating the position where the parser finds something unexpected.
I edited your original code to include syntax highlighting, which facilitates finding this kind of errors. Fiji's script editor includes syntax highlighting and is recommended when working with ImageJ macros.
In general, ImageJ-specific questions are more likely to be answered in time when posted on the dedicated forum: http://forum.imagej.net/
Related
I am trying to write a code in macro language of ImageJ in order to automate manuel image analysis work. I have found another website to hande with this problem. Then, I have recently downloaded IMAGEJ v1.52q which is the latest version. Next, I pasted the code into the recorder of Marcos and I run the code. The execution caused 'Unrecognized Command':LoG 3D Error. I looked at plugin of LoG filters and I only found the one that is released in 2000. I uploaded this one into plugins part of the ImageJ, but I have got the same error. Please let me know if you have any solutions for this problem.
Thank you in advance.
The code I wrote is taken from the website: https://forum.image.sc/t/manual-image-analysis-works-but-not-the-macro-batch/134/15
and it is:
macro "Focal adhesion analysis" {
dir = getDirectory("Choose a Directory ");
list = getFileList(dir);
setBatchMode(true);
for (i=0; i<list.length; i++) {
path = dir+list[i];
open(path);
run("16-bit");
run("Subtract Background...", "rolling=50 sliding");
run("CLAHE ", "blocksize=15 histogram=256 maximum=6");
title = getTitle;
run("LoG 3D", "sigmax=4 sigmay=4");
selectWindow("LoG of "+title);
setAutoThreshold("Otsu");
run("Analyze Particles...", "size=1-Infinity circularity=0.05-1.00 clear add");
path2 = dir+File.nameWithoutExtension;
saveAs("JPEG", path2+"-bin.jpeg");
selectWindow(title);
run("Revert");
roiManager("Measure");
close();
saveAs("results", path2+"-results.tsv");
roiManager("reset");
}
}
Do you have the CLAHE and LoG 3D plugins installed? ImageJ does not come bundled with them.
I am scripting with DM and would like to read hdf5 file format.
I borrowed Tore Niermann's gms_HDF5_Plug-In (hdf5_GMS2X_amd64.dll) and his CMD_import_hdf5.s script. It use h5_read_dataset(filename, datapath) to read a image dataset.
I am trying to figure out the way to read a string info stored in the same file. I am particular interested to read the angle stored in string as shown in this figure.Demonstrated string to read. The h5_read_dataset(filename, datapath) function doesn't work for reading string.
There is a help file (hdf5_plugin.chm) with a list of functions but unfortunately I can't open them to see more info.
hdf5_plugin.chm showing the function list.
I suppose the right function to read strings should be something like h5_read_attr() or h5_info() but I didn't test them out. DM always says the two functions doesn't exist.
After reading out the angle by string, I will also need a bit help to convert the string to a double datatype.
Thank you.
Converting String to Number is done with the Val() command.
There is no integer/double/float concept for variables in DM-script, all are just number. ( This is different for images, where you can define the numeric type. Also: For file-inport/export a type differntiation can be made using the taggroup streaming commands in the other answer. )
Example script:
string numStr = "1.234e-2"
number num = val( numStr )
ClearResults()
Result( "\n As string:" + numStr )
Result( "\n As value:" + num )
Result( "\n As value, formatted:" + Format(num,"%3.2f") )
Potential answer regarding the .chm files: When you download (or email) .chm files in Windows, the OS classifies them as "potentially dagerouse" (because it could contain executable HTML code, I think). As a result, these files can not be shown by default. However, you can right-click these files and "unblock" them in the file properties.
Example:
I think this will be most likely a question specific to that plugin and not general DM scripting. So it might be better to contact the plugin-author directly.
The alternative (not good) solution would be to "rewrite" your own HDF5 file-reader, if you know the file-format. For this you would need the "Streaming" commands of the DM script language and browse through the (binary?) source file to the apropriate file location. The starting point for reading on this in the F1 help documentation would be here:
I'm thinking about building a tool to help me visualise the generated LLVM-IR code for each instruction/function on my original source file.
Something like this but for LLVM-IR.
The steps to build such tool so far seem to be:
Start by with LLVM-IR AST builder.
Parse generated IR code.
On caret position get AST element.
Read the element scope, line, column and
file and signal it on the original source file.
Is this the correct way to approach it? Am I trivialising it too much?
I think your approach is quite correct. The UI part will probably be quite long to implement so I'll focus on the llvm part.
Let's say you start from a input file containing your LLVM-IR.
Step 1 process module:
Read file content to a string. Then Build a module from it, and process it to get the debug info:
llvm::MemoryBuffer* buf = llvm::MemoryBuffer::getMemBuffer(llvm::StringRef(fileContent)).release();
llvm::SMDiagnostic diag;
llvm::Module* module = llvm::parseIR(buf->getMemBufferRef(), diag, *context).release();
llvm::DebugInfoFinder* dif = new llvm::DebugInfoFinder();
dif->processModule(*module);
Step 2 iterate on instructions:
Once done with that, you can simply iterate on function and blocks and instructions:
// pseudo code for loops (real code is a bit long)
foreach(llvm::Function f in module.functions)
{
foreach(llvm::BasicBlock b in f.BasicBlockList)
{
foreach(llvm::Instruction inst in b.InstList)
{
llvm::DebugLoc dl = inst.getDebugLoc();
unsigned line = dl->getLine();
// accordingly populate some dictionary between your instructions and source code
}
}
}
Step 3 update your UI
This is another story...
In R there is the source function where you can source an R script from another R script.
I want to be able to do the same in SPSS.
How can I source an SPSS syntax file from another SPSS syntax file?
Updated Following #AndyW's comments.
There is the INSERT and INCLUDE commands. INSERT is newer and more versatile than INCLUDE.
See documentation on INSERT here.
The following is the basic syntax template:
INSERT FILE='file specification'
[SYNTAX = {INTERACTIVE*}]
{BATCH }
[ERROR = {CONTINUE*}]
{STOP }
[CD = {NO*}]
{YES}
[ENCODING = 'encoding specification']
Thus, the following command can be placed in an SPSS syntax file
INSERT FILE='foo.sps'.
and it would import foo.sps syntax file.
By default, syntax must follow the rules of interactive mode, and the code wont stop on an error.
To avoid having to specify the full path to the file, the working directory can be specified as an argument in the INSERT statement or with a separate CD command.
E.g.,
CD '/user/jimbo/long/path/to/project'
Another option is to use FILE HANDLE.
For more information see the SPSS Syntax Reference (available here as a large PDF file).
I have a relatively complicated suite of OMake files designed for cross-compiling on a specific platform. My source is in C++.
I'm building from Windows and I need to pass to the compiler include directories which have spaces in their names. The way that the includes string which is inserted in the command line to compile files is created is by the line:
public.PREFIXED_INCLUDES = $`(addprefix $(INCLUDES_OPT), $(set $(absname $(INCLUDES))))
At some other point in the OMake files I have a line like:
INCLUDES += $(dir "$(LIBRARY_LOCATION)/Path with spaces/include")
In the middle of the command line this expands to:
-IC:\Library location with spaces\Path with spaces\include
I want it to expand to:
-I"C:\Library location with spaces\Path with spaces\include"
I don't want to change anything but the "INCLUDES += ..." line if possible, although modifying something else in that file is also fine. I don't want to have to do something like change the definition of PREFIXED_INCLUDES, as that's in a suite of OMake files which are part of an SDK which may change beneath me. Is this possible? If so, how can I do it? If not, in what ways can I make sure that includes with spaces in them are quoted by modifying little makefile code (hopefully one line)?
The standard library function quote adds escaped quotes around its argument, so it should do the job:
INCLUDES += $(quote $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))
If needed, see quote in Omake manual.
In case someone else is having the same problem, I thought I'd share the solution I eventually went with, having never figured out how to surround with quotes. Instead of putting quotes around a name with spaces in it I ended up converting the path to the short (8.3) version. I did this via a a simple JScript file called shorten.js and a one line OMake function.
The script:
// Get Access to the file system.
var FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");
// Get the short path.
var shortPath = FileSystemObject.GetFolder(WScript.Arguments(0)).ShortPath;
// Output short path.
WScript.StdOut.Write(shortPath);
The function:
ShortDirectoryPath(longPath) =
return $(dir $(shell cscript /Nologo $(dir ./tools/shorten.js) "$(absname $(longPath))"))
So now I just use a line like the following for includes:
INCLUDES += $(ShortDirectoryPath $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))