Hello everyone, thank you for this nice thing.
While working on openslide, I've come across a bfconvert bug when generating DICOM files.
DICOM has a photometricinterpretation tag to indicate either RGB or YCbCr colorspace in tiles. This (according to the DICOM spec) is the place where the tile colourspace is kept, and NOT in the JPEG tiles themselves. On decode, you need to open each tile, and force the tile colorspace from the DICOM header.
If you use -precompressed, conversion will copy over the JPEG tiles untouched, so if the DICOM header and the tile colorspace were correct beforehand, they will still match in the converted image.
If you convert without the precompressed flag, bfconvert will reencode the JPEGs and may well change the photometric interpretation. For example, SVS is saved as RGB (no chroma subsample), but bfconvert will save as YCbCr (chroma subsample). Now the DICOM photometric interpretation will be RGB, but the tiles will be YCbCr, so users will see crazy colors.
tldr: when saving DICOM, if tiles are being recompressed, bfconvert needs to update the DICOM photometric interpretation tag.
Referring openslide issue: openslide/openslide#558
Referring libdicom issue: ImagingDataCommons/libdicom#80
Hello everyone, thank you for this nice thing.
While working on openslide, I've come across a
bfconvertbug when generating DICOM files.DICOM has a photometricinterpretation tag to indicate either RGB or YCbCr colorspace in tiles. This (according to the DICOM spec) is the place where the tile colourspace is kept, and NOT in the JPEG tiles themselves. On decode, you need to open each tile, and force the tile colorspace from the DICOM header.
If you use
-precompressed, conversion will copy over the JPEG tiles untouched, so if the DICOM header and the tile colorspace were correct beforehand, they will still match in the converted image.If you convert without the
precompressedflag,bfconvertwill reencode the JPEGs and may well change the photometric interpretation. For example, SVS is saved as RGB (no chroma subsample), butbfconvertwill save as YCbCr (chroma subsample). Now the DICOM photometric interpretation will be RGB, but the tiles will be YCbCr, so users will see crazy colors.tldr: when saving DICOM, if tiles are being recompressed,
bfconvertneeds to update the DICOM photometric interpretation tag.Referring openslide issue: openslide/openslide#558
Referring libdicom issue: ImagingDataCommons/libdicom#80