Mosaicing and Compression
The business of demosaicing is perhaps played up to be more than it is. Whether a raw image file needs to be demosaiced to strip out a Bayer filter, or and X-Trans (6x6) filter is an issue of camera architecture and design.
For example, I have worked on multispectral cameras where there are 5 filters, loosely referred to as IR, near-IR (NIR), R, G, B, and even sometimes UV filters. Some architectures have a separate sensor for each spectral band. This allows other benefits, such as doping for higher quantum efficiency in each band.
A raw image file is a very loose generic term, and perhaps most of us agree that the format is selected by the designer, and my point is that the format can have interwoven RGB, or it could have a frame of R, a frame of G and a frame of B. One could even have two frames of G, which is what Brice had in mind with his so called "Bayer" filter. The filter was a compromise between having square pixels and providing greater spatial information in the band where the HVS had the greatest spatial resolution.
For what it is worth, yes, there IS a difference when the image is rendered with two green photosites on the resulting media. It does appear to have more clarity. I remember looking at jungle vegetation, where there was a distinctive difference between the combined RGB and the RGGB rendered image.
So if one is working with a mosaiced image, it is noteworthy that there are quite a few ways to demosaic the image. The results of each favor applications. For example, RCD, a ratio corrected demosaic method, works better when handling rounded objects. It is used commonly in astrophotography.
Mosaics, as mentioned above, are different. Some Sony cameras, and a few Pentax ones use a pixel shift methodology, where a circular offset shift in introduced into each frame, and then the four resultant frames are save in one raw file. When demosaicing images from these cameras, it os possible to filter the movement out and create clearer images, while reducing the four frames to one image. The Fujifilm cameras using X-Trans can be processed with either a 3 pass or a 1 pass filtering, which yields different sharpness, most notable on low ISO images. While not covering all methodologies here, it is worth noting one more, and that is the variable number of gradients method. Certain lenses, especially wide angle lenses, may result in cross talk between photosites, due to the ray geometry of the light. (This is more frequently seen in mirrorless consumer cameras, with an adapter for a wide angle lens.) There are algorithms for best handling these artifacts, and VNG4 is an example of such an algorithm.
So how does this tie in with compression, one might ask? Quite a bit. There are several places in the image chain where compression might be applied. If one had separate frames for each spectral band, merely replicating compression hardware for each band would be an easy way to speed up compression. Fortunately that is not done anymore. These days, compression takes into account the spatial characteristics of the image, the color gradients in the image, and other factors. The JPEG 2000 standard utilizes wavelet transforms which can be applied against several different factors.
There is all kinds of literature which covers this at various levels of detail. The link provided gives an introduction to wavelet (DWT or discrete wavelet transform) and scratches on the surface of applications. Keep in mind that there are MANY ways to apply compression to an image. It can be in color domains, spatial domains, temporal domains (common for motion imaging), and others.
If you take a look at this link, page through it, and look at the pictures. We're photographers, right? Ignore the math, unless you are a math geek, and then you will like it, and you might find a few mistakes (grin). Do read the words which describe in general attributes, as they are understandable by most system users (photographers).
http://eeweb.poly.edu/~yao/EL6123_s16/Wavelet_J2K.pdfFinally, there are data compression methods and image specific data compression methods. Lossless compression is a no-brainer. It's easy to imagine that any compressor/decompressor which can deterministically get output identical to input can be easily used on images. The real challenge comes when trying to obtain higher compression rates, or output streams which are more tolerant of data errors in rendering. Image specific, perhaps lossy, compression can offer that. Not only that, but the processing cost for decompression is far less when temporal parameters are included, which helps keep streaming video data rates or media size minimized, and reduces complexity of player/renderers.