Jump to content

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


  • Please log in to reply
3 replies to this topic

#1
JohnnyR

JohnnyR

    InsanelyMac Protégé

  • Members
  • Pip
  • 2 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

#2
k3nny

k3nny

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 560 posts
  • Gender:Male
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


#3
JohnnyR

JohnnyR

    InsanelyMac Protégé

  • Members
  • Pip
  • 2 posts
It is cell samples from the retina of rats.

Thanks for your suggestion. I'm not familiar with imagemagick but I'll sure have a look at it now.

#4
k3nny

k3nny

    InsanelyMac Legend

  • Members
  • PipPipPipPipPipPipPip
  • 560 posts
  • Gender:Male
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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy