Discussion:
Batch channel splitter
csadangi
2014-09-11 15:54:54 UTC
Permalink
Does anyone know how to split channels in a batch for multiple images using
ImageJ?

Also how to select only a particular channel for batch conversion? For ex:
converting multiple RGB TIFF images to green channel only?

Lastly, how can i change the default save from .TIFF to .JPEG. When i press
CTRL+S after taking a screenshot my images are stored as .TIFF and i want to
save the images as .JPEG.

Thanks :)



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Mark Hiner
2014-09-11 17:36:28 UTC
Permalink
Post by csadangi
Does anyone know how to split channels in a batch for multiple images
using ImageJ?

Batch processing is a pretty common question, so I wrote a wiki page
explaining your options: http://imagej.net/Batch_Processing

The split channels command (macro code: run("Split Channels"); ) produces
output images for each channel, so you would want to use the batch
processing template <http://imagej.net/Batch_Processing#Flexible_option>,
and only write out the image(s) corresponding to your desired channel(s).
Post by csadangi
Lastly, how can i change the default save from .TIFF to .JPEG
CTRL+S ends up calling the File Saver#save()
<https://github.com/imagej/ImageJA/blob/master/src/main/java/ij/io/FileSaver.java#L37-39>
method, which always writes TIFFs it looks like. However, there is a Save
as JPEG... command under Plugins>Macros, with a default hotkey of "j" as
well as the File>Save As>Jpeg... option, either of which can be used in
your final batch macro to write out JPEGs.

Hope that helps,
Mark
Post by csadangi
Does anyone know how to split channels in a batch for multiple images using
ImageJ?
converting multiple RGB TIFF images to green channel only?
Lastly, how can i change the default save from .TIFF to .JPEG. When i press
CTRL+S after taking a screenshot my images are stored as .TIFF and i want to
save the images as .JPEG.
Thanks :)
--
http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
csadangi
2014-09-11 17:39:02 UTC
Permalink
Hi Mark,

Thanks for the tips :)

Image saving to JPEG format works fine but is there any way we can change it
from TIFF to JPEG.

I am not aware of how to edit the macro. Could you help?
I understood this --- go to process --- batch --- macro, then i set up the
input and output folders and the desired format. I want the conversion to
green and red channels only. How can i do that?

Thanks a lot for your help :)



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009579.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Jeff Spector
2014-09-11 17:39:36 UTC
Permalink
Post by csadangi
Does anyone know how to split channels in a batch for multiple images using
ImageJ?
converting multiple RGB TIFF images to green channel only?
Lastly, how can i change the default save from .TIFF to .JPEG. When i press
CTRL+S after taking a screenshot my images are stored as .TIFF and i want to
save the images as .JPEG.
Thanks :)
--
http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Hi,
You can split the channels and then select the channel you want using the
imageID. A Macro that looks something like this

run("Split Channels"); //split the channels
blue = getImageID(); // get id of blue image
red = blue+1 ; //assign ids
green = blue + 2; //assign ids


should get you the individual channels.
then you can use selectImage(ImageID) to get the channel you want..


selectImage(green);

and then save it..


hope this helps...
-Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
csadangi
2014-09-11 18:15:15 UTC
Permalink
Hi Jeff,

I got the following code. Can you tell me what all to delete just to get the
green and red channel. I want one code for green and one for red. And is
this a java or a python language.

dir=getDirectory("Choose a Directory");
print(dir);
splitDir=dir + "\Split\\";
print(splitDir);
File.makeDirectory(splitDir);
list = getFileList(dir);

for (i=0; i<list.length; i++) {
if (endsWith(list[i], ".tif")){
print(i + ": " + dir+list[i]);
open(dir+list[i]);
imgName=getTitle();
baseNameEnd=indexOf(imgName, ".tif");
baseName=substring(imgName, 0, baseNameEnd);

run("Split Channels");
selectWindow(imgName + " (blue)");
rename(baseName + "-blue.tiff");
saveAs("Tiff", splitDir+baseName + "-blue.tif");
close();
selectWindow(imgName + " (green)");
saveAs("Tiff", splitDir+baseName + "-green.tif");
close();
selectWindow(imgName + " (red)");
saveAs("Tiff", splitDir+baseName + "-red.tif");

run("Close All");
}
}



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009583.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Herbie
2014-09-11 18:31:33 UTC
Permalink
No name,

the code is neither written in java, nor python but in the ImageJ-macro
language that is documented here
<http://rsb.info.nih.gov/ij/developer/macro/macros.html>
there
<http://fiji.sc/Introduction_into_Macro_Programming>
and there
<http://rsb.info.nih.gov/ij/developer/macro/functions.html>
and maybe many other places.

HTH

Herbie
Post by csadangi
Hi Jeff,
I got the following code. Can you tell me what all to delete just to
get the green and red channel. I want one code for green and one for
red. And is this a java or a python language.
dir=getDirectory("Choose a Directory"); print(dir); splitDir=dir +
"\Split\\"; print(splitDir); File.makeDirectory(splitDir); list =
getFileList(dir);
for (i=0; i<list.length; i++) { if (endsWith(list[i], ".tif")){
print(i + ": " + dir+list[i]); open(dir+list[i]);
imgName=getTitle(); baseNameEnd=indexOf(imgName, ".tif");
baseName=substring(imgName, 0, baseNameEnd);
run("Split Channels"); selectWindow(imgName + " (blue)");
rename(baseName + "-blue.tiff"); saveAs("Tiff", splitDir+baseName +
"-blue.tif"); close(); selectWindow(imgName + " (green)");
saveAs("Tiff", splitDir+baseName + "-green.tif"); close();
selectWindow(imgName + " (red)"); saveAs("Tiff", splitDir+baseName +
"-red.tif");
run("Close All"); } }
http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009583.html
Sent from the ImageJ mailing list archive at Nabble.com.
Post by csadangi
-- ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Jeff Spector
2014-09-11 20:02:30 UTC
Permalink
Post by csadangi
Hi Jeff,
I got the following code. Can you tell me what all to delete just to get the
green and red channel. I want one code for green and one for red. And is
this a java or a python language.
dir=getDirectory("Choose a Directory");
print(dir);
splitDir=dir + "\Split\\";
print(splitDir);
File.makeDirectory(splitDir);
list = getFileList(dir);
for (i=0; i<list.length; i++) {
if (endsWith(list[i], ".tif")){
print(i + ": " + dir+list[i]);
open(dir+list[i]);
imgName=getTitle();
baseNameEnd=indexOf(imgName, ".tif");
baseName=substring(imgName, 0, baseNameEnd);
run("Split Channels");
selectWindow(imgName + " (blue)");
rename(baseName + "-blue.tiff");
saveAs("Tiff", splitDir+baseName + "-blue.tif");
close();
selectWindow(imgName + " (green)");
saveAs("Tiff", splitDir+baseName + "-green.tif");
close();
selectWindow(imgName + " (red)");
saveAs("Tiff", splitDir+baseName + "-red.tif");
run("Close All");
}
}
--
http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009583.html
Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
This is imageJ macro language. There are many good examples and it is worth
taking some time to look through them. I'm not sure what your goal is, and
the "example" code above is different that what I suggested (using imageIDs
to get the different channels) but I am guessing that you don't want to
save the blue image, so try deleting

rename(baseName + "-blue.tiff");
saveAs("Tiff", splitDir+baseName + "-blue.tif");

and see where you can go from there..
-Jeff

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
csadangi
2014-09-11 21:33:57 UTC
Permalink
so i have developed/modified three macros. One for both red & green, one only
for red and one for green. Thank you everyone for your guidance and help :)

"for both"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+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("Jpeg", dir2+title+"green.jpg");
close();
saveAs("Jpeg", dir2+title+"red.jpg");
close();
setBatchMode(false);

}
}
}
}

===========
"GREEN"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+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("Jpeg", dir2+title+"green.jpg");
close();
close();
setBatchMode(false);

}
}
}
}
==========

"RED"

dir1 = getDirectory("open file ");
list = getFileList(dir1);
dir2 = dir1+"splits"+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();


close();
saveAs("Jpeg", dir2+title+"red.jpg");
close();
setBatchMode(false);

}
}
}
}



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009595.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Curtis Rueden
2014-09-11 18:18:20 UTC
Permalink
Hi Chinmaya,
Post by csadangi
I am not aware of how to edit the macro. Could you help?
Your exact question has been asked and answered before; maybe this thread
in the archives helps you. It has a fully formed macro you could adapt to
your purposes.

https://list.nih.gov/cgi-bin/wa.exe?A2=IMAGEJ;cdc7ef1a.1008

Regards,
Curtis
Post by csadangi
Post by csadangi
Does anyone know how to split channels in a batch for multiple images
using
Post by csadangi
ImageJ?
Also how to select only a particular channel for batch conversion? For
converting multiple RGB TIFF images to green channel only?
Lastly, how can i change the default save from .TIFF to .JPEG. When i
press
Post by csadangi
CTRL+S after taking a screenshot my images are stored as .TIFF and i want to
save the images as .JPEG.
Thanks :)
--
http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575.html
Sent from the ImageJ mailing list archive at Nabble.com.
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Hi,
You can split the channels and then select the channel you want using the
imageID. A Macro that looks something like this
run("Split Channels"); //split the channels
blue = getImageID(); // get id of blue image
red = blue+1 ; //assign ids
green = blue + 2; //assign ids
should get you the individual channels.
then you can use selectImage(ImageID) to get the channel you want..
selectImage(green);
and then save it..
hope this helps...
-Jeff
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
csadangi
2014-09-11 19:06:21 UTC
Permalink
Hi Curtis,

That was helpful. I think i can save them in .JPEG format by substituting
.TIFF with .JPEG?
But it again gives me all the 3 channels and i need only 1. So how can i do
that? Also, now it doesn't tell me which one is blue, green or red.

Any help would be highly appreciated



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009589.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Cammer, Michael
2014-09-11 19:27:22 UTC
Permalink
Example syntax:

saveAs("Jpeg", "J:\\Smith_Lab_20140911\\Isabelle\\20140911_Liver_GFP\\temp.jpg");

===========================================================================
Michael Cammer, Microscopy Core & Skirball Institute, NYU Langone Medical Center
Cell: 914-309-3270 note that we do not receive messages left at 212-263-3208
http://ocs.med.nyu.edu/microscopy & http://microscopynotes.com/


-----Original Message-----
From: ImageJ Interest Group [mailto:IMAGEJ-9srhZJH3/***@public.gmane.org] On Behalf Of csadangi
Sent: Thursday, September 11, 2014 3:06 PM
To: IMAGEJ-9srhZJH3/***@public.gmane.org
Subject: Re: Batch channel splitter

Hi Curtis,

That was helpful. I think i can save them in .JPEG format by substituting .TIFF with .JPEG?
But it again gives me all the 3 channels and i need only 1. So how can i do that? Also, now it doesn't tell me which one is blue, green or red.

Any help would be highly appreciated



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009589.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
csadangi
2014-09-11 19:54:07 UTC
Permalink
Thanks Miachel.

How to get rid of getting all the three channels? I just need one.



--
View this message in context: http://imagej.1557.x6.nabble.com/Batch-channel-splitter-tp5009575p5009592.html
Sent from the ImageJ mailing list archive at Nabble.com.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Continue reading on narkive:
Loading...