DICOM icc profile comparation and verify via GIMP

Posted on Fri, Aug 19, 2022 DICOM

簡介

紀錄一下以前 Raccoon 新增 ICC Profiles 功能時所遇到的坑。

因 Raccoon 是使用 Node.js 編寫的,所以當時找了處理影像的套件 sharp 套用 ICC Profile,結果發現套用後,與其他 PACS 的顏色不同,並且還發生了一點小插曲!?

以下將使用一些工具展示套用 ICC Profile 的結果。

方法

使用影像內建的 ICC Profile 測試
image.raw.icc1769.0KB
使用第 78 張 Frame
ExifTool Version Number         : 12.44
File Name                       : 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.jpg
Directory                       : I:/Blog/icc-profile/code
File Size                       : 207 kB
File Modification Date/Time     : 2022:08:18 22:40:14+08:00
File Access Date/Time           : 2022:08:19 12:42:51+08:00
File Creation Date/Time         : 2022:08:18 22:42:09+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.02
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Image Width                     : 1024
Image Height                    : 1024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1024x1024
Megapixels                      : 1.0

GIMP 套用 ICC Profile

步驟

結果

GIMP apply ICC Profile
ExifTool Version Number         : 12.44
File Name                       : 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6-GIMP.jpg
Directory                       : I:/Blog/icc-profile/code
File Size                       : 2.0 MB
File Modification Date/Time     : 2022:08:19 13:41:10+08:00
File Access Date/Time           : 2022:08:19 14:06:18+08:00
File Creation Date/Time         : 2022:08:19 13:41:10+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Exif Byte Order                 : Little-endian (Intel, II)
Orientation                     : Horizontal (normal)
X Resolution                    : 300
Y Resolution                    : 300
Resolution Unit                 : inches
Software                        : GIMP 2.10.32
Modify Date                     : 2022:08:19 13:40:30
Subfile Type                    : Reduced-resolution image
Compression                     : JPEG (old-style)
Photometric Interpretation      : YCbCr
Samples Per Pixel               : 3
Thumbnail Offset                : 286
Thumbnail Length                : 19933
XMP Toolkit                     : XMP Core 4.4.0-Exiv2
Document ID                     : gimp:docid:gimp:b2934add-b705-4ffb-acb0-a0d04170b392
Instance ID                     : xmp.iid:b075a0e2-1e02-4764-b587-e2e32511818a
Original Document ID            : xmp.did:211c4e7e-908a-4479-b011-7931fb1faa0a
Format                          : image/jpeg
Api                             : 2.0
Platform                        : Windows
Time Stamp                      : 1660887670731023
Version                         : 2.10.32
Creator Tool                    : GIMP 2.10
Metadata Date                   : 2022:08:19T13:40:30+08:00
History Action                  : saved
History Changed                 : /
History Instance ID             : xmp.iid:45d5e005-74f1-4e23-8db1-9fe8c733a00a
History Software Agent          : Gimp 2.10 (Windows)
History When                    : 2022:08:19 13:41:10
Profile CMM Type                : Adobe Systems Inc.
Profile Version                 : 4.3.0
Profile Class                   : Input Device Profile
Color Space Data                : RGB
Profile Connection Space        : Lab
Profile Date Time               : 2017:11:08 10:54:51
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Unknown (    )
Device Model                    : 
Device Attributes               : Transparency, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Unknown (    )
Profile ID                      : eb312bfb398ba400bbab5bb1b050428b
Profile Description (en-GB)     : DP 200 : 1234567890 : 0987654321 : 1
Profile Copyright (en-GB)       : FFEI Ltd
Media White Point               : 0.9642 1 0.82489
Chromatic Adaptation            : 1.00003 2e-005 -5e-005 2e-005 1 -2e-005 -2e-005 2e-005 0.99971
A To B0                         : (Binary data 1811028 bytes, use -b option to extract)
Image Width                     : 1024
Image Height                    : 1024
Encoding Process                : Progressive DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1024x1024
Megapixels                      : 1.0
Thumbnail Image                 : (Binary data 19933 bytes, use -b option to extract)

dcm4che dcm2jpg 套用 ICC Profile

指令

dcm2jpg input.dcm --iccprofile yes --frame 78 output.jpg

結果

ExifTool Version Number         : 12.44
File Name                       : 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.-dcm4che.jpg
Directory                       : I:/Blog/icc-profile/code
File Size                       : 2.0 MB
File Modification Date/Time     : 2022:08:19 14:06:09+08:00
File Access Date/Time           : 2022:08:19 14:09:59+08:00
File Creation Date/Time         : 2022:08:19 14:08:58+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.02
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Profile CMM Type                : Little CMS
Profile Version                 : 4.3.0
Profile Class                   : Input Device Profile
Color Space Data                : RGB
Profile Connection Space        : Lab
Profile Date Time               : 2017:11:08 10:54:51
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Unknown (    )
Device Model                    : 
Device Attributes               : Transparency, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Little CMS
Profile ID                      : eb312bfb398ba400bbab5bb1b050428b
Profile Description (en-GB)     : DP 200 : 1234567890 : 0987654321 : 1
Profile Copyright (en-GB)       : FFEI Ltd
Media White Point               : 0.9642 1 0.82489
Chromatic Adaptation            : 1.00003 2e-005 -5e-005 2e-005 1 -2e-005 -2e-005 2e-005 0.99971
A To B0                         : (Binary data 1811028 bytes, use -b option to extract)
Image Width                     : 1024
Image Height                    : 1024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1024x1024
Megapixels                      : 1.0

