Is it possible to write a double data matrix into TIFF images ( Movie)?

I have a 100X100X19 matrix in the attached Aniso file. Now I want to convert those double data into images ( Movie). Is it at all possible?
FYI: I have used MATLAB "Tiff" function but it supports only the int16 data.

13 commentaires

What exactly is 'MATLAB "Tiff" function'? Please post the code and a copy of the complete error message.
Have you found out the solution to your question?If yes then can you share the code and thank you in advance.
Here I attached the code(a function) which I have found few months ago in Matlab. I used this function in my followinfg code to simulate the one dimensional random walk in terms of a movie (.tiff file extenstion).
clear all; close all; clc;
A=(-0.5:0.02:0.5)';
A = 0.02*randn(length(A),1); A(:,2)=zeros(length(A),1);
x=-27:27; y=-10:10;
for i=1:length(A)
mu=A(i,:);
mu=mu/0.02; sigma=1;
z1=(1/(sigma*sqrt(2*pi)))* exp(-0.5*((x-mu(1))/sigma).^2);
z2=((1/(sigma*sqrt(2*pi)))* exp(-0.5*((y-mu(2))/sigma).^2))';
z(:,:,i)=12.5*z2*z1;
end
imwrite2tif(z,[],['Diffusion.tiff'],'single','Compression',1);
If it is an image then how to modify your code?
What is the format of the image?
please give me the code for both jpg and tif.
j=1143 1142 1134 1132 1119 1101 1104 1099 1085
this are the pixel values present in the matrix j.Now I want it to be converted to an image without the loss of precision.But when I am doing so all the values are changing to 255.
Walter Roberson
Walter Roberson le 23 Nov 2018
Modifié(e) : Walter Roberson le 23 Nov 2018
imwrite(uint16(j),FilenameGoesHere )
Jaladhar Mahato
Jaladhar Mahato le 23 Nov 2018
Modifié(e) : Jaladhar Mahato le 25 Nov 2018
Hi, sb icse
It will be good to discuss rather than adding small points again and again. This confuses the problems. You can first send me an email in Gmail and then we can chat on Google Hangout. There You can state your problem.
I also faced a great problem while handling a tiff file with my desirable precision. While searching this problem in MATLAB I have found that most of the answer doesn't match with our query. It so happens that neither the seeker nor the replier properly understands the problem. Members replied just to get higher in MATLAB rank. I was in this problem for more than a month and was highly frustrated. It is a small trick to preserve your precision as a tiff file format. I felt that MATLAB should implement this code in their library. I have found that tiff file does a great job to save the 3D vector data ( .mat file). People can easily see the pixel values within a tiff file by opening the file in opensource software like ImageJ, Fiji etc. and make out the meaning of their data. I encourage You to install the NIH ImageJ in your PC before our conversation. It's really a nice java platform.
My email id is: jaladhar.27@gmail.com
Wish You a good night
Jaladhar Mahato
"Members replied just to get higher in MATLAB rank."
Sigh. The selfish members just do not care about the problems of the asking persons.
The imwrite2tif code that you attached as the solution is the code I linked to back on January 14 2018, the day after you posted your question.
So far I still find no evidence that any program supports movies stored in TIFF format. ImageJ supports reading TIFF into a "stack" and supports animating a stack, but if you wanted to save that as a video you would need animated GIF or AVI in ImageJ itself, with some other possibilities such as QuickTime being available through plugins -- but not one of the plugins I found supports movies stored in TIFF format.
Jaladhar Mahato
Jaladhar Mahato le 25 Nov 2018
Modifié(e) : Jaladhar Mahato le 25 Nov 2018
Dear Walter Roberson,
You are right that You have provided me the link of that code date back to January 14, 2018. Actually, I was seeking this answer a long time ago and found it, but was not able to use it. After communicating with You I have found the trick to use it and that is why I have recommended your answer. However, I don't think a new user will be able to use this function properly. It is simple but complicated.
FYI: The default file format in ImageJ is Tiff only. We almost daily used ImageJ to read, write and store in a tiff movie file. I can say that ImageJ is made for tiff. The good thing about ImageJ is that You can visualize a single precision 3D data matrix as an image, which Matlab can represent in a complicated way. This helps a broad range of layman (in terms of image analysis) working in different field of microscopy and astronomy (few). However, You can not do any operation on 64-bit images in ImageJ, but you can open in Fiji- an ImageJ based java platform.
Regards
Jaladhar

Connectez-vous pour commenter.

 Réponse acceptée

It is possible to write ieee single (32 bit) to tiff.
It is not possible to write in half precision (16 bit floating point) in any released version of MATLAB; I would need to check to see if that is even supported by the TIFF 6.0 standard. I do not recall support for half precision anywhere in any MATLAB toolbox.
But these matters are not relevant because TIFF has no movie format. If you need to create movies then you need to use a different format.

2 commentaires

Dear Walter Roberson,
We have a data acquisition software where we can collect movie into 16bit Tiff format. We can open those images in a software name as ImageJ (NIH) and can do many image processing operation. But yes, I agree with You, when we do any operation on floating point, we converted the image into a 32-bit image.
Here in MATLAB, although I can do a hell lot of stuff, but I can not save the final result in a double precision Tiff format.
Thanks and Regards
Jaladhar Mahato

Connectez-vous pour commenter.

Plus de réponses (2)

This will work with imwrite.
Data = load('Aniso.mat');
A = Data.A;
imwrite(A(:, :, 1), 'test.tiff');
for k = 2:size(A, 3)
imwrite(A(:, :, k), 'test.tiff', 'WriteMode', 'append');
end

4 commentaires

Yes, I know this function. But the output is 8-bit images( 0 255). All of my data are scaled. I want my output image in 16-bit or 32-bit format.
Thanks for your help.
Jaladhar
And as far as I understand your comment, you have used something like:
t = Tiff('myfile.tif', 'w');
t.write(A(:, :, k))
and this works for 16 bit data, but you want it for 32 bit data also? Sorry, I still so not get the problem.
My question was converting a double data matrix into TIFF format, whereas "Tiff" only work with int16, int32 unit16, unit32.
"imwrite" and "Tiff", convert my data into integer whereas my data have decimal values. I want exact input values in the output images (Movie). Hope You got my point.
You can convert the decimal values to uint16 by:
data = rand(640, 480);
dataU16 = im2uint16(data);
This can be written for uint32 also:
dataU32 = data * intmax('uint32');
Of course you loos some precision, but TIFF files are not designed to store double data. As you see in Walter's answer, at least single would work.

Connectez-vous pour commenter.

I hope this can help some of you. I am not sure if this is answering your question though, but you can save your double as a .mat file, then load it, then extract it from the resulting structure as follows:
cd(folder_name)
save('file_name.mat','var_name');
X = load('file_name.mat');
Since you end up with a structure, you need to extract the data as follows:
Y = X.var_name; % voila. You have your double back.
You can check you end up with the exact same with the command
Z=mean(Y-var_name,'all'); % and you can verify that Z=0.

1 commentaire

I do not see how this would have helped? The original poster already had their data as a .mat file.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Import and Analysis dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by