I want to compress large tiff file (1.5gb) to atleast 100mb or less to the same file type (tiff). I need to maintain the original resolution and metadata for co-ordinate points. Is there any built-in matlab function that i can use to solve this?

5 views (last 30 days)
does imwrite2tif function help?

Answers (1)

DGM
DGM on 26 Nov 2023
Edited: DGM on 26 Nov 2023
We can't afford to change depth, resolution, or use lossy compression; nor can we discard any extraneous metadata. Given that, the ability to reduce the filesize depends mostly on the image content and whether the original image is already compressed. Since nobody ever knew either of these things, nobody would have known if it were a realistic goal.
Assume you had a very simple synthetic image. I'm going to ignore metadata and assume a simple uint8 single-channel intensity image.
% pick a fixed image geometry
N = round(sqrt(200E6)); % approx 200MB uncompressed
% a simple 8x8 checkerboard pattern
A = im2uint8(checkerboard(round(N/8)));
dumpfilestats(A) % it compresses a lot
bigfilesize = 200.0534
smallfilesize = 0.5363
ratio = 373.0517
% a photograph of the same size
A = imread('cameraman.tif');
A = imresize(A,[N N]);
dumpfilestats(A) % it compresses less
bigfilesize = 199.9969
smallfilesize = 16.1685
ratio = 12.3695
% a random noise image of the same size
A = randi([0 255],N,N,'uint8');
dumpfilestats(A) % it doesn't compress at all
bigfilesize = 199.9969
smallfilesize = 200.0583
ratio = 0.9997
function dumpfilestats(A)
% say you had an uncompressed version
fn1 = 'testbig.tif';
imwrite(A,fn1,'compression','none');
S = dir(fn1);
bigfilesize = S.bytes/1E6
% you could compress the same data
fn2 = 'testsmall.tif';
imwrite(A,fn2,'compression','deflate');
S = dir(fn2);
smallfilesize = S.bytes/1E6
% how much would it compress?
ratio = bigfilesize/smallfilesize
end
Obviously, it the original file is already compressed, that changes what's possible. If it's lossy compressed, then the whole data integrity boat has already sailed.

Community Treasure Hunt

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

Start Hunting!