Batch split channels and save

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

Batch split channels and save

Dr D.J. Metcalf
Hi,

I'd be grateful for some help on making my macro capable of batch
processing a folder of images. I'm not sure if it's possible to modify the
one I've written or if another approach is required.

The aim is to open RGB tif files and then save the individual channels but
with the added complication of discarding the blue image and saving the
green and red images. Ideally I'd like to save the green image twice with
different file names (see below).

My starting file names are A_A##f##.tif My result file names are
A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the green
chanel, d1 is the green channel and d2 is the red channel)

Thanks,

Dan


open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");
run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); close();
close(); run("Save",
"save=[V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif]"); close();
open("V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif");
open("V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); run("Merge
Channels...", "red=C3-A_A06f12.tif green=C1-A_A06f12.tif
blue=C1-A_A06f12.tif gray=*None* create"); run("Split Channels");
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d0.tif]"); close();
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d1.tif]"); close();
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d2.tif]"); close();
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

Krs5
Dear Dan,

See if the macro below does what you want. At the moment it saves the results to a new directory called "analysed". If you want to save the result files in the same directory as your original files delete the line "dir2 = ....." and change in the first lane "dir1" into "dir2"


dir1 = getDirectory("Choose Source Directory ");
list = getFileList(dir1);
dir2 = dir1+"analysed"+File.separator;
File.makeDirectory(dir2);
for (i=0; i<list.length; i++)
        {
       
        if (File.isDirectory(dir1+list[i])){}
        else{
               
                path = dir1+list[i];
                if (endsWith(path, ".db")){}
                else{
                       
                        open(path);
                        if (bitDepth!=24){}  
                        else {
                                setBatchMode(true);
                                title = File.nameWithoutExtension ;
                                run("Split Channels");
                                close();
                               
                                saveAs("Tiff", dir2+title+"d0.tif");
                                saveAs("Tiff", dir2+title+"d1.tif");
                                close();
                                saveAs("Tiff", dir2+title+"d2.tif");
                                close();
                                setBatchMode(false);

                                }
                        }
                }
        }

Best wishes

Kees


Dr K.R. Straatman
Senior Experimental Officer
Centre for Core Biotechnology Services
College of Medicine, Biological Sciences and Psychology
http://www.le.ac.uk/biochem/microscopy/home.html


-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Dr D.J. Metcalf
Sent: 04 August 2010 17:14
To: [hidden email]
Subject: Batch split channels and save

Hi,

I'd be grateful for some help on making my macro capable of batch
processing a folder of images. I'm not sure if it's possible to modify the
one I've written or if another approach is required.

The aim is to open RGB tif files and then save the individual channels but
with the added complication of discarding the blue image and saving the
green and red images. Ideally I'd like to save the green image twice with
different file names (see below).

My starting file names are A_A##f##.tif My result file names are
A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the green
chanel, d1 is the green channel and d2 is the red channel)

Thanks,

Dan


open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");
run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); close();
close(); run("Save",
"save=[V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif]"); close();
open("V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif");
open("V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); run("Merge
Channels...", "red=C3-A_A06f12.tif green=C1-A_A06f12.tif
blue=C1-A_A06f12.tif gray=*None* create"); run("Split Channels");
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d0.tif]"); close();
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d1.tif]"); close();
run("Save", "save=[V:\\Dan\\new files\\A_A06f12d2.tif]"); close();
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

Dr D.J. Metcalf
Dear Kees,

Thanks for your reply. I've just tried the macro but I get an error message:
 
'(' expected in line 19.

title= File . nameWithoutExtension <;>

Regards,

Dan

On Aug 6 2010, Straatman, Kees R. (Dr.) wrote:

