Hi, I need to read a directory and determine if a file is Dicom, what is the fastest way to do this.
Currently I'm using DcmFileFormat to open each file, but this is too slow in some cases.
Thanks in advance.
Determining if a file is a Dicom file
Moderator: Moderator Team
-
- Posts: 101
- Joined: Wed, 2009-07-08, 16:06
- Location: Oldenburg, Germany
-
- Posts: 347
- Joined: Mon, 2009-02-23, 19:57
Thanks omarelgazzar, here's the function with a slight modification:
Code: Select all
bool fileIsDicom(char * fname)
{
bool ok = false;
FILE* f = NULL;
f = fopen(fname, "rb");
if (f == 0) {
ok = false;
} else {
char signature[4];
if ((fseek(f, DCM_PreambleLen, SEEK_SET) < 0) ||
(fread(signature, 1, DCM_MagicLen, f) != DCM_MagicLen)) {
ok = false;
} else if (strncmp(signature, DCM_Magic, DCM_MagicLen) != 0) {
ok = false;
} else {
/* looks ok */
ok = true;
}
fclose(f);
}
return ok;
}
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest