[疑难杂症2024-003]如何判断一张没有头信息的dcm图像,是否是压缩图像?

发布于:2024-04-19 ⋅ 阅读:(34) ⋅ 点赞:(0)

本文由Markdown语法编辑器编辑完成.

1. 前言:

DCM格式,是医学图像领域里面的通用格式.DCM图像一般分为两大部分,一部分是TAG信息,一部分是像素.

而TAG信息,一般又会分为两部分,如下图所示, 是用dcmtk下面的dcmdump指令,来读图任意一张正常的dcm图像后,展示的tag信息.
可以看到,主要分为两部分:
Dicom-Meta-Information-Header和DICOM-Data-Set.
在这里插入图片描述
DICOM-Meta-Information-Header, 是dicom头,一般是0002开头的Element.
这里面, TransferSyntaxUID, 是用来标识这个图像的传输方式.

以下是对Transfer Syntax UID的一个说明:

来源于: https://www.dicomlibrary.com/dicom/transfer-syntax/Transfer Syntax
A Transfer Syntax is a set of encoding rules able to unambiguously represent one or more Abstract Syntaxes. 
In particular, it allows communicating Application Entities to negotiate common encoding techniques they both support (e.g., byte ordering, compression, etc.).
A Transfer Syntax is an attribute of a Presentation Context, one or more of which are negotiated at the establishment of an Association between DICOM Application Entities.

这里面提到了,它用来标识图像的字节排序,压缩算法,等等。

今天要提到的这个解决方案,就是跟dicom的Trasnfer Syntax UID取值相关的。

从以上的定义,我们可以知道,如果想知道,一张dcm图像,到底是不是压缩图像,我们可以很方便地根据这个tag来识别。
以下是我分别读取一张标准的(非压缩图),和压缩图,读取图像后的区别。

# 读取正常图像
import pydicom
file_1 = "/path/to/normal"
ds1 = pydicom.read_file(file_1)
print(ds1.file_meta.TransferSyntaxUID.is_compressed)

file_2 = "/path/to/compress"
ds2 = pydicom.read_file(file2)
print(ds2.file_meta.TransferSyntaxUID.is_compressed)

但是,今天遇到的问题,却是,这个图像没有头信息,所以使用pydicom读取后,没有file_meta, 当然也就没有TransferSyntaxUID. 由于后续的服务,只能在原图上面进行。

因此,我需要做的事情就是,在没有file_meta的情况下,依然能够根据图像是否是压缩图像来解压。

2. 解决方案

经过一系列的调研,dicom的TAG中,还是会有一些,可以帮助我们来推算出图像的压缩类型。
以下列举这些有用的dicom, 以及计算方法:

DICOM TAG 含义 取值
BitsAllocated
Rows
Columns
SamplePerPixel
FrameOf

未完待续…