>Dear Dan,
>
> See if the macro below does what you want. At the moment it saves the
> results to a new directory called "analysed". If you want to save the
> result files in the same directory as your original files delete the line
> "dir2 = ....." and change in the first lane "dir1" into "dir2"
>
>
>dir1 = getDirectory("Choose Source Directory ");
>list = getFileList(dir1);
>dir2 = dir1+"analysed"+File.separator;
>File.makeDirectory(dir2);
>for (i=0; i<list.length; i++)
> {
>
> if (File.isDirectory(dir1+list[i])){}
> else{
>
> path = dir1+list[i];
> if (endsWith(path, ".db")){}
> else{
>
> open(path);
> if (bitDepth!=24){}  
> else {
> setBatchMode(true);
> title = File.nameWithoutExtension ;
> run("Split Channels");
> close();
>
> saveAs("Tiff", dir2+title+"d0.tif");
> saveAs("Tiff", dir2+title+"d1.tif");
> close();
> saveAs("Tiff", dir2+title+"d2.tif");
> close();
> setBatchMode(false);
>
> }
> }
> }
> }
>
>Best wishes
>
>Kees
>
>
>Dr K.R. Straatman
>Senior Experimental Officer
>Centre for Core Biotechnology Services
>College of Medicine, Biological Sciences and Psychology
>http://www.le.ac.uk/biochem/microscopy/home.html
>
>
> -----Original Message----- From: ImageJ Interest Group
> [mailto:[hidden email]] On Behalf Of Dr D.J. Metcalf Sent: 04 August
> 2010 17:14 To: [hidden email] Subject: Batch split channels and save
>
>Hi,
>
>I'd be grateful for some help on making my macro capable of batch
>processing a folder of images. I'm not sure if it's possible to modify the
>one I've written or if another approach is required.
>
>The aim is to open RGB tif files and then save the individual channels but
>with the added complication of discarding the blue image and saving the
>green and red images. Ideally I'd like to save the green image twice with
>different file names (see below).
>
>My starting file names are A_A##f##.tif My result file names are
>A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the green
>chanel, d1 is the green channel and d2 is the red channel)
>
>Thanks,
>
>Dan
>
>
> open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");
> run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif");
> close(); close(); run("Save",
> "save=[V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif]"); close();
> open("V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif");
> open("V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); run("Merge
> Channels...", "red=C3-A_A06f12.tif green=C1-A_A06f12.tif
> blue=C1-A_A06f12.tif gray=*None* create"); run("Split Channels");
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d0.tif]"); close();
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d1.tif]"); close();
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d2.tif]"); close();
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

Krs5
Dear Dan,

Maybe delete the spaces in this line?

However, on my system it runs without problems. Windows XP, ImageJ 1.44e, so not sure what the problem is. I also copied the email text back into a new text window and it still runs OK

Kees

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Dr D.J. Metcalf
Sent: 06 August 2010 13:36
To: [hidden email]
Subject: Re: Batch split channels and save

Dear Kees,

Thanks for your reply. I've just tried the macro but I get an error message:
 
'(' expected in line 19.

title= File . nameWithoutExtension <;>

Regards,

Dan

On Aug 6 2010, Straatman, Kees R. (Dr.) wrote:

>Dear Dan,
>
> See if the macro below does what you want. At the moment it saves the
> results to a new directory called "analysed". If you want to save the
> result files in the same directory as your original files delete the line
> "dir2 = ....." and change in the first lane "dir1" into "dir2"
>
>
>dir1 = getDirectory("Choose Source Directory ");
>list = getFileList(dir1);
>dir2 = dir1+"analysed"+File.separator;
>File.makeDirectory(dir2);
>for (i=0; i<list.length; i++)
> {
>
> if (File.isDirectory(dir1+list[i])){}
> else{
>
> path = dir1+list[i];
> if (endsWith(path, ".db")){}
> else{
>
> open(path);
> if (bitDepth!=24){}  
> else {
> setBatchMode(true);
> title = File.nameWithoutExtension ;
> run("Split Channels");
> close();
>
> saveAs("Tiff", dir2+title+"d0.tif");
> saveAs("Tiff", dir2+title+"d1.tif");
> close();
> saveAs("Tiff", dir2+title+"d2.tif");
> close();
> setBatchMode(false);
>
> }
> }
> }
> }
>
>Best wishes
>
>Kees
>
>
>Dr K.R. Straatman
>Senior Experimental Officer
>Centre for Core Biotechnology Services
>College of Medicine, Biological Sciences and Psychology
>http://www.le.ac.uk/biochem/microscopy/home.html
>
>
> -----Original Message----- From: ImageJ Interest Group
> [mailto:[hidden email]] On Behalf Of Dr D.J. Metcalf Sent: 04 August
> 2010 17:14 To: [hidden email] Subject: Batch split channels and save
>
>Hi,
>
>I'd be grateful for some help on making my macro capable of batch
>processing a folder of images. I'm not sure if it's possible to modify the
>one I've written or if another approach is required.
>
>The aim is to open RGB tif files and then save the individual channels but
>with the added complication of discarding the blue image and saving the
>green and red images. Ideally I'd like to save the green image twice with
>different file names (see below).
>
>My starting file names are A_A##f##.tif My result file names are
>A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the green
>chanel, d1 is the green channel and d2 is the red channel)
>
>Thanks,
>
>Dan
>
>
> open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");
> run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif");
> close(); close(); run("Save",
> "save=[V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif]"); close();
> open("V:\\Dan\\tif_files\\discards\\C1-A_A06f12.tif");
> open("V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif"); run("Merge
> Channels...", "red=C3-A_A06f12.tif green=C1-A_A06f12.tif
> blue=C1-A_A06f12.tif gray=*None* create"); run("Split Channels");
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d0.tif]"); close();
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d1.tif]"); close();
> run("Save", "save=[V:\\Dan\\new files\\A_A06f12d2.tif]"); close();
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

