Converting .tif file into an .ascii file

21 ビュー (過去 30 日間)
Ahmed Abdulla
Ahmed Abdulla 2020 年 6 月 9 日
回答済み: Deepak 2024 年 11 月 5 日 8:09
I have a .tif file that i would like to convert to .ascii . Or a way to be able to convert the .tif file into a numerical matrix where i can convert some values to NaN. I have tried:
Trial 1:
t = Tiff('File_name.tif','r');
imageData = read(t);
imagesc(imageData)
Trial 2:
A = imread('maxlike34_ica_34minerals_step3_2ppd_mostdominant_tiff.tif');
save('myTiff2mat','A');
In both trials when i run a loop to convert any cells that contain a 0 to NaN then none of them change and they all remain as 0, and the .mat files have the dimensions and uint8 which is unlike any data file that i import using .ascii files.
  4 件のコメント
KSSV
KSSV 2020 年 6 月 9 日
Attach your file.
Ahmed Abdulla
Ahmed Abdulla 2020 年 6 月 9 日
sorry im not allowed to do so, thank you for trying to help! i'll keep trying

サインインしてコメントする。

回答 (1 件)

Deepak
Deepak 2024 年 11 月 5 日 8:09
As I understand it, you are attempting to convert a “.tif” image file into a numerical matrix in MATLAB, with the goal of replacing all zero values in matrix with NaN.
To achieve this, we can first read the image using “imread” function in MATLAB to load it into a matrix. Next, we can convert the matrix from its default integer type (uint8) to a floating-point type like “double”, as only floating-point types can represent NaN. Once converted, we can use logical indexing to replace all zero values with NaN. Finally, we can use “dlmwrite” to save the matrix to a text file to convert it to ASCII format.
Here is the MATLAB code to accomplish the same:
imageData = imread('File_name.tif');
% Convert the matrix to double to allow NaN values
imageData = double(imageData);
% Replace zeros with NaN
imageData(imageData == 0) = NaN;
% Save the matrix as an ASCII file
dlmwrite('output_matrix.txt', imageData, 'delimiter', ' ');
save('myTiff2mat.mat', 'imageData');
Please find attached the documentation of functions used for reference:
I hope this helps in resolving the issue.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by