Skip to content

Commit

Permalink
Correctly account for Cr and Cb subsampling when calculating number o…
Browse files Browse the repository at this point in the history
…f pixels
  • Loading branch information
CPBridge committed Jul 13, 2023
1 parent b19cea2 commit 95e6b31
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/highdicom/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,12 @@ def _bytes_per_frame_uncompressed(self) -> int:
# are packed into 12.5 -> 13 bytes
return n_pixels // 8 + (n_pixels % 8 > 0)
else:
if self.metadata.PhotometricInterpretation == 'YBR_FULL_422':
# Account for subsampling of CB and CR when calculating
# expected number of samples
# See https://dicom.nema.org/medical/dicom/current/output/chtml
# /part03/sect_C.7.6.3.html#sect_C.7.6.3.1.2
n_pixels = self.metadata.Rows * self.metadata.Columns * 2
return n_pixels * bits_allocated // 8

def close(self) -> None:
Expand Down

0 comments on commit 95e6b31

Please sign in to comment.