Saving image files using fwrite creates huge files
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I'm looking at using fwrite to save the (transformed) matrix components extracted from image files using fwrite but no amount of tweaking gets the resulting file to a manageable size, with size growing linearly (unsurprisingly) as the matrix dimension grows. For example, a 3000 x 4000 pixel PNG (18.4 Mb in size) saved as uint8 using fwrite (opening the file container as Wb) takes up 34.2 Mb in size, raw.
The sequence is the familiar one (XXX the file ID, YYY the data matrix to store)
fid = fopen(XXX,'Wb');
fwrite(fid,YYY,'uint8');
fclose(fid)
Using compression the resulting file shrinks but still requires over 20 Mb. The problem compounds massively if the file read is a MP4. Q is if there is any alternative method/routine to explore?
Thanks.
0 Kommentare
Antworten (2)
Image Analyst
am 7 Aug. 2021
A 12 million pixel image, if it's RGB, will take up 36 million bytes on disk assuming you use fwrite() to write just raw pixel data and no header/meta data. If you use imwrite() to compress it losslessly into a PNG format, it will be less, and 18 MB sounds reasonable. JPG will compress it even more but you'll change the pixel values and it won't look as good when recalled from disk.
If you want an uncompressed video with 12 megapixels and 15-30 frames per second, yes, it's likely the video file will be huge - in the GB or TB range depending on the length of the movie.
You have to ask yourself what size zcreen will people be playing my movie on. If it's a full size HDTV screen at 1920x1080, then there is no sense saving out the full resolution. Your uses will never see the extra resolution. Simply resize the image before adding the frame to the movie.
4 Kommentare
Image Analyst
am 8 Aug. 2021
Again, do you need the full 3000x4000 resolution for your movies? Tell us what kind of monitor people are going to view your movie on. Do they have some kind of 12 megapixel display?
Walter Roberson
am 8 Aug. 2021
is if there is any alternative method/routine to explore?
No, there is not.
Every method that encodes data into less data, in a more-or-less reversible manner, is a compression algorithm.
3000*4000*3 / 1024 / 1024
Any method that represents those 34 megabytes as less data, is a compression algorithm.
You have ruled out using compression algorithms, so you have ruled out representing your 34 megabytes as a smaller size.
2 Kommentare
Walter Roberson
am 8 Aug. 2021
Using compression the resulting file shrinks but still requires over 20 Mb.
You should mentally reframe that.
When you used the compression method that you used the compression gave that result.
However, there are an infinite number of compression methods. Every one-to-one function that maps at least one value to a value that takes less space to represent, is a compression method.
So the particular one you used gave the 20 Mb result, but that does not mean there are not better compression methods available. For example you could use the compression method that PNG does; https://en.wikipedia.org/wiki/Portable_Network_Graphics#Compression
Siehe auch
Kategorien
Mehr zu Image Segmentation and Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!