TIFF different than BMP in image compression

3 views (last 30 days)
hello every one ,
i use lena.tiff color image and gray image and i compressed it.
what is the different if i use lena.bmp, which one is better quality and better compression ? is there any different?
thanks for all

Answers (2)

DGM
DGM on 25 Aug 2021
Edited: DGM on 25 Aug 2021
I'm assuming you're asking about picking a format when writing an image file. The answer depends, but generally, TIFF would be the better choice.
Both are potentially lossless, so they're both capable of the same quality. TIFF can utilize different compression depending on the options, some of which are lossy. The default should be lossless, though.
As far as which offers better compression, that'd be TIFF, since imwrite can only write uncompressed BMP.
TIFF also offers a lot of other capabilities which BMP does not. That may or may not matter for your usage.
That said, PNG is also a lossless compressed format and is widely supported.
If you're unsure which to use, or which settings to use, you can always write some sample images. Observe the relative file sizes, and read them back to verify that the conversion was indeed lossless.
  6 Comments
DGM
DGM on 28 Aug 2021
Edited: DGM on 28 Aug 2021
If you're reading in two different images and then writing them again, then I can't generally make any claim which will be smaller. From my perspective, I cannot know if the two images you have are the same. If they are the same, then the source format is irrelevant. If they're not the same, then the result will differ depending on how the sources differ and to what degree.

Sign in to comment.


Walter Roberson
Walter Roberson on 28 Aug 2021
i read image in "lena.TIFF" then after compressed with DCT transform i write it lena.jpeg because the DCT deal with JPEG
No, that is not correct reasoning.
When you use imwrite() and ask for jpeg and do not ask for Lossless, then whatever data you ask to write will be put through jpeg lossy compression. Unless you used the exact sample computation as imwrite() does, including details about the rounding strategies (an important but often overlooked detail for jpeg), then whatever you carefully arranged in your array will be changed as it is written as jpeg.
Using imwrite() to a jpeg file is not the right way to do DCT compression and write out the calculated coefficients as a JPEG file!! You cannot do, for example,
im = imread('flamingos.jpg');
for K = 1 : 3
B{K} = dct2(im(:,:,K));
end
BB = uint8(cat(3,B{:}));
imwrite(BB, 'dct.jpg');
and expect the result to be the JPEG version of the original image!
In order to use imwrite(), you have to have reconstructed the image, like
im = imread('flamingos.jpg');
for K = 1 : 3
B{K} = do_my_dct_compression(im(:,:,K));
end
for K = 1 : 3
C{K} = do_my_dct_reconstruction(B{K});
end
CC = uint8(cat(3,C{:}));
imwrite(CC, 'dct_reconstruction.jpg');
but at that point, CC is the reconstructed image, which "ideally" would be identical to the original image, but instead has probably discarded some details.
imwrite() has no knowledge that CC has already gone through DCT deconstruction and reconstruction, and will treat CC just like any other array, and will process it through its own compression routines.
The only time you can "win" with doing your own compression and reconstruction is if your compression + reconstruction code discards details in a way that is compatible with the compression that will be done by imwrite, except that your compression has to have been "better" at it. For example, if you discarded more DCT components than imwrite() would do, and you happen to align your blocks exactly the same way that imwrite() would, then imwrite() might find more discardable zeros than it would have found for the original image unchanged. It would not be the case that you were writing the compression components that you had calculated: imwrite() would still write the compression components that it calculated, but you would have carefully calculated those in a way that would "prime" imwrite() to be able to do a better job than it would normally do on the original image.
If you want to write out your own compression components, if you are trying to compress the image "yourself", then you need to know the details of the image format, and you would need to write a complete binary file that happened to match the standards for the kind of image you are trying to imitate. Sometimes though, you can find third-party libraries similar to libjpeg that are willing to accept raw DCT components and write them out in a proper container -- but in such a case you have to be sure that the raw DCT components you are sending are compatible with the ones that would normally be written.
  2 Comments
eng m
eng m on 30 Aug 2021
thanks for explain
i read the image in TIFF but in reconstructed image i write it in jpeg (the original image and reconstructed ) to know compressd size.
i want to know if i read the image in anthor format what happened in size ,which one better
Walter Roberson
Walter Roberson on 31 Aug 2021
That doesn't work, not at all.
Suppose you had a world-champion suitcase packer, able to pack a drawer of clothes into a smaller suitcase than anyone else can. Except, for competition purposes, "suitcase" is a cardboard box rather than a commercial suitcase with handles and locks and wheels and so on -- more the "idea" of a suitcase than something you can take on an airplane.
So, you watch as the champion suitcase packer carefully puts the clothes into the very small suitcase, using vacuum bagging as part of the technique to get clothes very small. And then when you want to measure how well the champion did, imagine that instead of measuring the size of the competition-style suitcase, you had the champion take all the clothes out of competition suitcase and out of the vacuum bags, and put the clothes into a commercial suitcase, except this time without being allowed to use vacuum bags. And then you measure the size of the commercial suitcase (the one where vacuum bags were not permitted), and say that that is how well the champion packer did on their competition suitcase when they used vacuum bags.
You are measuring two different things. If you want to know how well your DCT compression did in memory, then you need to look at amount of memory that would be required to store everything needed to reconstruct from your DCT compression. You would not expand your DCT compressed version back to an array and then ask how well JPEG can compress the reconstructed version.

Sign in to comment.

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!