imwrite lossless jpg filesize

22 vues (au cours des 30 derniers jours)
Nick
Nick le 12 Juil 2021
Hello,
I am reading, cropping, and writing bulk DSLR jpg images in Matlab using imread, imcrop, and imwrite in a loop but have two questions:
-I want to retain the original pixel value information so I am using lossless mode during writing but I noticed that the resultant file size is ~6x the original image size even though the image is cropped to ~half the total original pixel count. Similarly, lossy export with 100% quality and half the number of pixels is ~2x the original image size. I can understand how saving subsequent lossy jpg files can compress information AND file size but it doesn't appear to be working this way. Maybe the compression/file writing scheme of Matlab and the original file differ? If so, maybe there is a file exchange that would allow for this scheme to be detected and remain consistent through repeated file exports?
-I am trying to speed up the batch export process using the 3 simple looped commands that are stated above. I think that if I can reduce the resultant lossless file size from my first point then I will speed up the biggest bottleneck which is writing the increased file size to desk. But maybe you have a more clever way to open and save a larger amount of images (~20k)? I do see other open-source software available for bulk image resizing but not necessarily bulk image cropping.
Thanks,
Nick
  1 commentaire
Walter Roberson
Walter Roberson le 12 Juil 2021
vlc is able to do bulk cropping; see https://wiki.videolan.org/VLC_HowTo/Crop/

Connectez-vous pour commenter.

Réponses (1)

Vineet Joshi
Vineet Joshi le 19 Juil 2021
Hi
Yes you are correct. When you read an image using imread, the function returns an array of size H * W * 3 and while writing using imwrite the compression scheme and parameters changes. You can control these by looking at some hyperparameters like 'Quality','Mode','CompressionRatio' etc.
Just to test, I ran the following code and got the output image size reduced by ~95% from 88Kb to 4Kb.
imwrite(Image,'NewFlower.jpg',"Mode","lossy","Quality",0)
Moreover, since you have to perform operations on ~20K images and each iteration is independent of the previous, you can run them in parallel using the parfor and similar methods.
Hope this was of help.
Thanks

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by