简体   繁体   English

原始 CR2 图像旋转并保存未压缩以访问像素 RGB

[英]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.我需要先将 CR2 图像旋转几度,然后从特定位置提取像素 RGB。 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).这些照片是用 Cannon EOS 5D(大约 2012 年)拍摄的。 I know how to rotate and work with images with Pillow Image (but not with raw files).我知道如何使用Pillow Image 旋转和处理图像(但不知道如何使用原始文件)。 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.我的计划是首先使用一些原始图像处理模块(如rawpy )读取 RGB 像素并将其保存为某种未压缩格式(.tiff?),以便它们尽可能接近捕获的内容,然后使用Pillow旋转图像并重新保存。

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.但是,每当我使用rawpy读取和保存 CR2 图像时,它们甚至与 Photoshop 渲染 CR2 图像的方式都不匹配。 Nor are either matching the compressed JPG version taken at the same time.也不匹配同时拍摄的压缩 JPG 版本。 The sun's corona for example is different in all three.例如,太阳的日冕在这三者中都是不同的。

Here is a MWE of what I am doing:这是我正在做的事情的 MWE:

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 .这是一个原始的 CR2 图像
Here is a JPG version captured by same camera at nearly the same time.这是同一台相机几乎同时拍摄的JPG 版本
Here is rawpy result saving to a .tiff w/ use_auto_wb .这是保存到 .tiff w/ use_auto_wb原始结果
Here is rawpy result saving to a .tiff w/ use_camera_wb .这是保存到带有use_camera_wb的 .tiff 的原始结果

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.我想要最简单的 Python 管道,用于打开 CR2 并将 RGB 值转换为未压缩格式,以便我可以旋转和提取。 But I am now worried about what the values are in the CR2 file and want the most accurate way to extract them.但我现在担心 CR2 文件中的值是什么,并希望以最准确的方式提取它们。 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蟒蛇 3.5.2
Pillow 4.3.0枕头 4.3.0
rawpy 0.13.1粗糙的 0.13.1
numpy 1.14.2麻木 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.当您制作“原始”照片时,您基本上会记录图像传感器上未处理和原始的所有信息,以便获得尽可能多的信息,以便您稍后以全尺寸对图像进行解释,使用 Photoshop 或 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.当您记录 JPEG 时,您会放弃大量信息,并允许相机内芯片做出关于白平衡、色彩空间、曝光、剪辑和高光补偿以及从 12/14 位转换的任意决定到 8 位。 There's not really any correct or accurate version, or correct or accurate RGB information, it's all subjective.没有任何正确准确的版本,或者正确准确的RGB 信息,这都是主观的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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