Saving Log Data Macro Not working

imagej

#1

I have an Image that I would like to gather data from. The macro I am using is below

run("Analyze Line Graph");
Plot.getValues(x, y);
  for (i=0; i<300; i++) 
    	 print(x[i], y[i]); 
selectWindow("Log");
path = getDirectory("home")+"profile.txt"
saveAs("Text", path); 

For some reason it does not want to save the x and y values that are shown in the Log window, but instead converts the TIF image into text.

When i click to test the macro, I can save the Log window and it saves exactly what I want. However when I put it into batch and process macro for 50 images, it doesnt save the log window but converts the tiff image into text and saves that. Can someone help me figure out why the macro isnt doing that

Thanks


#2

@gpopovic

I think if you change the selectWindow("Log"); call to getInfo("log"); that should do it??

Just test it and see… (I found that function here: Built-In Macro Functions list)

eta :slight_smile:


#3

Still getting the same thing as before, didnt work sadly :frowning:


#4

@gpopovic

Can you post an image - as well as your entire macro code? That way we can try to replicate/fix your issue…

eta


#5

Here is the tif file im using : https://ufile.io/sz9sm
Here is the txt file i get from the macro: https://ufile.io/8bqzk

Here is a screenshot of the whole macro

Thanks a ton for looking so far into this :slight_smile:


#6

ok @gpopovic

Did you look at the instructions here on Analyze Line Graph in the ImageJ User Guide?

Try running the following IJ1 macro script in the Script Editor:

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

/*
 * Macro template to process multiple images in a folder
 */

// See also Process_Folder.py for a version of this code
// in the Python scripting language.

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 + list[i]))
			processFolder("" + input + list[i]);
		if(endsWith(list[i], suffix))
			processFile(input, output, list[i]);
	}
}

function processFile(input, output, file) {
	setBatchMode(true); // keeps windows from all opening...
	run("Bio-Formats", "open=[" + input + "/" + file +"] autoscale color_mode=Default rois_import=[ROI manager] view=Hyperstack stack_order=XYCZT");
	setAutoThreshold("Default");
	//run("Threshold...");
	run("Create Mask");
	run("Analyze Line Graph");
	Plot.getValues(x,y);
	for (i=0;i<300;i++){
		print(x[i],y[i]);
	}
	getInfo("log");
	save(output + "/" + file +"_profile.txt");
	run("Close");
}

NOTE: YOU NEED TO TEST THIS CODE - SEEING THAT THE OUTPUT IS WHAT YOU WANT

I modified the example script that uses Script Parameters to ask the user for input/output directories… You can find this example script in the Script Editor > Templates > ImageJ 1.x > Examples > Process Folder (IJ1 Macro). Might be a better option than using Batch Process.

eta :slight_smile:


Multi-point pixel selections for an entire folder of images
Batch picture subtraction
#7

when you ran the script, it ran without problems? i seem to be getting errors


#8

Good day,

you write:

When i click to test the macro, I can save the Log window and it saves exactly what I want.

I’ve no success when running your macro code with the provided image.
(loop index out of range)

Regards

Herbie


#9
run("Analyze Line Graph");
Plot.getValues(x, y);
  for (i=0; i<x.length; i++) 
    	 print(x[i], y[i]); 
selectWindow("Log");
path = getDirectory("home")+"profile.txt"
saveAs("Text", path);

Try this? I just tried the macro again in batch macro and it works for me


#13

it works as stated above, but doesnt give me the correct info. it works as in it runs, but does not output the correct info as i stated in the original post.


#14

You wrote in your original post:

For some reason it does not want to save the x and y values that are shown in the Log […]

Now you write:

[…] does not output the correct info as i stated in the original post.

So what do you expect as the correct info?
I get:

106.3515 80.6585

That are the values from the log-window.

Clueless

Herbie


#15

I get those same values, however I am not able to get the macro to save the values from the log window into a text or csv file, instead it seems to save the text from the TIF image, i.e. its just rows and columns of 255 over and over again, not what I see in the log window. Im clueless as well since my log window shows the correct info i want, but i can’t seem to get it to save whats in the log window for the life of me


#16

As I’ve written, the values in the file are those of the log-window.

That said, the macro pasted in a new macro text window and run from there works for me.

I don’t understand what’s wrong with my flagged posts.

Great forum

Herbie


#17

Hmm, I have no idea then why it doesnt seem to be working for me :frowning: Have you had to change any settings of image j?


#18

Hi @gpopovic,

Perhaps a silly question, but did you check your home directory for the profile values?

When I run your batch macro on your image (using the Process > Batch > Macro command exactly as you did) I get the following:

  1. In my home directory, the profile values saved as profile.txt:
106.3515 80.6585
  1. In the Output directory, as specified at the top of the batch macro window, the text image that you described (mostly 255’s).

It is a quirk of the Batch Macro window that it always produces an output image even if you do not actually want it to.
Edited with new info from the ImageJ manual: Output images are not saved if you leave the Output directory box blank.
If you specify an Output directory but don’t modify the image in the macro, a copy of each input image will be saved there in the format you selected. You selected Text Image so that’s why you got the output you described.

In this case, the profile.txt file is the only desired output, so you can simply discard the files automatically created in the Output directory.

Hope this helps.


#19

I judge this analysis being right to the point!

(Of course, in my test I was only looking at the indicated home-directory.)

Herbie


#20

Now, my previous question, which is flagged for whatever reasons, concerned the correct result in the text file:

106.3515 80.6585

Therefore I ask again:

Is the result what you are expecting?

(I refer to the image provided by you earlier.)

regards

Herbie


#21

@Herbie, are you referring to the fact that the result has only 1 data point, but @gpopovic might want the coordinates of the points along the curve?

Attaching a PNG version of the image here for clarity:

I get a long list of points if I insert the thresholding steps that @etarena included in the suggestion above:

// paste this into the batch macro window
setAutoThreshold("Default");
run("Create Mask");
run("Analyze Line Graph");
Plot.getValues(x, y);
for (i=0; i<x.length; i++) 
    	 print(x[i], y[i]); 
selectWindow("Log");
path = getDirectory("home")+"profile.txt"
saveAs("Text", path);

Note – I did not yet check to see if the values are correct, that is, if they actually represent the values on the curve, and include all the values on the curve.

Another potential issue, @gpopovic, is that the Log window will accumulate all the values from all your images. Is that what you want, or would you prefer a separate file for each?


#22

Good day Theresa,

well something along these lines,

are you referring to the fact that the result has only 1 data point, but @gpopovic might want the coordinates of the points along the curve?

yes, but I think this is/was evident and must be judged by the original poster. If he is happy with two values (that must have been present from the beginning on the log-window), then I see no reason to continue asking/helping.

Regards

Herbie


#23

I’m hoping not to make this thread too “meta,” but I think it’s helpful when more experienced people in the field point out questions that should be asked, so that the OP ends up with a robust solution and not just the absence of error messages.