.tif files not loading in correctly

Hi, I am loading in .tif files for my code, but the problem is when loading it in the values are changing. i.e. for my images they are 1024x1024 .tif files, and when looking at the pixel info using ImageJ, at (686,674) the value is 1.0759. Loading the image into matlab using the fitsread function and looking at (686,674) gives me 1.11037. Has anyone else experience this issue, I am using this image values to calculate temperature arrays, and as a result my arrays are usually 5-8 Kelvin less than expected, I am not sure why when loading in it is doing this. The file classes are uint16 and I have been converting them to doubles without issue. Here is my code
[images, pathname] = uigetfile( ...
{'*.tif', 'All .tif Files (*.tif)'; ...
'*.*','All Files (*.*)'},...
'Select Wind on file to Load');
handles.Calibration_ratio = importTSP_image(images, pathname);
Calibration_ratio = double(handles.Calibration_ratio.('Run9_cam4_ratio'));
function imgdata = importTSP_image(fileToRead1,pathname)
%IMPORTFILE(FILETOREAD1)
% Imports data from the specified file
% FILETOREAD1: file to read
fileToRead1 = fullfile(pathname,fileToRead1);
% Import the file
rawData1 = importdata(fileToRead1);
[~,name] = fileparts(fileToRead1);
newData1.(matlab.lang.makeValidName(name)) = rawData1;
% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
assignin('base', vars{i}, newData1.(vars{i}));
end
imgdata = newData1;
end

8 Comments

@Dean: please uplpad a sample data file by clicking the paperclip button. And show us the exact code you are using to import that data into MATLAB.
I can not upload a sample data file, but I uploaded the code I use to import
To upload a TIFF file, you'd have to zip it to work around the limitations of the editor. If you're saying you can't upload it for reasons of confidentiality, then that's an obstacle.
Can't upload it for both
Image Analyst
Image Analyst on 21 Jul 2023
Edited: Image Analyst on 21 Jul 2023
Why not? Are they bigger than 5 MB?
Are the values floating point rather than uint8 or uint16 integers?
DGM
DGM on 21 Jul 2023
Edited: DGM on 21 Jul 2023
Is it possible to at least upload any non-identifying information contained in the metadata (e.g. the output from imfinfo(filename) ? TIFF is one of the most flexible image formats, so it's possible that subtle differences could be caused by misinterpreting the file. I'm not familiar with all the edge cases and specialized uses, so I can't really intuit an explanation for the discrepancy without seeing more clues.
So they are floating point TIFs: here is the imfinfo data, the files are below 5 MB
FileModDate: '20-Jul-2023 15:06:46'
FileSize: 4196028
Format: 'tif'
FormatVersion: []
Width: 1024
Height: 1024
BitDepth: 32
ColorType: 'grayscale'
FormatSignature: [77 77 0 42]
ByteOrder: 'big-endian'
NewSubFileType: 0
BitsPerSample: 32
Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
StripOffsets: 1724
SamplesPerPixel: 1
RowsPerStrip: 1024
StripByteCounts: 4194304
XResolution: []
YResolution: []
ResolutionUnit: 'Inch'
Colormap: []
PlanarConfiguration: 'Chunky'
TileWidth: []
TileLength: []
TileOffsets: []
TileByteCounts: []
Orientation: 1
FillOrder: 1
GrayResponseUnit: 0.0100
MaxSampleValue: 4.2950e+09
MinSampleValue: 0
Thresholding: 1
Offset: 8
ImageDescription: 'ImageJ=1.54f↵min=1.2345000173693373E-21↵max=1.9735080003738403↵'
SampleFormat: 'IEEE floating point'
UnknownTags: [2×1 struct]
50838 246 [12,1458]
50839 254 1x1470 double
Basically the pixel values from the original compared to the array that matlab creates when loading are completely different, but I am not sure how, it seems like the image is shifting or some values are being replaced when loading

Sign in to comment.

Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2023a

Asked:

on 20 Jul 2023

Commented:

on 21 Jul 2023

Community Treasure Hunt

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

Start Hunting!