BenTupper
In reply to this post by Dr D.J. Metcalf
Hi,

On Aug 6, 2010, at 8:35 AM, Dr D.J. Metcalf wrote:

> Dear Kees,
>
> Thanks for your reply. I've just tried the macro but I get an error  
> message:
> '(' expected in line 19.
>
> title= File . nameWithoutExtension <;>
>

It might be that you have a different version of ImageJ than that  
required.  The File.nameWithoutExtension requires at least 1.42d  
according to ...

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

Cheers,
Ben




> Regards,
>
> Dan
>
> On Aug 6 2010, Straatman, Kees R. (Dr.) wrote:
>
>> Dear Dan,
>>
>> See if the macro below does what you want. At the moment it saves  
>> the results to a new directory called "analysed". If you want to  
>> save the result files in the same directory as your original files  
>> delete the line "dir2 = ....." and change in the first lane "dir1"  
>> into "dir2"
>>
>>
>> dir1 = getDirectory("Choose Source Directory ");
>> list = getFileList(dir1);
>> dir2 = dir1+"analysed"+File.separator;
>> File.makeDirectory(dir2);
>> for (i=0; i<list.length; i++) {
>>
>> if (File.isDirectory(dir1+list[i])){}
>> else{
>>
>> path = dir1+list[i];
>> if (endsWith(path, ".db")){} else{
>>
>> open(path);
>> if (bitDepth!=24){}   else {
>> setBatchMode(true); title = File.nameWithoutExtension ;
>> run("Split Channels");
>> close();
>>
>> saveAs("Tiff", dir2+title+"d0.tif");
>> saveAs("Tiff", dir2+title+"d1.tif");
>> close();
>> saveAs("Tiff", dir2+title+"d2.tif");
>> close();
>> setBatchMode(false);
>> }
>> }
>> }
>> }
>>
>> Best wishes
>>
>> Kees
>>
>>
>> Dr K.R. Straatman
>> Senior Experimental Officer
>> Centre for Core Biotechnology Services
>> College of Medicine, Biological Sciences and Psychology
>> http://www.le.ac.uk/biochem/microscopy/home.html
>>
>>
>> -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]
>> ] On Behalf Of Dr D.J. Metcalf Sent: 04 August 2010 17:14 To: [hidden email]
>>  Subject: Batch split channels and save
>>
>> Hi,
>>
>> I'd be grateful for some help on making my macro capable of batch  
>> processing a folder of images. I'm not sure if it's possible to  
>> modify the one I've written or if another approach is required.
>>
>> The aim is to open RGB tif files and then save the individual  
>> channels but with the added complication of discarding the blue  
>> image and saving the green and red images. Ideally I'd like to save  
>> the green image twice with different file names (see below).
>>
>> My starting file names are A_A##f##.tif My result file names are  
>> A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the  
>> green chanel, d1 is the green channel and d2 is the red channel)
>>
>> Thanks,
>>
>> Dan
>>
>> open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");  
>> run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif");  
>> close(); close(); run("Save", "save=[V:\\Dan\\tif_files\\discards\
>> \C1-A_A06f12.tif]"); close(); open("V:\\Dan\\tif_files\\discards\
>> \C1-A_A06f12.tif"); open("V:\\Dan\\tif_files\\discards\\C3-
>> A_A06f12.tif"); run("Merge Channels...", "red=C3-A_A06f12.tif  
>> green=C1-A_A06f12.tif blue=C1-A_A06f12.tif gray=*None* create");  
>> run("Split Channels"); run("Save", "save=[V:\\Dan\\new files\
>> \A_A06f12d0.tif]"); close(); run("Save", "save=[V:\\Dan\\new files\
>> \A_A06f12d1.tif]"); close(); run("Save", "save=[V:\\Dan\\new files\
>> \A_A06f12d2.tif]"); close();
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

Dr D.J. Metcalf
Thanks very much. You're right; I was running an older version of ImageJ.
The macro works perfectly Kees. Thanks,

Dan


On Aug 6 2010, Ben Tupper wrote:

>Hi,
>
>On Aug 6, 2010, at 8:35 AM, Dr D.J. Metcalf wrote:
>
>> Dear Kees,
>>
>> Thanks for your reply. I've just tried the macro but I get an error  
>> message:
>> '(' expected in line 19.
>>
>> title= File . nameWithoutExtension <;>
>>
>
>It might be that you have a different version of ImageJ than that  
>required.  The File.nameWithoutExtension requires at least 1.42d  
>according to ...
>
>http://rsb.info.nih.gov/ij/developer/macro/functions.html#F
>
>Cheers,
>Ben
>
>
>
>
>> Regards,
>>
>> Dan
>>
>> On Aug 6 2010, Straatman, Kees R. (Dr.) wrote:
>>
>>> Dear Dan,
>>>
>>> See if the macro below does what you want. At the moment it saves  
>>> the results to a new directory called "analysed". If you want to  
>>> save the result files in the same directory as your original files  
>>> delete the line "dir2 = ....." and change in the first lane "dir1"  
>>> into "dir2"
>>>
>>>
>>> dir1 = getDirectory("Choose Source Directory ");
>>> list = getFileList(dir1);
>>> dir2 = dir1+"analysed"+File.separator;
>>> File.makeDirectory(dir2);
>>> for (i=0; i<list.length; i++) {
>>>
>>> if (File.isDirectory(dir1+list[i])){}
>>> else{
>>>
>>> path = dir1+list[i];
>>> if (endsWith(path, ".db")){} else{
>>>
>>> open(path);
>>> if (bitDepth!=24){}   else {
>>> setBatchMode(true); title = File.nameWithoutExtension ;
>>> run("Split Channels");
>>> close();
>>>
>>> saveAs("Tiff", dir2+title+"d0.tif");
>>> saveAs("Tiff", dir2+title+"d1.tif");
>>> close();
>>> saveAs("Tiff", dir2+title+"d2.tif");
>>> close();
>>> setBatchMode(false);
>>> }
>>> }
>>> }
>>> }
>>>
>>> Best wishes
>>>
>>> Kees
>>>
>>>
>>> Dr K.R. Straatman
>>> Senior Experimental Officer
>>> Centre for Core Biotechnology Services
>>> College of Medicine, Biological Sciences and Psychology
>>> http://www.le.ac.uk/biochem/microscopy/home.html
>>>
>>>
>>> -----Original Message----- From: ImageJ Interest Group
>>> [mailto:[hidden email] ] On Behalf Of Dr D.J. Metcalf Sent: 04
>>> August 2010 17:14 To: [hidden email]
>>>  Subject: Batch split channels and save
>>>
>>> Hi,
>>>
>>> I'd be grateful for some help on making my macro capable of batch  
>>> processing a folder of images. I'm not sure if it's possible to  
>>> modify the one I've written or if another approach is required.
>>>
>>> The aim is to open RGB tif files and then save the individual  
>>> channels but with the added complication of discarding the blue  
>>> image and saving the green and red images. Ideally I'd like to save  
>>> the green image twice with different file names (see below).
>>>
>>> My starting file names are A_A##f##.tif My result file names are  
>>> A_A##f##d0.tif, A_A##f##d1.tif, A_A##f##d2.tif (where d0 is the  
>>> green chanel, d1 is the green channel and d2 is the red channel)
>>>
>>> Thanks,
>>>
>>> Dan
>>>
>>> open("V:\\Dan\\tif_files\\A_A06f12.tif"); run("Split Channels");  
>>> run("Save", "save=V:\\Dan\\tif_files\\discards\\C3-A_A06f12.tif");  
>>> close(); close(); run("Save", "save=[V:\\Dan\\tif_files\\discards\
>>> \C1-A_A06f12.tif]"); close(); open("V:\\Dan\\tif_files\\discards\
>>> \C1-A_A06f12.tif"); open("V:\\Dan\\tif_files\\discards\\C3-
>>> A_A06f12.tif"); run("Merge Channels...", "red=C3-A_A06f12.tif  
>>> green=C1-A_A06f12.tif blue=C1-A_A06f12.tif gray=*None* create");  
>>> run("Split Channels"); run("Save", "save=[V:\\Dan\\new files\
>>> \A_A06f12d0.tif]"); close(); run("Save", "save=[V:\\Dan\\new files\
>>> \A_A06f12d1.tif]"); close(); run("Save", "save=[V:\\Dan\\new files\
>>> \A_A06f12d2.tif]"); close();
>
Reply | Threaded
Open this post in threaded view
|

Re: Batch split channels and save

cmparkes
In reply to this post by Dr D.J. Metcalf
Hello I am having a similar problem.

I have Images which I want to split into the three colour channels. I have worked out the commands that I would like to be performed on the green and blue images once they have been split, but when it comes to putting it into a batch command process I don't know how to change my code so that it will apply to all of the images in the directory I want to use and select the blue image to do the following steps with.

This is what I would like to happen to the BLUE images:
open("FOLDER NAMEf");
run("Split Channels");
selectWindow[THIS IS WHERE I THINK I NEED TO PUT THE FILE NAME OF THE SPLIT WINDOW???]

//run("Brightness/Contrast...");
setMinAndMax(0, 50);
run("Close");
run("Enhance Contrast...", "saturated=2 normalize");
run("Find Edges");
setAutoThreshold("Default dark");
//run("Threshold...");
setThreshold(0, 193);
run("Measure");
I would then like the Green and Blue images to be saved to separate directorys and discard the red image.


I am not a programmer so any help would be greatly appreciated.

Thanks,

Christina