gpt4 book ai didi

python-3.x - 使用 Python 查找 '.dng' 图像分辨率

转载 作者:行者123 更新时间:2023-12-05 03:38:54 31 4
gpt4 key购买 nike

我正在尝试获取“.dng”图像分辨率,但我得到的分辨率不正确。但我得到了“.jpg”图像的正确分辨率

img = Image.open("01109677451NasiLemakBiasa.dng")
width = img.width
height = img.height
print(width, height)

# Output 256 171

图像(01109677451NasiLemakBiasa.dng)的实际分辨率为 1024 x 683

请帮我得到正确的图像宽度和高度

最佳答案

PIL 不读取 DNG 文件,也不喜欢每 channel 16 位 RGB。我想你需要像 rawpy 这样的东西

import rawpy

path = '/Users/mark/Desktop/RAW_LEICA_M8.DNG'
with rawpy.imread(path) as raw:
rgb = raw.postprocess()

print(rgb.shape) # It's a Numpy array

样本输出

Out[9]: (2638, 3920, 3)

另一个选项是 Exiftool,您可以像这样安装它:

pip3 install PyExifTool

并像这样使用:

import exiftool

with exiftool.ExifTool() as et:
metadata = et.get_metadata('/path/to/RAW_LEICA_M8.DNG')

print(metadata)

{'SourceFile': '/path/to/RAW_LEICA_M8.DNG',
'ExifTool:ExifToolVersion': 12.0,
'File:FileName': 'RAW_LEICA_M8.DNG',
'File:Directory': '/path/to',
'File:FileSize': 10575296,
'File:FileModifyDate': '2021:08:16 08:54:30+01:00',
'File:FileAccessDate': '2021:08:16 09:56:33+01:00',
'File:FileInodeChangeDate': '2021:08:16 09:56:31+01:00',
'File:FilePermissions': 644,
'File:FileType': 'DNG',
'File:FileTypeExtension': 'DNG',
'File:MIMEType': 'image/x-adobe-dng',
'File:ExifByteOrder': 'II',
'EXIF:Make': 'Leica Camera AG',
'EXIF:Model': 'M8 Digital Camera',
'EXIF:Orientation': 1,
'EXIF:Software': 1.107,
'EXIF:Artist': '',
'EXIF:SubfileType': 0,
'EXIF:ImageWidth': 3920, <--- HERE IS THE WIDTH
'EXIF:ImageHeight': 2638, <--- HERE IS THE HEIGHT
'EXIF:BitsPerSample': 8,
'EXIF:Compression': 1,
'EXIF:PhotometricInterpretation': 32803,
'EXIF:StripOffsets': '(Binary data 1315 bytes, use -b option to extract)',
'EXIF:SamplesPerPixel': 1,
'EXIF:RowsPerStrip': 16,
'EXIF:StripByteCounts': '(Binary data 989 bytes, use -b option to extract)',
'EXIF:XResolution': 300,
'EXIF:YResolution': 300,
'EXIF:PlanarConfiguration': 1,
'EXIF:ResolutionUnit': 2,
'EXIF:CFARepeatPatternDim': '2 2',
'EXIF:CFAPattern2': '0 1 1 2',
'EXIF:LinearizationTable': '(Binary data 1244 bytes, use -b option to extract)',
'EXIF:WhiteLevel': 16383,
'EXIF:DefaultCropOrigin': '2 2',
'EXIF:DefaultCropSize': '3916 2634',
'EXIF:BayerGreenSplit': 500,
'EXIF:AntiAliasStrength': 0,
'EXIF:Copyright': '',
'EXIF:ExposureTime': 12,
'EXIF:ExposureProgram': 1,
'EXIF:ISO': 160,
'EXIF:ExifVersion': '0220',
'EXIF:CreateDate': '2007:08:02 22:13:49',
'EXIF:ShutterSpeedValue': 11.3137084989848,
'EXIF:ExposureCompensation': 0,
'EXIF:MaxApertureValue': 2,
'EXIF:MeteringMode': 2,
'EXIF:LightSource': 0,
'EXIF:Flash': 0,
'EXIF:FocalLength': 50,
'EXIF:FileSource': 3,
'EXIF:SceneType': 1,
'EXIF:WhiteBalance': 0,
'EXIF:DigitalZoomRatio': 0,
'EXIF:FocalLengthIn35mmFormat': 67,
'EXIF:SceneCaptureType': 0,
'EXIF:ImageUniqueID': '00000000000000000000000000000147',
'EXIF:SelfTimerMode': 0,
'EXIF:DateTimeOriginal': '2007:08:02 22:13:49',
'EXIF:FocalPlaneXResolution': 3729,
'EXIF:FocalPlaneYResolution': 3764,
'EXIF:FocalPlaneResolutionUnit': 2,
'EXIF:TIFF-EPStandardID': '0 0 0 1',
'EXIF:DNGVersion': '1 0 0 0',
'EXIF:UniqueCameraModel': 'M8 Digital Camera',
'EXIF:ColorMatrix1': '1.0469 -0.5314 0.128 -0.4326 1.2176 0.2419 -0.0886 0.2473 0.716',
'EXIF:ColorMatrix2': '0.7675 -0.2195 -0.0305 -0.586 1.4118 0.1857 -0.2425 0.4007 0.6578',
'EXIF:CameraCalibration1': '1 0 0 0 1 0 0 0 1',
'EXIF:CameraCalibration2': '1 0 0 0 1 0 0 0 1',
'EXIF:AsShotNeutral': '0.4750637903 1 0.7966159382',
'EXIF:BaselineNoise': 1,
'EXIF:BaselineSharpness': 1,
'EXIF:CameraSerialNumber': 3106091,
'EXIF:CalibrationIlluminant1': 17,
'EXIF:CalibrationIlluminant2': 21,
'MakerNotes:UserProfile': 1,
'MakerNotes:SerialNumber': 3106091,
'MakerNotes:WhiteBalance': 0,
'MakerNotes:LensType': '33 3',
'MakerNotes:ExternalSensorBrightnessValue': -5.16796875,
'MakerNotes:MeasuredLV': -4.359375,
'MakerNotes:ApproximateFNumber': 4,
'MakerNotes:CameraTemperature': 19,
'MakerNotes:ColorTemperature': 5515,
'MakerNotes:UV-IRFilterCorrection': 0,
'MakerNotes:CCDVersion': 0,
'MakerNotes:CCDBoardVersion': 1,
'MakerNotes:ControllerBoardVersion': 0,
'MakerNotes:M16CVersion': 0,
'MakerNotes:ImageIDNumber': 327,
'Composite:CFAPattern': '2 2 0 1 1 2',
'Composite:ImageSize': '3920 2638',
'Composite:LensID': '33 3',
'Composite:Megapixels': 10.34096,
'Composite:ScaleFactor35efl': 1.34,
'Composite:ShutterSpeed': 12,
'Composite:CircleOfConfusion': 0.0224225825588557,
'Composite:FOV': 30.0756572109854,
'Composite:FocalLength35efl': 67}

Raw Samples 下载的示例原始图像.

关于python-3.x - 使用 Python 查找 '.dng' 图像分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68798276/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com