首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当使用python将大型(1.3GB) DNG文件转换为PNG时,图像太大,无法处理

当使用python将大型(1.3GB) DNG文件转换为PNG时,图像太大,无法处理
EN

Stack Overflow用户
提问于 2022-08-24 14:55:06
回答 1查看 124关注 0票数 2

我需要使用python将DNG文件转换为PNG。我在这里找到了一篇关于如何转换DNG:Opencv Python开放dng格式的文章

我试过的密码:

代码语言:javascript
运行
复制
#open dng and convert
import rawpy
import imageio
import os

os.chdir(r'C:\Path\to\dir')
path = r'path\to\file'

with rawpy.imread(path) as raw:
    rgb = raw.postprocess()

rgb_img.save('image.png')

但是,它会产生以下错误:

代码语言:javascript
运行
复制
line 13, in <module>
    rgb = raw.postprocess()
  File "rawpy\_rawpy.pyx", line 887, in rawpy._rawpy.RawPy.postprocess
  File "rawpy\_rawpy.pyx", line 790, in rawpy._rawpy.RawPy.dcraw_process
  File "rawpy\_rawpy.pyx", line 438, in rawpy._rawpy.RawPy.ensure_unpack
  File "rawpy\_rawpy.pyx", line 432, in rawpy._rawpy.RawPy.unpack
  File "rawpy\_rawpy.pyx", line 936, in rawpy._rawpy.RawPy.handle_error
rawpy._rawpy.LibRawTooBigError: b'Image too big for processing'

是否有转换DNG文件的替代方法,或绕过此错误的方法?

来自exiftool的信息:

代码语言:javascript
运行
复制
ExifTool Version Number         : 11.88

File Name                       : DSCF0001.DNG

Directory                       : .

File Size                       : 1313 MB

File Modification Date/Time     : 2022:08:24 12:06:31+01:00

File Access Date/Time           : 2022:08:25 08:17:15+01:00

File Inode Change Date/Time     : 2022:08:24 15:19:04+01:00

File Permissions                : rwxrwxrwx

File Type                       : DNG

File Type Extension             : dng

MIME Type                       : image/x-adobe-dng

Exif Byte Order                 : Little-endian (Intel, II)

Make                            : FUJIFILM

Camera Model Name               : GFX 100

Preview Image Start             : 115208860

Orientation                     : Horizontal (normal)

Rows Per Strip                  : 3000

Preview Image Length            : 3011337

Software                        : FUJIFILM Pixel Shift Combiner 1.2.0.2 (Real Color + High Resolution mode)

Modify Date                     : 2022:08:24 12:06:29

Artist                          : 

Subfile Type                    : Full-resolution image

Image Width                     : 23296

Image Height                    : 17472

Bits Per Sample                 : 16 16 16

Compression                     : JPEG

Photometric Interpretation      : Linear Raw

Samples Per Pixel               : 3

Planar Configuration            : Chunky

Tile Width                      : 128

Tile Length                     : 96

Tile Offsets                    : (Binary data 341026 bytes, use -b option to extract)

Tile Byte Counts                : (Binary data 198743 bytes, use -b option to extract)

Black Level                     : 256 255 256

White Level                     : 65535 65535 65535

Default Scale                   : 1 1

Default Crop Origin             : 16 12

Default Crop Size               : 23264 17448

Anti Alias Strength             : 1

Best Quality Scale              : 1

Opcode List 3                   : WarpRectilinear, FixVignetteRadial

Rating                          : 0

Copyright                       : 

Exposure Time                   : 1/125

F Number                        : 8.0

Exposure Program                : Manual

ISO                             : 100

Sensitivity Type                : Standard Output Sensitivity

Standard Output Sensitivity     : 100

Exif Version                    : 0230

Date/Time Original              : 2019:03:10 00:44:16

Create Date                     : 2019:03:10 00:44:16

Shutter Speed Value             : 1/125

Aperture Value                  : 8.0

Brightness Value                : 8.57

Exposure Compensation           : 0

Max Aperture Value              : 2.0

Metering Mode                   : Multi-segment

Light Source                    : Unknown

Flash                           : No Flash

Focal Length                    : 110.0 mm

Version                         : 0130

Internal Serial Number          : 

Quality                         : NORMAL

White Balance                   : Auto

Saturation                      : 0 (normal)

White Balance Fine Tune         : Red +0, Blue +0

Noise Reduction                 : 0 (normal)

Fuji Flash Mode                 : Manual

Flash Exposure Comp             : 0

Focus Mode                      : Manual

AF Mode                         : No

Focus Pixel                     : 2001 1501

AF-S Priority                   : Release

AF-C Priority                   : Release

Focus Mode 2                    : AF-M