nodejs sharp 套用 ICC Profile

🚫

這邊只是稍微紀錄,sharp 在套用影像內建的 ICC Profile 時跳出 Error: icc_transform: no output profile 的錯誤

使用的程式碼

const sharp = require("sharp");

(async() => {
    await sharp("2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.jpg")
          .toColorspace("srgb")
          .withMetadata({
            icc: "./sRGB.icc"
          })
          .toFile("2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6-sharp.jpg")
})();

結果

node.js sharp apply ICC profile
ExifTool Version Number         : 12.44
File Name                       : 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6-sharp.jpg
Directory                       : I:/Blog/icc-profile/code
File Size                       : 222 kB
File Modification Date/Time     : 2022:08:18 22:44:48+08:00
File Access Date/Time           : 2022:08:19 13:27:54+08:00
File Creation Date/Time         : 2022:08:18 22:44:48+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Exif Version                    : 0210
Components Configuration        : Y, Cb, Cr, -
Flashpix Version                : 0100
Color Space                     : Uncalibrated
Exif Image Width                : 1024
Exif Image Height               : 1024
Profile CMM Type                : Little CMS
Profile Version                 : 2.3.0
Profile Class                   : Input Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2006:12:28 18:07:22
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Little CMS
Device Model                    : 
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Little CMS
Profile ID                      : 0
Device Mfg Desc                 : (lcms internal)
Profile Description             : sRGB built-in
Device Model Desc               : sRGB built-in
Media White Point               : 0.95015 1 1.08826
Red Matrix Column               : 0.43585 0.22238 0.01392
Blue Matrix Column              : 0.14302 0.06059 0.71384
Green Matrix Column             : 0.38533 0.71704 0.09714
Red Tone Reproduction Curve     : (Binary data 2060 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 2060 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 2060 bytes, use -b option to extract)
Chromaticity Channels           : 3
Chromaticity Colorant           : Unknown (0)
Chromaticity Channel 1          : 0.64 0.33
Chromaticity Channel 2          : 0.3 0.60001
Chromaticity Channel 3          : 0.14999 0.06
Image Width                     : 1024
Image Height                    : 1024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1024x1024
Megapixels                      : 1.0
可以發現比原本的內容多了一些

imagemagick 套用 ICC Profile

指令

magick input.jpg -profile "image.raw.icc" output.jpg 

結果

ExifTool Version Number         : 12.44
File Name                       : 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6-magick.jpg
Directory                       : I:/Blog/icc-profile/code
File Size                       : 2.0 MB
File Modification Date/Time     : 2022:08:19 13:34:37+08:00
File Access Date/Time           : 2022:08:19 13:36:17+08:00
File Creation Date/Time         : 2022:08:19 13:06:23+08:00
File Permissions                : -rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1
Profile CMM Type                : Adobe Systems Inc.
Profile Version                 : 4.3.0
Profile Class                   : Input Device Profile
Color Space Data                : RGB
Profile Connection Space        : Lab
Profile Date Time               : 2017:11:08 10:54:51
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Unknown (    )
Device Model                    : 
Device Attributes               : Transparency, Glossy, Positive, Color
Rendering Intent                : Media-Relative Colorimetric
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Unknown (    )
Profile ID                      : eb312bfb398ba400bbab5bb1b050428b
Profile Description (en-GB)     : DP 200 : 1234567890 : 0987654321 : 1
Profile Copyright (en-GB)       : FFEI Ltd
Media White Point               : 0.9642 1 0.82489
Chromatic Adaptation            : 1.00003 2e-005 -5e-005 2e-005 1 -2e-005 -2e-005 2e-005 0.99971
A To B0                         : (Binary data 1811028 bytes, use -b option to extract)
Image Width                     : 1024
Image Height                    : 1024
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1024x1024
Megapixels                      : 1.0

小記錄

dcm4che 預設轉圖顏色不一致

如果您使用了以下預設的指令將圖轉出來

dcm2jpg 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.dcm ^
2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.jpg ^
--frame 78

您會發現,轉出來的圖與 weasis 顯示的圖,顏色明顯不同

The DICOM view from weasis
The image convert by command above

此時加入 ICC Profile: No 就會與使用 weasis 觀看到的影像顏色相同

dcm2jpg 2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.dcm ^
2.16.840.1.113995.3.110.3.0.10118.2000002.862753.6.jpg ^
--frame 78 --icc-profile no

這是因為 dcm4che 預設會將原本的影像轉換成 sRGB,並且會自動把 YBR 的影像也都轉換成 RGB,所以在套用 sRGB 時,影像未與其他工具套用 sRGB 的結果不同,是否該預設轉 RGB,目前筆者沒有答案

By default, include no ICC profile, but
transform original pixels to sRGB color
space if an ICC Profile is specified in the
DICOM image.