Combining multipage Tiffs with "2 dimension"

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
lorach
Posts: 3
Joined: 2020-02-13T05:49:22-07:00
Authentication code: 1152

Combining multipage Tiffs with "2 dimension"

Post by lorach »

Hi, I am beginner with Imagemagick

I try to combine different multipage Tiffs with convert and having some issues.

For example, I am trying to combine "Image1.tiff" and "Image2.tiff" to get an output "output.tiff". Whereas "Image1.tiff" and "Image2.tiff" are both multipage Tiffs with lets say 2 channels and 5 frames. If I now run

Code: Select all

convert Image1.tiff Image2.tiff -adjoin output.tiff 
I get "output.tiff" which is a multipage Tiff with 20 frames, whereas the first frame is channel 1 and frame 1 from "Image1.tiff", frame 2 is channel 2 and frame1 from "Image1.tiff", frame 3 is channel 1 and frame 2 from "Image1.tiff", ...

What I actually wanted would be a multipage Tiff with 2 channels and 10 frames.

I hope you understand what I mean...

Thanks a lot :D

snibgo
Posts: 12682
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combining multipage Tiffs with "2 dimension"

Post by snibgo »

"Channel" normally means a component of each pixel: the red channel, or alpha channel, etc. But you seem to mean something different.

Please paste a link to a TIFF file that has "2 channels and 5 frames".
snibgo's IM pages: im.snibgo.com

lorach
Posts: 3
Joined: 2020-02-13T05:49:22-07:00
Authentication code: 1152

Re: Combining multipage Tiffs with "2 dimension"

Post by lorach »

Wow that was a quick answer :) Ah maybe it is important to mention that they are 16 bit gray scale images, so the channels actually kind of correspond to colors.

Since I don't know where it would be the best to upload here a wetransfer link:
https://we.tl/t-IcTuUen7lB

There you find. Image1 and Image2 as well as the output.tif from Imagemagick and the expectet_output.tiff what is actually what I want. The output.jpg is a screenshot from imagej where you can clearly see the difference between what I want and what I get.

User avatar
fmw42
Posts: 26086
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combining multipage Tiffs with "2 dimension"

Post by fmw42 »

You cannot have just 2 channels in Imagemagick. But you can take two images and make then two channels (R or G or B) and make the extra channel black. I do not understand what you have done in ImageJ. Can you tell me what you did and I can then repeat it and then figure out what to do in Imagemagick.

Your two input images look the same or nearly so. The expected output also looks the same. But your comparison has red on one side. That is confusing to me. The two input images and the expected output image are all grayscale (one channel) and 20 pages. So I do not see any differences.

snibgo
Posts: 12682
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Combining multipage Tiffs with "2 dimension"

Post by snibgo »

image1.tif and image2.tif both contain ten images. All are 1024x1024, grayscale, no alpha. They all have only one channel.

They contain a property comment:

Code: Select all

  Properties:
    comment: ImageJ=1.52h
images=10
channels=2
frames=5
hyperstack=true
mode=color
loop=false
min=601.0
max=14308.0
I don't know what "channels=2" means.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26086
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Combining multipage Tiffs with "2 dimension"

Post by fmw42 »

Looking at your expected result image in ImageJ, it appears to be a special format for ImageJ. I tried to recreate it in Imagemagick by combining the two input images as the red and green channels with a blue channel set to 0. But ImageJ did not open it the same way as your image. The property, channels=2, means something specific to ImageJ.

246246
Posts: 200
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Combining multipage Tiffs with "2 dimension"

Post by 246246 »

Your images, channels, and frames info is written in ImageDescription tag.
https://www.awaresystems.be/imaging/tif ... ption.html
It is merely an ASCII description. It does not affect image.

Code: Select all

$ for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19; do magick compare  -quiet -metric PSNR "output.tif[$i]"  "output_expected.tif[$i]" NUL; echo; done
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
inf
ImageMagick can only do a copy the tag from one of the input images and set it to the output.

lorach
Posts: 3
Joined: 2020-02-13T05:49:22-07:00
Authentication code: 1152

Re: Combining multipage Tiffs with "2 dimension"

Post by lorach »

fmw42 wrote:
2020-02-13T10:44:37-07:00
You cannot have just 2 channels in Imagemagick. But you can take two images and make then two channels (R or G or B) and make the extra channel black. I do not understand what you have done in ImageJ. Can you tell me what you did and I can then repeat it and then figure out what to do in Imagemagick.

Your two input images look the same or nearly so. The expected output also looks the same. But your comparison has red on one side. That is confusing to me. The two input images and the expected output image are all grayscale (one channel) and 20 pages. So I do not see any differences.
I will give some inputs to you, because I think this is something very specific to my field. "Image1.tif" and "Image2.tif" are pictures taken from a microscope. There we have a camera which acquires grayscale images. This camera then takes for example every minute a picture, additionally there are different filters in front of the camera which allow light of wavelength e.g. 450 nm or 560 nm. All information is then saved in a multipage tiff (e.g. "Image1.tif").

Software to analyze this kind of pictures (imagej and others) show the information about the time point and the wavelength of one slide of the tiff as additional dimensions. So the "ouptut_expected.tiff" has an additional c (for channel) dimension which describes the wavelength (or the "channel" of the microscope) and a t dimension for the timepoint. You can see this in output.jpg on the right in the red circle (c 1/2 t1/10 -> this slide is wavelength 1 from 2 and at timepoint 1 from 2). You can also see the two sliders at the bottom to change either the "channel" or the timepoint. Some images even have a z dimension which is for the slice of 3D images.

I assumed this dimensions "c", "t" and "z" are somehow incoded in the tif format, but as 246246 just said I guess this is not the case and the information about them is in this property comment. So I just have to adjust this comment.

ImageMagick can only do a copy the tag from one of the input images and set it to the output.
I will try this and see if it works.

246246
Posts: 200
Joined: 2015-07-06T07:38:22-07:00
Authentication code: 1151

Re: Combining multipage Tiffs with "2 dimension"

Post by 246246 »

I am afraid that is not enough, because your Image1.tif, Image2.tif and output_expected.tif has tiff tag 50838 and 50839, that is somehow used by ImageJ (as well as 270 (= ImageDescription)), but ignored by libtiff (and also with ImageMagick, I guess). output.tif does not have those tags.

https://imagej.nih.gov/ij/source/ij/io/TiffDecoder.java

So if you could somehow calculate the value and set to ImageDescription tags, still there is a possibility something is missing for ImageJ.

So I think it is a straight approach to use ImageJ API.

Post Reply