Including folder name in image naming by a macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Including folder name in image naming by a macro

otills
Hi, is there a way when running a macro which is running on images in subfolders to use the folder name in the naming of the images produced by the macro?

Also, I've succesfully got a macro to run on my PC, but when I try to move it across to a Mac it doesn't work. I think the problem might be the file extension, how should a Mac file extension be written and how do you find it e.g. the C:\\ part of the extension?

Many thanks,

Oli Tills
[hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Including folder name in image naming by a macro

John Oreopoulos
Oliver, have you tried the "getFileList" macro function?

http://rsbweb.nih.gov/ij/developer/macro/functions.html#getFileList

Maybe this will help.

John Oreopoulos, BSc,
PhD Candidate
University of Toronto
Institute For Biomaterials and Biomedical Engineering
Centre For Studies in Molecular Imaging


On 16-Feb-10, at 2:54 PM, Oliver Tills wrote:

> Hi, is there a way when running a macro which is running on images  
> in subfolders to use the folder name in the naming of the images  
> produced by the macro?
>
> Also, I've succesfully got a macro to run on my PC, but when I try  
> to move it across to a Mac it doesn't work. I think the problem  
> might be the file extension, how should a Mac file extension be  
> written and how do you find it e.g. the C:\\ part of the extension?
>
> Many thanks,
>
> Oli Tills
> [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Including folder name in image naming by a macro

BenTupper
Hi,

On Feb 16, 2010, at 3:08 PM, John Oreopoulos wrote:

> Oliver, have you tried the "getFileList" macro function?
>
> http://rsbweb.nih.gov/ij/developer/macro/functions.html#getFileList
>

You might also want to look at the many "File.xyz" functions - in  
particular the File.getName and File.getParent functions.  You can see  
them all here...

http://rsbweb.nih.gov/ij/developer/macro/functions.html#F

//this takes the name of the file (including path info) and creates a  
new file name using the directory name
dir = File.getParent(file);
dirName = File.getName(dir);
newFile = dir + File.separator + dirName + ".tif";

Ben


> Maybe this will help.
>
> John Oreopoulos, BSc,
> PhD Candidate
> University of Toronto
> Institute For Biomaterials and Biomedical Engineering
> Centre For Studies in Molecular Imaging
>
>
> On 16-Feb-10, at 2:54 PM, Oliver Tills wrote:
>
>> Hi, is there a way when running a macro which is running on images  
>> in subfolders to use the folder name in the naming of the images  
>> produced by the macro?
>>
>> Also, I've succesfully got a macro to run on my PC, but when I try  
>> to move it across to a Mac it doesn't work. I think the problem  
>> might be the file extension, how should a Mac file extension be  
>> written and how do you find it e.g. the C:\\ part of the extension?
>>
>> Many thanks,
>>
>> Oli Tills
>> [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Including folder name in image naming by a macro

otills
Hi,

Thankyou Ben and John for your advice. I think I should be able to use these functions to achieve what I want, however I've had no luck incorporating them into my macro.

It is designed to open an image stack, identify two regions of interest which are then duplicated from the stack and saved as separate stacks. I'm going to be doing this for a large number of files so, although I've managed to label the slices with their number I'd like the date taken to be included on this label too. Can you suggest how I might incorporate this into the macro below?

run("Image Sequence...", "open=[C:\\Documents and Settings\\otills\\My Documents\\Allied Camera Trial\\421 Test 1 well\\421_Test100000.BMP] number=50 starting=1 increment=1 scale=100 file=[] or=[] sort");
makeRectangle(752, 694, 326, 296);
run("Duplicate...", "title=[421 Test 1 well-1] duplicate range=1-50");
run("Label...", "starting=0 interval=1 x=5 y=20 font=30 text=C");
run("Image Sequence... ", "format=TIFF name=170210 start=0 digits=4 save=[C:\\Documents and Settings\\otills\\My Documents\\Allied Camera Trial\\New Folder\\1702100000.tif] save=[C:\\Documents and Settings\\otills\\My Documents\\Allied Camera Trial\\New Folder\\1702100000.tif]");
selectWindow("421 Test 1 well-1");
close();
selectWindow("421 Test 1 well");
makeRectangle(752, 694, 326, 296);
run("Duplicate...", "title=[421 Test 1 well-1] duplicate range=1-50");
run("Label...", "starting=0 interval=1 x=5 y=20 font=30 text=A");
run("Image Sequence... ", "format=TIFF name=170210 start=0 digits=4 save=[C:\\Documents and Settings\\otills\\My Documents\\Allied Camera Trial\\New Folder1\\1702100000.tif] save=[C:\\Documents and Settings\\otills\\My Documents\\Allied Camera Trial\\New Folder1\\1702100000.tif]");
selectWindow("421 Test 1 well-1");
close();
selectWindow("421 Test 1 well");
close();

Also, how can I modify this macro to run on images in all subfolders?

Many thanks,

Oli Tills
[hidden email]