how to run tiff images?

3 次查看(过去 30 天)
NAVNISH GOEL
NAVNISH GOEL 2021-7-14
how to run tiff images through matlab. i am getting this error while executing. my image size is more than 500 MB.
Error using rtifc
Maximum variable size allowed by the program is exceeded.
Error in readtif (line 48)
[X, map, details] = rtifc(args);
Error in imread (line 415)
[X, map] = feval(fmt_s.read, filename, extraArgs{:});
Error in tiff (line 1)
x = imread('test_046.tif', 'tif');

回答(1 个)

Vedant Shah
Vedant Shah 2025-6-2
This error message typically arises when MATLAB attempts to load a very large TIFF image entirely into memory, exceeding the allowable size for a single variable. This limit depends on the operating system, MATLAB version, and available system memory. Additional details on maximum allowed variable size can be found in the following MATLAB Central discussion:
To address this issue, we can access the image incrementally rather than loading it in full. MATLAB’s low-level Tiff class provides a suitable approach by enabling tile-by-tile or strip-by-strip reading, thereby conserving memory.
Below is a code snippet demonstrating how to read a TIFF image in strips which works well on a sample 625MB TIFF image:
t = imread('test_046.tif', 'tiff');
% Get image metadata
imageInfo = imfinfo(' test_046.tif');
rowsPerStrip = t.getTag('RowsPerStrip');
imageHeight = imageInfo.Height;
imageWidth = imageInfo.Width;
numChannels = t.getTag('SamplesPerPixel');
% Preallocate full image array
fullImage = zeros(imageHeight, imageWidth, numChannels, 'uint16');
% Read image strip by strip
for row = 1:rowsPerStrip:imageHeight
stripIndex = ceil(row / rowsPerStrip);
strip = t.readEncodedStrip(stripIndex);
numRows = size(strip, 1);
fullImage(row:row+numRows-1, :, :) = strip;
end
t.close();
For more information, refer to the following documentation of “tiff” and “imfinfo” used in the above code snippet:

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by