Login  Register

Re: Merge 4 color channels

Posted by Straub, Volko A. (Dr.) on May 23, 2015; 6:06am
URL: http://imagej.273.s1.nabble.com/Merge-4-color-channels-tp5012905p5012923.html

Okay, I had a closer look at your code. There were another few problems.
First, when you use the Bio-Formats Importer the first time, you also
need to combine the name variable with the rest of the string as I
mentioned in my last email. I would also suggest that you put square
brackets before and after the name variable to make sure that spaces in
your file names are included.
Second, all the commands are case sensitive. So, when you use color_mode
to pass an arguement to the Bio-Formats Importer, you need to use
color_mode, not Color_mode. The same applies to c2, c3 (not C2, C3) in
the merge command.
I modified the code below and it appears to be working. If you copy it,
just be aware of any line breaks that might have been introduced by the
email programme.
Finally, the code seems rather complicated for what you want to achieve.
If you simply want to assign specific colours to individual channels and
adjust their brightness, why don't you just open the image with the
Bio-Formats Importer without using the 'Split channel' option, but
select 'Composite' as Color Mode? You could then use the 'Channels Tool
- More' to assign specific colors to each channel. You should also be
able to individually adjust the brightness/contrast for each channel.
Hope this solves your issues,
Volko

Modified macro code:

dir1 = getDirectory('Choose Directory ');
list = getFileList(dir1);
dir2 = dir1+"JPG"+File.separator;
File.makeDirectory(dir2);

setBatchMode(true);
for (i=0; i<list.length; i++) {
print(dir1 + list[i]);
showProgress(i, list.length);
name = dir1 + list[i];

run("Bio-Formats Importer", "open=["+name+"] view=Hyperstack
stack_order=XYCZT color_mode=Default split_channels"); //name is
variable; put [ ] around string variable to include potential spaces in
filename; color_mode, not Colour mode
name1 = list[i];
index = lastIndexOf(name1, ".");
if (index!=-1) name2 = substring(name1, 0, index);
path = dir2 + name2;
print(path);

selectWindow(name1 + ' - C=0');
run("Channels Tool...");
run("Green");
run("RGB Color");
run("Brightness/Contrast...");
setMinAndMax(8, 50);
call("ij.ImagePlus.setDefault16bitRange", 8);
selectWindow("B&C");
run("Close");

selectWindow(name1 + ' - C=1');
run("Channels Tool...");
run("Blue");
run("RGB Color");
run("Brightness/Contrast...");
setMinAndMax(8, 150);
call("ij.ImagePlus.setDefault16bitRange", 8);
selectWindow("B&C");
run("Close");

selectWindow(name1 + ' - C=2');
run("Channels Tool...");
run("Yellow");
run("RGB Color");
run("Brightness/Contrast...");
setMinAndMax(8, 35);
call("ij.ImagePlus.setDefault16bitRange", 8);
selectWindow("B&C");
run("Close");

selectWindow(name1 + ' - C=3');
run("Channels Tool...");
run("Magenta");
run("RGB Color");
run("Brightness/Contrast...");
setMinAndMax(8, 100);
call("ij.ImagePlus.setDefault16bitRange", 8);
selectWindow("B&C");
run("Close");
selectWindow("Channels");
run("Close");

selectWindow(name1 + ' - C=0');
green = getTitle;
selectWindow(name1 + ' - C=1');
blue = getTitle;
selectWindow(name1 + ' - C=2');
yellow = getTitle;
selectWindow(name1 + ' - C=3');
magenta = getTitle;

print(green);
print(blue);
print(yellow);
print(magenta);

run("Merge Channels...", "c2=["+green+"] c3=["+blue+"] c6=["+yellow+"]
c7=["+magenta+"] keep"); // c2, not C2 (small c, commands are case
sensitive); use [] around string variables to include spaces in filenames
saveAs("jpeg", path + ".jpg");
run("Close");
}

On 22/05/2015 15:25, woojkim wrote:

> Dear Volko Straub,
>
> I tried as you suggested, but it shows the same dialog box...
> Any other suggestion?
> Thank you very much!
>
> Woo Jae
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Merge-4-color-channels-tp5012905p5012915.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