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!