File tree Expand file tree Collapse file tree
tensorflow_datasets/core/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -177,16 +177,25 @@ def create_thumbnail(
177177 if use_colormap : # Apply the colormap first as it modify the shape/dtype
178178 ex = apply_colormap (ex )
179179
180- _ , _ , c = ex .shape
180+ c = ex .shape [ - 1 ] if ex . ndim == 3 else 1
181181 postprocess = _postprocess_noop
182182 if c == 1 :
183183 ex = ex .squeeze (axis = - 1 )
184- mode = 'L'
184+ if ex .dtype == np .uint16 :
185+ mode = 'I;16'
186+ postprocess = _postprocess_convert_rgb
187+ else :
188+ mode = 'L'
185189 elif ex .dtype == np .uint16 :
186- mode = 'I;16'
190+ # PIL.Image.fromarray doesn't support uint16 for >1 channels.
191+ # https://github.com/python-pillow/Pillow/blob/11.0.0/src/PIL/Image.py#L3225
192+ # Scale to 8-bit for visualization.
193+ ex = (ex / 257 ).astype (np .uint8 )
194+ mode = None
187195 postprocess = _postprocess_convert_rgb
188196 else :
189197 mode = None
198+ postprocess = _postprocess_convert_rgb
190199 img = PIL_Image .fromarray (ex , mode = mode )
191200 img = postprocess (img )
192201 if default_dimensions :
You can’t perform that action at this time.
0 commit comments