AF Area Mode                    : Single Point

AF Area Point Size              : n/a

AF Area Zone Size               : n/a

AF-C Setting                    : Set 1 (multi-purpose)

AF-C Tracking Sensitivity       : 2

AF-C Speed Tracking Sensitivity : 0

AF-C Zone Area Switching        : Auto

Slow Sync                       : Off

Picture Mode                    : Manual

Exposure Count                  : 1

Shadow Tone                     : 0 (normal)

Highlight Tone                  : 0 (normal)

Lens Modulation Optimizer       : On

Grain Effect                    : Off

Color Chrome Effect             : Off

Crop Mode                       : n/a

Color Chrome FX Blue            : Off

Shutter Type                    : Electronic

Auto Bracketing                 : Unknown (6)

Sequence Number                 : 1

Drive Mode                      : Single

Drive Speed                     : n/a

Blur Warning                    : None

Focus Warning                   : Good

Exposure Warning                : Good

Dynamic Range                   : Standard

Film Mode                       : F0/Standard (Provia)

Dynamic Range Setting           : Manual

Development Dynamic Range       : 100

Min Focal Length                : 110

Max Focal Length                : 110

Max Aperture At Min Focal       : 2

Max Aperture At Max Focal       : 2

Image Stabilization             : Sensor-shift; Off; 0

Image Generation                : Original Image

Image Count                     : 34

Flicker Reduction               : Off (0x0002)

Faces Detected                  : 0

Num Face Elements               : 0

Color Space                     : Uncalibrated

Focal Plane X Resolution        : 5320

Focal Plane Y Resolution        : 5320

Focal Plane Resolution Unit     : cm

File Source                     : Digital Camera

Scene Type                      : Directly photographed

Custom Rendered                 : Normal

Exposure Mode                   : Auto

Focal Length In 35mm Format     : 87 mm

Scene Capture Type              : Standard

Sharpness                       : Unknown (3)

Subject Distance Range          : Unknown (48)

Serial Number                   : 

Lens Info                       : 110mm f/2

Lens Make                       : FUJIFILM

Lens Model                      : GF110mmF2 R LM WR

Lens Serial Number              : 

DNG Version                     : 1.4.0.0

DNG Backward Version            : 1.1.0.0

Unique Camera Model             : FUJIFILM GFX 100

Color Matrix 1                  : 1.7191 -1.1 0.1278 -0.3574 1.1733 0.2076 -0.0002 0.0497 0.654

Color Matrix 2                  : 1.6212 -0.8423 -0.1583 -0.4336 1.2583 0.1937 -0.0195 0.0726 0.6199

Analog Balance                  : 1 1 1

As Shot Neutral                 : 0.5644 1 0.5153

Baseline Exposure               : -0.01

Baseline Noise                  : 1

Baseline Sharpness              : 1.33

Linear Response Limit           : 1

Camera Serial Number            : 

DNG Lens Info                   : 110mm f/2

Shadow Scale                    : 1

DNG Private Data                : (Binary data 114927728 bytes, use -b option to extract)

Calibration Illuminant 1        : Standard Light A

Calibration Illuminant 2        : D65

Aperture                        : 8.0

Image Size                      : 23296x17472

Megapixels                      : 407.0

Preview Image                   : (Binary data 3011337 bytes, use -b option to extract)

Scale Factor To 35 mm Equivalent: 0.8

Shutter Speed                   : 1/125

Circle Of Confusion             : 0.038 mm

Field Of View                   : 23.4 deg

Focal Length                    : 110.0 mm (35 mm equivalent: 87.0 mm)

Hyperfocal Distance             : 39.81 m

Light Value                     : 13.0
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-24 17:53:23

对于内存映像的完全扩展,似乎有一个2GB的限制。我不是指DNG在磁盘上需要的空间,而是指以下数字:

代码语言:javascript
运行
复制
ImageHeight * ImageWidth * NumberOfChannels * BytesPerSample

因此,如果您使用exiftool告诉我们这些参数,点击问题下面的edit并添加来自:

代码语言:javascript
运行
复制
exiftool YOURIMAGE.DNG

此限制在变量imgdata.params.max_raw_memory_mb中强制执行,该变量在底层libraw C代码中设置为2048。我不知道如何通过Python接口设置它。

您可能会成功地将其转换为带有ImageMagick的PNG或TIFF,如下所示:

代码语言:javascript
运行
复制
magick YOURIMAGE.DNG converted.png

如果这样做有效,您可以使用Imagemgaick.绑定的魔棒

您可以尝试使用ufraw,大致如下:

代码语言:javascript
运行
复制
ufraw-batch --out-type=png --out-depth=16 --output=result.png YOURIMAGE.dng
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73475379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档