Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identify provides the wrong ResolutionUnit for pyramid Tiff Files #1276

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ocrd_models/ocrd_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def run_identify(self, img):
for prop in ['compression', 'photometric_interpretation']:
setattr(self, prop, img.info[prop] if prop in img.info else None)
if img.filename:
ret = run(['identify', '-format', r'%[resolution.x] %[resolution.y] %U', img.filename], check=False, stderr=PIPE, stdout=PIPE)
ret = run(['identify', '-format', r'%[resolution.x] %[resolution.y] %U ', img.filename], check=False, stderr=PIPE, stdout=PIPE)
else:
with BytesIO() as bio:
img.save(bio, format=img.format)
ret = run(['identify', '-format', r'%[resolution.x] %[resolution.y] %U', '/dev/stdin'], check=False, stderr=PIPE, stdout=PIPE, input=bio.getvalue())
ret = run(['identify', '-format', r'%[resolution.x] %[resolution.y] %U ', '/dev/stdin'], check=False, stderr=PIPE, stdout=PIPE, input=bio.getvalue())
if ret.returncode:
stderr = ret.stderr.decode('utf-8')
if 'no decode delegate for this image format' in stderr:
Expand Down
8 changes: 7 additions & 1 deletion tests/model/test_exif.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
('leptonica_samples/data/OCR-D-IMG/OCR-D-IMG_1555_007.jpg',
944, 1472, 1, 1, 1, 'inches', 'RGB', None),
('kant_aufklaerung_1784-jp2/data/OCR-D-IMG/INPUT_0020.jp2',
1457, 2084, 1, 1, 1, 'inches', 'RGB', None)
1457, 2084, 1, 1, 1, 'inches', 'RGB', None),
# tolerate multi-frame TIFF:
('gutachten/data/IMG/IMG_1.tif',
2088, 2634, 300, 300, 300, 'inches', 'RGB', 'raw'),
# multi-frame TIFF with metric pixel density (is actually YCBCR not RGB but Pillow thinks otherwise...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, Pillow just does not say anything. We could ask ImageMagick about it, though.

(However, %[EXIF:PhotometricInterpretation] does not yield anything... Not sure how to get that info.)

So IMO this test should state YCbCr and fail until we fix OcrdExif.run_identify to include the results from the CLI, or we find a way to make Pillow give us the info.

BTW, using Pillow's TiffTags we can actually get the right value:

# val = img.tag_v2.named()['PhotometricInterpretation']
val = img.tag_v2.get(262)
interpretation = dict((v, k) for k, v in TiffTags.TAGS_V2.get(262).enum.items())
val = interpretation[val]

('indian-ferns/data/OCR-D-IMG/0004.tif',
2626, 3620, 28, 28, 28, 'cm', 'RGB', 'jpeg'),
])
def test_ocrd_exif(path, width, height, xResolution, yResolution, resolution, resolutionUnit, photometricInterpretation, compression):
"""Check EXIF attributes for different input formats
Expand Down
Loading