I have to pick all valid DICOM Files from folder. I can recursively pick all the files from the folder which have *.DCM extension. But any file with *.DCM also picked up and such file is not valid DICOM File.
What is best way.
I thought of reading few byte of the file and validating.
Or
Any Other Method or any other EXEs we have which validates.
Thank you, Harsha
Edit: Solution for the problem: I finally used the dcmftest.exe for verification. Hope I am on right track. -Harsha
To read metadata from a DICOM file, use the dicominfo function. dicominfo returns the information in a MATLAB® structure where every field contains a specific piece of DICOM metadata.
DICOM files may also open with IrfanView, Adobe Photoshop, and GIMP. If you're still having trouble opening the file, it might be because it's compressed. You can try renaming it so that it ends in . zip, and then compress it with a free file extractor program, like PeaZip or 7-Zip.
A DICOM image file is an outcome of the Digital Imaging and Communications in Medicine standard. Specifically, image files that are compliant with part 10 of the DICOM standard are generally referred to as “DICOM format files” or simply “DICOM files” and are represented as “.dcm.”[2]
DICOM images cannot be shared as you would other files. Sharing a batch of snapshots in the JPEG format or Word documents is a fairly simple process. You can either send them as an email attachment or copy them to a pen drive or an external hard disk and hand that over to the desired recipient.
You want to recognize DICOM files, not to validate. There is big difference. Validation means (at least!) that all the tags required for its SOP class are present.
Recognition is easy, as the DICOM file has to contain text DICM
at the offset 0x80, so that tags start at the offset 0x84 of file.
Note that sometimes only the serialized dataset is stored (starting with tag group 8 at file offset 0), and these are more difficult to recognize, but are not standard.
EDIT: As an example, consider a RAR archive. It's easy to recognize, because it starts with Rar!
. However, to be sure that it's a valid RAR archive, you have to decompress all the files and check their CRCs, and this is something that could be done only by RAR itself (and it's slow).
I know this has been answered already but I had a similar requirement, so I whipped up some extension methods to do exactly that. Works on Files, FileStreams, MemoryStreams and generic Streams. Only reads the specific 4 bytes needed to validate the filetype. Extremely efficient, I was able to run through thousands of files within seconds.
C#
public static class Dicom
{
public static bool IsDicomFile(this Stream s)
{
//Create an empty 4 byte array
byte[] dba = new byte[4];
//Seek to 0x80
s.Seek(128, SeekOrigin.Begin);
//Read the following 4 dba
s.Read(dba, 0, 4);
//Compare to 'DICM'
return dba.SequenceEqual(new byte[4] {68, 73, 67, 77});
}
public static bool IsDicomFile(this MemoryStream ms)
{
return ((Stream)ms).IsDicomFile();
}
public static bool IsDicomFile(this FileStream fs)
{
return ((Stream)fs).IsDicomFile();
}
public static bool IsDicomFile(this FileInfo fi)
{
return fi.OpenRead().IsDicomFile();
}
}
VB.NET
<Extension()> _
Public Function IsDicomFile(ByVal s As Stream) As Boolean
'Create an empty 4 byte array
Dim dba() As Byte = New Byte(3) {}
'Seek to 0x80
s.Seek(128, SeekOrigin.Begin)
'Read the subsequent 4 bytes
s.Read(dba, 0, 4)
'Compare to 'DICM'
Return dba.SequenceEqual(New Byte(3) {68, 73, 67, 77})
End Function
<Extension()> _
Public Function IsDicomFile(ByVal ms As MemoryStream) As Boolean
Return DirectCast(ms, Stream).IsDicomFile
End Function
<Extension()> _
Public Function IsDicomFile(ByVal fs As FileStream) As Boolean
Return DirectCast(fs, Stream).IsDicomFile
End Function
<Extension()> _
Public Function IsDicomFile(ByVal fi As FileInfo) As Boolean
Return fi.OpenRead().IsDicomFile
End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With