TIFF plot generation and compression: R vs. GIMP vs. IrfanView vs. Photoshop file sizes
Apparently the TIFF LZW compressor used by R is not making use of an important option (the TIFF predictor) which is leading to an extremely large file. Data compression works best when it can recognize symmetries/redundancies in the data. In this case, the image data is composed of 24-bit (3-byte) pixels containing red, green and blue 8-bit values. Standard LZW compression looks at a stream of bytes for repeating patterns. If it looks at the color image simply as a stream of bytes, it will see repeating patterns of 3-bytes instead of repeating patterns of constant color. Enabling the TIFF predictor on the data causes a differencing filter to store the delta of each pixel with its neighbor. If the neighboring pixels are the same color, it will store 0's. A long string of 0's compresses much better than repeating patterns of non-zeros which are at least 3 bytes long.
Here is an example of how it works on a 6 pixel line. When encoding, the predictor starts from the right edge and works left for each scan line:
Original data:
2A 50 40 2A 50 40 2A 50 40 2A 50 40 2A 50 40 2A 50 40 (6 pixels of the same color)
After horizontal differencing (TIFF predictor):
2A 50 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
The data is much more compressible after the predictor since long runs of the same value (0x00) are easier for LZW to compress.
Conclusion: This should be filed as a bug against the owner of the R compression code since using LZW on full color images without the predictor produces poor results. In the mean time, a workaround is needed to compress it more efficiently.
What is the difference between .psd (photoshop) and .xcf (gimp) file types?
XCF supports saving each layer, the current selection, channels, transparency, paths and guides. However, unlike the native file format for Adobe Photoshop, PSD, the undo history is not saved in an XCF file.
The .PSD (Photoshop Document), Photoshop's native format, stores an image with support for most imaging options available in Photoshop. These include layers with masks, color spaces, ICC profiles, transparency, text, alpha channels and spot colors, clipping paths, and duotone settings
Related Topics
Force Ggplot to Evaluate Counter Variable
Passing Ellipsis Arguments to Map Function Purrr Package, R
Applying Function (Ks.Test) Between Two Data Frames Column-Wise in R
Customise The Infowindow/Tooltip in R -> Plotly
Axis-Labeling in R Histogram and Density Plots; Multiple Overlays of Density Plots
How Could I Find The Growth Rate of Gdp
Is There a General Inverse of The Table() Function
Standard Error of Variance Component from The Output of Lmer
How to Plot Contours on a Map with Ggplot2 When Data Is on an Irregular Grid
Rselenium on Docker: Where Are Files Downloaded
R:Binary Matrix for All Possible Unique Results
Creating a Stacked Bar Chart Centered on Zero Using Ggplot
Ggplot2 Equivalent of 'Factorization or Categorization' in Googlevis in R
How to Round Percentage to 2 Decimal Places in Ggplot2