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)
Show older comments
does imwrite2tif function help?
0 Comments
Answers (1)
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
% a photograph of the same size
A = imread('cameraman.tif');
A = imresize(A,[N N]);
dumpfilestats(A) % it compresses less
% a random noise image of the same size
A = randi([0 255],N,N,'uint8');
dumpfilestats(A) % it doesn't compress at all
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.
0 Comments
See Also
Categories
Find more on Image Data in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!