Jump to content

Photoshop - combine red and green channel images into a merged image?


4 posts in this topic

Recommended Posts

I am a developmental biologist carrying out experiments on a type of microscope known as a Confocal Laser Scanning Microscope (CSLM). Basically, this is a microscope coupled to some lasers which allow fluorescently-labelled parts of a biological sample to be imaged in high detail.

 

For each sample there will be a set of two images produced, named and numbered as follows:

 

sample01_g.tif

sample01_r.tif

 

Each image represents one fluorescent wavelength and correspond to green ( g ) and red ( r ). These images are in rgb colour.

 

I want to produce a merge of these two channels to generate a new TIFF file such that:

 

Green channel is taken from sample01_g.tif

Red channel is taken from sample01_r.tif

 

Which would show me how the different channels co-localise, or not.

 

This is fine to do by hand in Photoshop, but takes a long time when you have a couple of hundred images to process. So, what I would like to do is write a script that batch automates the process, like a droplet. I have the process outlined below:

 

1. Create a new RGB TIFF called sample01_merge.tif

2. Take the green channel from sample01_g.tif and copy it to the green channel of sample01_merge.tif

3. Take the red channel from sample01_r.tif and copy it to the red channel of sample01_merge.tif

4. Save sample01_merge.tif into a folder named "Merged Images" on the desktop

5. Close the opened images

6. Go to next set of images –> sample02_g.tif and sample02_r.tif

7. Create a new RGB TIFF called sample02_merge.tif....and go through step 2-6, untill the last set of images has been processed.

 

I have never used Applescript before and would love to learn, but I am making slow progress and would like to have this problem solved sooner than I will be able to do so by myself. So... I was wondering if anyone could give me some advice on how to go about doing this?

 

Any help will be greatly appreciated!

 

Best regards,

John

Link to comment
Share on other sites

Hi, it sounds interesting. Which kinds of samples are you analyzing?

 

I'm not really familiar with AppleScript and I would recommend you to consider creating a shell script utilizing the freeware tool Imagemagick (section "Combining RGB Channel Images").

 

This shell script should do the conversion:

#!/bin/sh

dirMerged="Merged Images"
suffixMerged="_merge"

mkdir "$dirMerged"
# Separate red channel for images with suffix _r. Output in folder $dirMerged.
for img in *_r.tif; do
 convert "$img" -channel R -separate "$dirMerged"/"$img"
done
# Separate green channel for images with suffix _g. Output in folder $dirMerged.
for img in *_g.tif; do
 convert "$img" -channel G -separate "$dirMerged"/"$img"
done
# Combine red and green channels. Output in $dirMerged.
# Remove single channel images from $dirMerged.
cd "$dirMerged"
for img in *_r.tif; do
 img=${img%_r.*}
 convert "$img"_r.tif "$img"_g.tif -channel red,green -combine "${img}${suffixMerged}".tif
 rm "$img"_r.tif "$img"_g.tif
done

Link to comment
Share on other sites

I forgot to mention a thing. Imagemagick requires an additional installation argument for TIFF support.

 

I would recommend you to use homebrew to manage the installation.

After you set it up, enter "brew install imagemagick --with-libtiff" to set up imagemagick.

That should be all.

Link to comment
Share on other sites

 Share

×
×
  • Create New...