@@ -20,8 +20,8 @@ def decode_pixel_data(src: bytes, ds: "Dataset", **kwargs) -> "np.ndarray":
2020 ds : pydicom.dataset.Dataset
2121 A :class:`~pydicom.dataset.Dataset` containing the group ``0x0028``
2222 elements corresponding to the image frame.
23- kwargs : dict, optional
24- A dictionary containing options for the decoder. Current options are:
23+ ** kwargs
24+ Current decoding options are:
2525
2626 * ``{'byteorder': str}`` specify the byte ordering for the decoded data
2727 when more than 8 bits per pixel are used, should be '<' for little
@@ -64,17 +64,16 @@ def encode_array(
6464 The dataset corresponding to `arr` with matching values for *Rows*,
6565 *Columns*, *Samples per Pixel* and *Bits Allocated*. Required if
6666 the array properties aren't specified using `kwargs`.
67- kwargs : dict, optional
68- A dictionary containing keyword arguments. Required if `ds` isn't used,
69- keys are:
67+ **kwargs
68+ Required keyword parameters if `ds` isn't used are:
7069
71- * ``{ 'rows': int, 'columns': int} `` the number of rows and columns
72- contained in `arr`.
73- * ``{ samples_per_px': int} `` the number of samples per pixel, either
70+ * ``'rows': int`` the number of rows contained in `src`
71+ * ``'columns': int`` the number of columns contained in `src`
72+ * ``samples_per_px': int`` the number of samples per pixel, either
7473 1 for monochrome or 3 for RGB or similar data.
75- * ``{ 'bits_per_px': int} `` the number of bits needed to contain each
74+ * ``'bits_per_px': int`` the number of bits needed to contain each
7675 pixel, either 8, 16, 32 or 64.
77- * ``{ 'nr_frames': int} `` the number of frames in `arr`, required if
76+ * ``'nr_frames': int`` the number of frames in `arr`, required if
7877 more than one frame is present.
7978
8079 Yields
@@ -91,11 +90,11 @@ def encode_array(
9190 if ds :
9291 kwargs ['rows' ] = ds .Rows
9392 kwargs ['columns' ] = ds .Columns
94- kwargs ['samples_per_px ' ] = ds .SamplesPerPixel
95- kwargs ['bits_per_px ' ] = ds .BitsAllocated
96- kwargs ['nr_frames ' ] = int (getattr (ds , "NumberOfFrames" , 1 ))
93+ kwargs ['samples_per_pixel ' ] = ds .SamplesPerPixel
94+ kwargs ['bits_allocated ' ] = ds .BitsAllocated
95+ kwargs ['number_of_frames ' ] = int (getattr (ds , "NumberOfFrames" , 1 ) or 1 )
9796
98- if kwargs ['nr_frames ' ] > 1 :
97+ if kwargs ['number_of_frames ' ] > 1 :
9998 for frame in arr :
10099 yield encode_pixel_data (frame .tobytes (), ** kwargs )
101100 else :
@@ -127,43 +126,42 @@ def encode_pixel_data(
127126 *Columns*, *Samples per Pixel* and *Bits Allocated*. Required if
128127 the frame properties aren't specified using `kwargs`.
129128 byteorder : str, optional
130- Required if the samples per pixel is greater than 1 and the value is
131- not passed using `kwargs`. If `src` is in little-endian byte order
132- then ``'<'``, otherwise ``'>'`` for big-endian.
133- kwargs : dict
134- A dictionary containing keyword arguments. Required keys are:
135-
136- * ``{ 'rows': int, 'columns': int} `` the number of rows and columns
137- contained in `src`
138- * ``{samples_per_px ': int} `` the number of samples per pixel, either
129+ Required if the samples per pixel is greater than 1. If `src` is in
130+ little-endian byte order then ``'<'``, otherwise ``'>'`` for
131+ big-endian.
132+ ** kwargs
133+ If `ds` is not used then the following are required :
134+
135+ * ``'rows': int`` the number of rows contained in `src`
136+ * ``'columns': int`` the number of columns contained in `src`
137+ * ``samples_per_pixel ': int`` the number of samples per pixel, either
139138 1 for monochrome or 3 for RGB or similar data.
140- * ``{'bits_per_px ': int} `` the number of bits needed to contain each
139+ * ``'bits_allocated ': int`` the number of bits needed to contain each
141140 pixel, either 8, 16, 32 or 64.
142- * ``{'byteorder': str}``, required if the samples per pixel is greater
143- than 1. If `src` is in little-endian byte order then ``'<'``,
144- otherwise ``'>'`` for big-endian.
145141
146142 Returns
147143 -------
148144 bytes
149145 The RLE encoded frame.
150146 """
151147 if ds :
152- r , c = ds .Rows , ds .Columns
148+ r = ds .Rows
149+ c = ds .Columns
153150 bpp = ds .BitsAllocated
154151 spp = ds .SamplesPerPixel
155152 else :
156- r , c = kwargs ['rows' ], kwargs ['columns' ]
157- bpp = kwargs ['bits_per_px' ]
158- spp = kwargs ['samples_per_px' ]
153+ r = kwargs ['rows' ]
154+ c = kwargs ['columns' ]
155+ bpp = kwargs ['bits_allocated' ]
156+ spp = kwargs ['samples_per_pixel' ]
159157
160158 # Validate input
161159 if spp not in [1 , 3 ]:
162- src = "(0028,0002) 'Samples per Pixel'" if ds else "'samples_per_px '"
160+ src = "(0028,0002) 'Samples per Pixel'" if ds else "'samples_per_pixel '"
163161 raise ValueError (src + " must be 1 or 3" )
164162
165163 if bpp not in [8 , 16 , 32 , 64 ]:
166- src = "(0028,0100) 'Bits Allocated'" if ds else "'bits_per_px '"
164+ src = "(0028,0100) 'Bits Allocated'" if ds else "'bits_allocated '"
167165 raise ValueError (src + " must be 8, 16, 32 or 64" )
168166
169167 if bpp / 8 * spp > 15 :
@@ -172,7 +170,8 @@ def encode_pixel_data(
172170 "Standard only allows a maximum of 15 segments"
173171 )
174172
175- if bpp > 8 and byteorder not in ('<' , '>' ):
173+ byteorder = '<' if bpp == 8 else byteorder
174+ if byteorder not in ('<' , '>' ):
176175 raise ValueError (
177176 "A valid 'byteorder' is required when the number of bits per "
178177 "pixel is greater than 8"
@@ -236,8 +235,9 @@ def generate_frames(ds: "Dataset", reshape: bool = True) -> "np.ndarray":
236235 "elements are missing from the dataset: " + ", " .join (missing )
237236 )
238237
239- nr_frames = getattr (ds , "NumberOfFrames" , 1 )
240- r , c = ds .Rows , ds .Columns
238+ nr_frames = int (getattr (ds , "NumberOfFrames" , 1 ) or 1 )
239+ r = ds .Rows
240+ c = ds .Columns
241241 bpp = ds .BitsAllocated
242242
243243 dtype = pixel_dtype (ds )
0 commit comments