imwrite lossless jpg filesize
12 ビュー (過去 30 日間)
古いコメントを表示
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 件)
Vineet Joshi
2021 年 7 月 19 日
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!