concatenate images.

Discuss questions and projects related to processing of imaging data here
Post Reply
user-3423
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

concatenate images.

Post by user-3423 »

I have a folder of individual images taken from a time series.
Any suggestions on how to concatenate back into one file?
The Time Concatenation function is not available in Record, and I haven't been able to find a similar function in OAD.

Soren
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

I have a folder of individual images taken from a time series.
Any suggestions on how to concatenate back into one file?
The time concatenate function is not yet available in the MacroEditor.
But you can solve this by the following macro:

Code: Select all

################################################################
##
## Macro name: Concatenate single time points to a time series
##
## Load single time point images
## Concatenate all single time points to a time series 
## 
################################################################
##
##
## Remove all open documents
Zen.Application.Documents.RemoveAll()
##
## activate IO library
from System.IO import File, Directory, FileInfo
##
## create setup dialog
window = ZenWindow()
InImages = Zen.Application.Environment.GetFolderPath(ZenSpecialFolder.Images)
OutImages = Zen.Application.Environment.GetFolderPath(ZenSpecialFolder.Images)
window.AddFolderBrowser('sourcefolder','Source folder (Single time points)              ',InImages)
window.AddFolderBrowser('destfolder','Destination folder (Concatenated images) ',OutImages)
##
## do setup
result=window.Show()
## check, if Cancel button was clicked
if result.HasCanceled == True:
    sys.exit('Macro aborted with Cancel!')
## get string name of source folder
sPath = str(result.GetValue('sourcefolder'))
## Check, if source path exists
if (Directory.Exists(sPath)== False):
    strMessage = 'Path: ' + sPath + ' does not exist!\nRestart macro and select an existing path!'
    sys.exit(strMessage)
## get string name of destination folder
dPath = str(result.GetValue('destfolder'))
## Check, if destination path exists
if (Directory.Exists(dPath)== False):
    strMessage = 'Path: ' + dPath + ' does not exist!\nRestart macro and select an existing path!'
    sys.exit(strMessage)
## set file type for images
itype = "*.czi" 
files = Directory.GetFiles(sPath,itype)
## Check, if image type exists
if files.Length == 0: 
    strMessage = 'Images of type : ' + itype + ' do not exist!\nRestart macro and select an existing image type!'
    sys.exit(strMessage)
##
## Sort files in one folder list
mylist = []
## append all file names in list
files = Directory.GetFiles(sPath,itype)
for i in range(0,files.Length): 
    file = files[i] 
    fileInfo = FileInfo(file) 
    PathAndFile = sPath + "\\" + fileInfo.Name
    fileName = fileInfo.Name
    len = fileName.Length
    mylist.append(fileName)
## sort list
mylist.sort()
##
## Load all time points automatically
for t in range(0,mylist.Count):
    print mylist[t]
    PathAndFile = sPath + "\\" + mylist[t]
    image = Zen.Application.LoadImage(PathAndFile,False)
    #Zen.Application.Documents.Add(image)
    if t == 0:
        ## Clone image
        destImage = image.Clone()
        ## Clone display setting
        dsp = image.DisplaySetting.Clone()
        ## Get file name without extension
        im = image.Name
        prefix = im.Substring(0,im.Length-4)
    ## Add each time point to destination image
    destImage.AddSubImage(image, t, 0, 0)
##
## Show result image
destImage.SetDisplaySetting(dsp)
## Apply display setting of first image
Zen.Application.Documents.Add(destImage) 
##
## Save time series in destination folder
newFileName = prefix + '.czi'
imageName = dPath + '\\' + newFileName
destImage.Save(imageName)
##
################################################################
user-3423
Posts: 4
Joined: Thu Jan 01, 1970 1:00 am

Post by user-3423 »

Thanks for the swift reply.
Any suggestions if I want to concatenate Z-stacks?
user-9
Posts: 82
Joined: Thu Jan 01, 1970 1:00 am

Post by user-9 »

Any suggestions if I want to concatenate Z-stacks?
This is easy to do as you have to modify one line in the macro:

Code: Select all

    
destImage.AddSubImage(image, 0, 0, z)
user-5282
Posts: 1
Joined: Thu Jan 01, 1970 1:00 am

Image concatenate

Post by user-5282 »

Thank you for sharing about image concatenate...It was very useful for my Image processing..!!

Regards
user-64
Posts: 22
Joined: Thu Jan 01, 1970 1:00 am

image concatenate

Post by user-64 »

I want to point out that I have had very good success with using "Image Import" in the processing tab.

Any TIF series can be sort of glued back together, if the files are correctly named, using the import.

As an example, I have used this to acquire individual z-stacks of 500 planes, with overlapping xy coordinates, and then import as a tiles image.

I used a file naming utility called "Bulk Rename Utility" in order to get the TIFs in the proper naming convention for the import.
user-64
Posts: 22
Joined: Thu Jan 01, 1970 1:00 am

Concatenate time images

Post by user-64 »

Admin,

I have just tried the code posted for concatenate time images, and the results are not correct. The channels in my resulting images are not maintained properly. Each timepoint after 1 is listed as having all channels, but the image data is only present for the first channel.

Can you confirm that this code should still work for a multi-channel image? I am using Zen 2.6.

I have attached a 3 timepoint result showing the issue.

I have had a similar issue attempting to use .AddSubImage and .AddScene, and came to this post trying to find an answer.


Regards,

Dan
Attachments
time concatenate results.zip
(5.2 MiB) Downloaded 165 times
user-4
Posts: 398
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Hello Dan,

the code above is based on

destImage.AddSubImage(image, t, c, z)

where t stands for time, c for channel and z for z-position.

So what you can do is to add individual images t=0, c=0...3

destImage.AddSubImage(image00, 0, 0, 0)
destImage.AddSubImage(image01, 0, 1, 0)
destImage.AddSubImage(image02, 0, 2, 0)
destImage.AddSubImage(image03, 0, 3, 0)

and then t=1, c=0...3

destImage.AddSubImage(image10, 1, 0, 0)
destImage.AddSubImage(image11, 1, 1, 0)
destImage.AddSubImage(image12, 1, 2, 0)
destImage.AddSubImage(image13, 1, 3, 0)

and finally t=2, c=0...3

destImage.AddSubImage(image20, 2, 0, 0)
destImage.AddSubImage(image21, 2, 1, 0)
destImage.AddSubImage(image22, 2, 2, 0)
destImage.AddSubImage(image23, 2, 3, 0)

But the function is not desigend to add images that are composed of multiple images (channels in your case) in a single step.

I understand that this would be a nice feature.
Post Reply