Skip to content

Instantly share code, notes, and snippets.

View JulesGorny's full-sized avatar

Zerkay JulesGorny

  • Clermont-Ferrand, FRANCE
View GitHub Profile
INCLUDE_DIRECTORIES(
#DCMTK
C:/pro/dcmtk/build/include
C:/pro/dcmtk/src/dcmdata/include/dcmtk/dcmdata
C:/pro/dcmtk/build/include
C:/pro/dcmtk/src/dcmdata/include
C:/pro/dcmtk/src/ofstd/include
C:/pro/dcmtk/src/oflog/include
C:/pro/dcmtk/src/dcmimage/include/dcmtk
C:/pro/dcmtk/src/dcmimgle/include
//Includes DCMTK
#include "dcdicdir.h"
#include "dcdeftag.h"
#include "dcddirif.h"
#include "dcmtk/config/osconfig.h"
#include "dctk.h"
#include "dcmimage.h"
#include "diregist.h" // Support for color images
#include "dcrledrg.h" // Support for RLE images
#include "djdecode.h" // Support for JPEG images
//hierarchyRecord being a DcmDirectoryRecord (check DICOMDIR_Open.cpp)
OFCondition status = EC_TagNotFound;
DcmStack stack;
DcmObject *object = NULL;
//Browse the properties of the element
while (hierarchyRecord->nextObject(stack, OFTrue).good())
{
object = stack.top();
DcmTag tag = object->getTag();
//Open the DICOM file and get the dictionary
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(file);
DcmDataset *dictionary;
if (status.good())
dictionary = fileformat.getDataset();
/////////////////////////////////////////
// Modify anything in the DICOM file //
/////////////////////////////////////////
//Functions to copy a pixel
void Anonymizer::copyPixel(const Uint8* src, Uint8* dest, int at, int SamplesPerPixel)
{
for(int spp=0; spp<SamplesPerPixel; spp++)
dest[at+spp] = src[at+spp];
}
void Anonymizer::copyPixel(const Uint16* src, Uint16* dest, int at, int SamplesPerPixel)
{
char *file = "C:/Folder1/Folder2/dicomfile";
//Open the DICOM file and get the dictionary
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(file);
DcmDataset *dictionary;
if (status.good())
dictionary = fileformat.getDataset();
//Get the transfer syntax to check if we need jpeg codecs
char *file = "C:/Folder1/Folder2/dicomfile";
//Open the DICOM file and get the dictionary
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(file);
DcmDataset *dictionary;
if (status.good())
dictionary = fileformat.getDataset();
//Get the transfer syntax to check if we need jpeg codecs
char *file = "C:/Folder1/Folder2/dicomfile";
//Open the DICOM file
DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(file);
DcmDataset *dictionary;
//If the loading worked
if( status.good() )
dictionary = fileformat.getDataset();
@JulesGorny
JulesGorny / DICOMDIR_Open.cpp
Last active March 22, 2021 08:59
How to open a DICOMDIR file and retrieve the DICOM files.
//Open the DICOMDIR File
QString DICOMDIR_folder = "C:/Folder1/Folder2";
const char *fileName = "C:/Folder1/Folder2/DICOMDIR";
DcmDicomDir dicomdir(fileName);
//Retrieve root node
DcmDirectoryRecord *root = &dicomdir.getRootRecord();
//Prepare child elements
DcmDirectoryRecord *rootTest = new DcmDirectoryRecord(*root);
DcmDirectoryRecord *PatientRecord = NULL;
DcmDirectoryRecord *StudyRecord = NULL;