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 images produced, named as follows:
Each image represents one fluorescent wavelength and correspond to green (ch0), red (ch1) and blue (ch2). These images are in indexed colour and have to be converted to RGB before processing. They are always 1024 x 1024 pixels.
I want to produce a merge of these channels to generate a new TIFF file such that:
Green channel is taken from SAMPLENAME_ch0.tif
Red channel is taken from SAMPLENAME_ch1.tif
Blue channel is taken from SAMPLENAME_ch2.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 automates the process. I have the process outlined below:
Convert SAMPLENAME_ch0.tif, SAMPLENAME_ch1.tif and SAMPLENAME_ch2.tif to RGB
Create a new RGB TIFF of dimensions 1024 x 1024 called SAMPLENAME_merge.tif
Take the green channel from SAMPLENAME_ch0.tif and copy it to the green channel of SAMPLENAME_merge.tif
Take the red channel from SAMPLENAME_ch1.tif and copy it to the red channel of SAMPLENAME_merge.tif
Take the blue channel from SAMPLENAME_ch2.tif and copy it to the blue channel of SAMPLENAME_merge.tif
Save SAMPLENAME_merge.tif
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?
Extra information:
Using an iMac with OSX 10.5
Photoshop CS installed
Any advice that anyone can give would be very gratefully received!
Cheers,
J
Model: iMac
Browser: Firefox 3.6.27
Operating System: Mac OS X (10.5)
Here is a possibly complicated non-photoshop but possible solution… tell me if it works!
FIRST, run this on each of the files:
repeat 3
set thePicture to quoted form of POSIX path of (choose file)
do shell script "/usr/bin/sips -m '/System/Library/ColorSync/Profiles/Generic RGB Profile.icc' -s " & thePicture
end repeat
It may take too long, however, as you have hundreds of photos, but I don’t have the expertise to give you a solution that will do this more automatically.
I think that this should get you pretty close. As it works right now you need to have the three images open. It will copy the “green” document to the clipboard, convert it to RGB and paste the coppied channel to the green channel of the RGB image. Then it will go to the red and blue, copy the channel close the file and paste it into the appropriate channel of the RGB image. Then it saves the new RGB image to the same folder as the original files with “_merge.tif” replacing the channel label in the file name.
To speed things up more I would probably make it into a dropplet with some file sorting routines to open the files as needed to build the composite images.
tell application "Adobe Photoshop CS4"
activate
set docOne to every document whose name ends with "0.tif"
set current document to item 1 of docOne
tell item 1 of docOne
-- set up varibles for path and file name based off first file
set OldDelim to AppleScript's text item delimiters
set theFile to file path as string
set AppleScript's text item delimiters to ":"
set saveFolder to text items 1 through -2 of theFile as string
set fileName to characters 1 through -8 of (last text item of theFile as string)
set AppleScript's text item delimiters to ""
set fileName to (fileName as string) & "_merge.tif"
set AppleScript's text item delimiters to OldDelim
--copy Green channel from channel 0 image
set channelList to every channel
set current channels to channelList
select all
cut
-- convert to RGB and paste green channel into channel 2 of image
change mode to RGB
set current channels to {channel 2} --Green Channel
paste
end tell
--copy Red channel from channel 1 image
set docTwo to every document whose name ends with "1.tif"
set current document to item 1 of docTwo
tell item 1 of docTwo
set channelList to every channel
set current channels to channelList
select all
cut
close saving no
end tell
--paste Red channel into channel 1 of combined image
set current document to item 1 of docOne
tell item 1 of docOne
set current channels to {channel 1} --Red Channel
paste
end tell
--copy blue channel from channel 2 image
set docThree to every document whose name ends with "2.tif"
set current document to item 1 of docThree
tell item 1 of docThree
set channelList to every channel
set current channels to channelList
select all
cut
close saving no
end tell
--paste blue channel into channel 3 of combined image
set current document to item 1 of docOne
tell item 1 of docOne
set current channels to {channel 3} --Blue Channel
paste
--save and close file
save in alias (saveFolder & ":" & fileName) as TIFF with copying
close saving no
end tell
end tell
I’m running into the same problem and would be grateful if you could guide me. I have about 450 tif images (one red channel and one green channel) that I need to assemble together. Is it possible to create a droplet that goes through the images and combines the red channel image and the green channel together (ex Sample01_r.tif and Sample01_g.tif, Sample02_r.tif and Sample02_g.tif and so on)?
I know nothing about AppleScript or Automator and I would really appreciate any help.
on open theImages
set theOutputFolder to (path to desktop folder as string) & "Merged Images:"
tell application "Finder"
if (folder theOutputFolder exists) = false then make new folder at desktop with properties {name:"Merged Images"}
end tell
repeat with anImage in theImages
tell application "Adobe Photoshop CS6"
set theOpenedImage to open anImage
tell theOpenImage
set theImageName to name
-- set up varibles for path and file name based off first file
set OldDelim to AppleScript's text item delimiters
set theFile to file path as string
set AppleScript's text item delimiters to ":"
set saveFolder to text items 1 through -2 of theFile as string
set fileName to characters 1 through -8 of (last text item of theFile as string)
set AppleScript's text item delimiters to ""
set theImageName to (theImageName as string) & "_merge.tif"
set AppleScript's text item delimiters to OldDelim
--copy Green channel from channel 0 image
set channelList to every channel
set current channels to channelList
select all
cut
-- convert to RGB and paste green channel into channel 2 of image
change mode to RGB
set current channels to {channel 2} --Green Channel
paste
end tell
--copy Red channel from channel 1 image
set anImage to (every document whose name ends with "r.tif")
set theOpenImage to item 1 of anImage
tell item 1 of anImage
set channelList to every channel
set current channels to channelList
select all
cut
close saving no
end tell
--paste Red channel into channel 1 of combined image
set current document to item 1 of anImage
tell item 1 of anImage
set current channels to {channel 1} --Red Channel
paste
save in (theOutputFolder & theImageName)
close
end tell
end tell
end repeat
end open
If anyone is still interested I could put together an iMagine Photo solution to this. Of non-cocoa solutions it is likely to be by far the fastest way to achieve what you want.