简体   繁体   中英

Raw CR2 image rotate and save uncompressed to access pixel RGBs

This is a flawed question. I am voting to close or delete it. For my purposes, I should just stay in a raw (or minimal interpolation) format.

I need to first rotate CR2 images a few degrees, and then extract the pixel RGBs from specific locations. This is for science, not aesthetics, so I care very much what the capture values are. The photos were taken with a Cannon EOS 5D (circa 2012). I know how to rotate and work with images with Pillow Image (but not with raw files). I suppose I could transform the pixels myself in memory, but was hoping to not have to do that.

My plan was to first use some raw image processing module (like rawpy ) to read and save out the RGB pixels to some uncompressed format (.tiff?) so they are as close to possible from what was captured, then use Pillow to rotate the image and resave it.

However, whenever I read and save the CR2 images with rawpy , they don't match up even close to how Photoshop is rendering the CR2 images. Nor are either matching the compressed JPG version taken at the same time. The sun's corona for example is different in all three.

Here is a MWE of what I am doing:

import sys
import argparse
import rawpy
from PIL import Image as Img

def main():
    parser = argparse.ArgumentParser(description='', formatter_class=argparse.RawTextHelpFormatter)
    parser.add_help = True
    parser.add_argument('filepath', help='a raw image file')
    args = parser.parse_args()

    raw = rawpy.imread(args.filepath)
    rgb = raw.postprocess(use_auto_wb=True)
    #rgb = raw.postprocess(use_camera_wb=True)
    Img.fromarray(rgb).save(args.filepath + '.tiff')
    raw.close()

if __name__ == '__main__':
    main()

Here is an original CR2 image .
Here is a JPG version captured by same camera at nearly the same time.
Here is rawpy result saving to a .tiff w/ use_auto_wb .
Here is rawpy result saving to a .tiff w/ use_camera_wb .

I think this all has something to do with "exposure compensation" and "white balance", but to be honest, I am no expert with raw images. I have no idea if I'm just doing something silly, or I should be using a different pipeline to accomplish what I am trying to do. I would like the simplest Python pipeline for opening a CR2 and getting the RGB values into an uncompressed format so I can then rotate and extract. But I am now worried about what the values are in the CR2 file and want the most accurate way to extract them. I guess as the comments below suggest, there is no right way because of all the processes involved in rendering the raw images to a positive format.

Python 3.5.2
Pillow 4.3.0
rawpy 0.13.1
numpy 1.14.2
I know there are newer versions of these, but I'm in the middle of a several year project, so would rather not upgrade lest subtle changes are introduced.

It won't fit in a comment but...

When you make a "raw" photo, you basically record all the information, unprocessed and raw off the image sensor with a view to having as much information as possible to permit you to make your interpretation of the image later at a full-size, high-performance computer using sophisticated software like Photoshop or Lightroom. When you record a JPEG, you give up a whole load of information and allow the in-camera chip to make arbitrary decisions about white-balance, about colour-space, about exposure, about clipping and highlight compensation and converting from 12/14 bits to 8-bits. There's not really any correct or accurate version, or correct or accurate RGB information, it's all subjective.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM