Language problem newbie

imagej
macro

#1

Apologies in advance. I am just using image j to convert the files from my scope. The following is my code. I am running into trouble with the bio-imports call. The error window states 'expected ‘)’ in line 31". I will annotate the line below but the error window goes on to indicate that the line in which the error is found is indeed the run(bio imports…). Can anyone help?

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

processFolder(input);

// 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]);
	}
}

function processFile(input, output, file) {

	for (i = 0; i < list.length; i++) {

**error line->**	run("Bio-Formats Windowless Importer", "open=[input + file]", "autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");
		//run("Bio-Formats", "open = file", "autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");
		//name = getTitle();
		
**line 31->**		/*num = getNChannels();
		if(num == 1) channel = red;
		else if(num == 2 ) channel = green;
		else if(num == 3) channel = blue;
		else channel = alpha;
		*/
		run("Split Channels", file);
		
		/*for(i = 1; i<=num; i++)
		{
			temp = getChannel(i);
			selectWindow(temp);	
			path = output + name + channel;
			saveAs("Processed Tiff", output + '\' + channel + '\' + name);		}
	}
	*/
}

#2

I think it may have something to do with this part of the code. I am not sure how to set the code file name pattern within the framework of the run(bioformats importer) function


#3

Good day,

please check the code line before the line indicated by the error message.

Regards

Herbie


#4

@sonderyugen

You are right!! You are having an issue because you need to call the variables input and file and concatenate them within the String within that run() call. So something like…

run("Bio-Formats Windowless Importer", "open=[" + input + "/" + file +"] autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");

Give it a try and see if that helps… you see the difference - yes?

eta


#5

Yes indeed. I had attempted some variations of this kind of approach. This seems to have solved it. Thank you!.


#6

sorry I’m still getting this same missing ‘)’ later in this file it adds up even less now because I don’t have any guesses… any assistance?


#7

@sonderyugen

Sorry… but can you re-post the code you are running AS IS without any extra comments, etc.?

I’m not sure of some of the functions you are calling… for example, I am not familiar with getNChannels(); … why not use getDimensions(width, height, channels, slices, frames)?? Be sure you are using the appropriate macro functions by using the Built-In Macro Functions list.

Unless I’m missing something… that you are writing your own functions?

eta


#8

Is “list” known to your function “processFile”?

Not sure what you are doing

Herbie


#9

I am just riffing off the template setup honestly. It is a little bit of a mess I apologize. I am pretty much only familiar with C so I am enlightened only so far as what I have and what I have done has worked. I think I can see how this image j java stuff works but I still don’t get it it would seem…

I see the potential problem there with list as you mention herbie.

Regarding those channels functions they are from separate set which I suspected wasn’t configured in my rig just yet or something. I am open to other considerations particularly those built in. I will investigate.


#10

Just check out these helpful links for Scripting in ImageJ/Fiji:

eta


Selecting the same areas of slightly altered images
#11

Yea I’ve definitely looked around the internet


#12

I am just branching out of C lately so its weird. In a sense I would prefer to write my own functions… I am working it out hopefully thanks yall


#13

You can write your own functions in ImageJ scripting… also, you don’t have to use the ImageJ1 Macro language if you don’t want to… there are a lot of languages to choose from for scripting in ImageJ/Fiji.


#14

It seemed like the easiest method to properly utilize the image j functions. Either way it is a new language as I only know c unfortunately. It makes enough sense I think but I keep getting this missing ‘(’ at every turn and I don’t get the reason why I guess…

here is my code presently…

#@ File (label = "Input directory", style = "directory") input
#@ File (label = "Output directory", style = "directory") output
#@ String (label = "File suffix", value = ".tif") suffix

processFolder(input);


function processFolder(input) {

	setBatchMode(true);
	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]);
	}
}

function processFile(input, output, file) {

	open(input + '\' + file);
	len = getDimensions(slices);
	close();
		
	for (i = 0; i < len; i++) {

		run("Bio-Formats Windowless Importer", "open=[" + input + '\' + file"]", "autoscale color_mode=Default view=Hyperstack stack_order=XYCZT");

		
		name = getTitle();
		num = getDimensions(channels);
		if(num == 1) channel = red;
		else if(num == 2 ) channel = green;
		else if(num == 3) channel = blue;
		else channel = alpha;
		
		run("Split Channels", input + file);
		
		for(i = 1; i<=num; i++)
		{
			temp = get(i);
			selectWindow(temp);	
			path = output + name + channel;
			save(output + '\' + channel + '\' + name + '.tif');		
		}
	}
	
}

#15

sorry - but can you also attach a sample image that we can run using your code… this way we can try to reproduce your error.

eta


#16

What is “len”?

Did you check that it gives you the number of slices?
Try: nSlices;

Puzzled

Herbie


#17

Truthfully I am not even attempting to open any images. I am in the macro builder only so far.


#18

It won’t let me upload the file I am converting because it is not an accepted format


#19

I try nSlices but still I get missing ‘)’


#20

"open=[" + input + '\' + file"]"

Shouldn’t it read:

"open=[" + input + "\" + file + "]"

Herbie