def is_dicom_file(filename):
    """
    This function is used to check whether a file is in the DICOM format. We
    do this by checking that bytes 129 to 132 are DICM. See

    http://stackoverflow.com/questions/4792727/validating-dicom-file

    for more details
    """
    try:
        with open(filename, 'rb') as f:
            f.read(128)
            if f.read(4) == b'DICM':
                return True
            else:
                return False
    except Exception:
        return False