当前位置:网站首页>Analysis of the tag in DCMTK learning notes 1

Analysis of the tag in DCMTK learning notes 1

2021-06-23 21:32:51 kevinlq

It is necessary to read this article 3.3 minute

We're going to parse and display a dcm Images , First, you have to parse part of the label information .

There are three main types of tag information :

  • Meta info
  • Ordinary tag
  • Pixels tag

Read as needed

Use DCMKT Read dicom Labeling is an easy thing

meata info tag Read

meta The information in 0002 Group

There are three ways to read , Here's the simplest one

    DcmMetaInfo metainfo;
    OFCondition status;
    status = metainfo.loadFile("G:/dicomFile/3.dcm");

    if (status.good())
    {
        OFString sopClassUID, xferUID;
        if (metainfo.findAndGetOFString(DCM_MediaStorageSOPClassUID, sopClassUID).good())
            COUT << "SOP Class UID: " << sopClassUID << OFendl;
        if (metainfo.findAndGetOFString(DCM_TransferSyntaxUID, xferUID).good())
            COUT << "Transfer Syntax UID: " << xferUID << OFendl;

        metainfo.print(COUT);
    }

Output result information :

SOP Class UID: 1.2.840.10008.5.1.4.1.1.2
Transfer Syntax UID: 1.2.840.10008.1.2.4.51
# Dicom-Meta-Information-Header
# Used TransferSyntax: Little Endian Explicit
(0002,0000) UL 202                                      #   4, 1 FileMetaInformationGroupLength
(0002,0001) OB 00\01                                    #   2, 1 FileMetaInformationVersion
(0002,0002) UI =CTImageStorage                          #  26, 1 MediaStorageSOPClassUID
(0002,0003) UI [1.2.276.0.7230010.3.1.4.2012715.17328.1511764633.841627] #  56, 1 MediaStorageSOPInstanceUID
(0002,0010) UI =JPEGExtended:Process2+4                 #  22, 1 TransferSyntaxUID
(0002,0012) UI [1.2.276.0.7230010.3.0.3.6.1]            #  28, 1 ImplementationClassUID
(0002,0013) SH [OFFIS_DCMTK_361]                        #  16, 1 ImplementationVersionName

Official references

Ordinary tag Read

Take reading the patient's name as an example

    DcmFileFormat dcmFormat;

    OFCondition ofResult = dcmFormat.loadFile("G:/dicomFile/3.dcm");

    if (!ofResult.good())
    {
        qDebug() << "dcmFormat read fail..." << ofResult.text();
        return false;
    }

    DcmDataset *pDataSet = dcmFormat.getDataset();

    if (nullptr == pDataSet)
    {
        return false;
    }

    OFString strPatientName;
    ofResult = pDataSet->findAndGetOFString(DCM_PatientName, strPatientName);

    if (!ofResult.good())
    {
        return false;
    }

    qDebug() << "patientName:" << strPatientName.c_str();

Results output

patientName: Zhang xxx

In actual development, parsing needs to correspond to different types , Encapsulate the corresponding parsing method separately

Like parsing strings tag

bool getStringTagValue(DcmDataset* pDataSet,const DcmTag& pTag, QString &value)
{
    if (nullptr == pDataSet)
    {
        return false;
    }

    const char* strValue = nullptr;
    Uint32 lLength = 0;
    OFCondition ofResult = pDataSet->findAndGetString(pTag, strValue, lLength);

    if (!ofResult.good())
    {
        return false;
    }

    value = QLatin1String(strValue, lLength);

    return true;
}

Like parsing floating point numbers tag

bool getU16TagValue(DcmDataset* pDataSet,const DcmTag& pTag, quint16 &nValue)
{
    Uint16	uint16 = 0;

    if ( pDataSet->findAndGetUint16( pTag, uint16).good() )
    {
        nValue = uint16;

        return true;
    }

    return false;
}

Actually DcmFileFormat The object contains DcmMetaInfo and DcmDataset Object pointer , Automatically created internally in the starting constructor , Internal use of a double linked list structure for storage

DcmFileFormat::DcmFileFormat()
  : DcmSequenceOfItems(InternalUseTag),
    FileReadMode(ERM_autoDetect)
{
    DcmMetaInfo *MetaInfo = new DcmMetaInfo();
    DcmSequenceOfItems::itemList->insert(MetaInfo);
    MetaInfo->setParent(this);

    DcmDataset *Dataset = new DcmDataset();
    DcmSequenceOfItems::itemList->insert(Dataset);
    Dataset->setParent(this);
}

summary

Yes, of course , The above methods are all based on DCMTK Open source library to read , You can read it step by step by making your own wheels , It's just a little bit more trouble

GitHub There is a project that has been open source for a long time qdcm, Is based on Qt Realized , You can refer to it

qdcm

Such as reading files , Determine whether the header information code is included

bool DcmFile::hasHeader(const QString &path)
{
    QFile file(path);
    if (!file.open(QFile::ReadOnly)) {
        return false;
    }

    QDataStream ds(&file);
    int s = ds.skipRawData(128);
    if (s != 128) {
        file.close();
        return false;
    }

    char signature[4];
    s = ds.readRawData(signature, 4);
    if (s != 4) {
        file.close();
        return false;
    }

    file.close();

    if (signature[0] == 'D' && signature[1] == 'I' && signature[2] == 'C' && signature[3] == 'M') {
        return true;
    }

    return false;
}

Next, let's learn Dicom Transmission syntax

版权声明
本文为[kevinlq]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/06/20210623213207152y.html