我正在尝试获得'。我的图像分辨率,但我得到不正确的分辨率。但我得到正确的分辨率为'.jpg'的图像
img = Image.open("01109677451NasiLemakBiasa.dng")
width = img.width
height = img.height
print(width, height)
# Output 256 171
图片(01109677451nasilemakbiasa . ng)的实际分辨率为1024 × 683
请帮我得到正确的宽度和高度的图像
PIL
不读取DNG文件,也不像每通道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
Sanple输出
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下载的原始图像样本。