当前位置: 首页>>代码示例>>Python>>正文


Python pydicom.dcmread方法代码示例

本文整理汇总了Python中pydicom.dcmread方法的典型用法代码示例。如果您正苦于以下问题:Python pydicom.dcmread方法的具体用法?Python pydicom.dcmread怎么用?Python pydicom.dcmread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pydicom的用法示例。


在下文中一共展示了pydicom.dcmread方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_dicom_image

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def is_dicom_image(file: str) -> bool:
    """Boolean specifying if file is a proper DICOM file with a image

    Parameters
    ----------
    file : str
        The path to the file.

    See Also
    --------
    pydicom.filereader.read_preamble
    pydicom.filereader.read_partial
    """
    result = False
    try:
        img = pydicom.dcmread(file, force=True)
        if 'TransferSyntaxUID' not in img.file_meta:
            img.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
        img.pixel_array
        result = True
    except (AttributeError, TypeError, KeyError, struct.error):
        pass
    return result 
开发者ID:jrkerns,项目名称:pylinac,代码行数:25,代码来源:io.py

示例2: is_dicomfile

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def is_dicomfile(file: Path) -> bool:
    """
    Checks whether a file is a DICOM-file. It uses the feature that Dicoms have the string DICM hardcoded at offset 0x80.

    :param file:    The full pathname of the file
    :return:        Returns true if a file is a DICOM-file
    """

    if file.is_file():
        if file.stem.startswith('.'):
            logger.warning(f'File is hidden: {file}')
        with file.open('rb') as dcmfile:
            dcmfile.seek(0x80, 1)
            if dcmfile.read(4) == b'DICM':
                return True
            else:
                dicomdict = pydicom.dcmread(str(file), force=True)       # The DICM tag may be missing for anonymized DICOM files
                return 'Modality' in dicomdict
    else:
        return False 
开发者ID:Donders-Institute,项目名称:bidscoin,代码行数:22,代码来源:bids.py

示例3: inspect_sourcefile

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def inspect_sourcefile(self, item):
        """When double clicked, show popup window. """
        if item.column() == 1:
            row  = item.row()
            cell = self.samples_table.item(row, 5)
            sourcefile = Path(cell.text())
            if bids.is_dicomfile(sourcefile):
                sourcedata = pydicom.dcmread(str(sourcefile), force=True)
            elif bids.is_parfile(sourcefile):
                with open(sourcefile, 'r') as parfid:
                    sourcedata = parfid.read()
            else:
                LOGGER.warning(f"Could not read {self.dataformat} file: {sourcefile}")
                return
            self.popup = InspectWindow(sourcefile, sourcedata, self.dataformat)
            self.popup.show()
            self.popup.scrollbar.setValue(0)     # This can only be done after self.popup.show() 
开发者ID:Donders-Institute,项目名称:bidscoin,代码行数:19,代码来源:bidseditor.py

示例4: assign2machine

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def assign2machine(source_file: str, machine_file: str):
    """Assign a DICOM RT Plan file to a specific machine. The source file is overwritten to contain
    the machine of the machine file.

    Parameters
    ----------
    source_file : str
        Path to the DICOM RTPlan file that contains the fields/plan desired
        (e.g. a Winston Lutz set of fields or Varian's default PF files).
    machine_file : str
        Path to a DICOM RTPlan file that has the desired machine. This is easily obtained from pushing a plan from the TPS
        for that specific machine. The file must contain at least one valid field.
    """
    dcm_source = pydicom.dcmread(source_file)
    dcm_machine = pydicom.dcmread(machine_file)
    for beam in dcm_source.BeamSequence:
        beam.TreatmentMachineName = dcm_machine.BeamSequence[0].TreatmentMachineName
    dcm_source.save_as(source_file) 
开发者ID:jrkerns,项目名称:pylinac,代码行数:20,代码来源:utilities.py

示例5: read_image_dicom

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def read_image_dicom(self,path,mode='image'):
        """ Read an image in dicom format.
        Args
            path: Path to the image.
            mode: image|image_sex_view
        """
        dicom_img = pydicom.dcmread(path)
        image = dicom_img.pixel_array
        image = np.stack((image,)*3, -1) #convert grayscale to rgb
        if mode=='image_sex_view':
            if dicom_img.PatientSex == 'F':
                image[:,:,1] = 0
            elif dicom_img.PatientSex == 'M':
                image[:,:,1] = 1
            else:
                raise Exception('Invalid Sex on dicom {}.'.format(path))
            if dicom_img.ViewPosition == 'AP':
                image[:,:,2] = 0
            elif dicom_img.ViewPosition == 'PA':
                image[:,:,2] = 1
            else:
                raise Exception('Invalid View Position on dicom {}. View position is: {}'.format(path,dicom_img.ViewPosition))
        return image[:, :].copy() 
开发者ID:alessonscap,项目名称:rsna-challenge-2018,代码行数:25,代码来源:rsna_generator_mask.py

示例6: imread

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def imread(self, path, grayscale=False, size=None, interpolate="bilinear",
               channel_first=False, as_uint16=False, num_channels=-1, return_palette_indices=False):
        """
        Read image by DICOM module.
        Notice that PIL only supports uint8 for RGB (not uint16).
        So this imread function returns only uint8 array for both RGB and gray-scale.
        (Currently ignore "I" mode for gray-scale (32bit integer).)

        Args:
            path (str or 'file object'): File path or object to read.
            grayscale (bool):
            size (tupple of int):
                (width, height).
                If None, output img shape depends on the files to read.
            channel_first (bool):
                This argument specifies the shape of img is whether (height, width, channel) or (channel, height, width).
                Default value is False, which means the img shape is (height, width, channel).
            interpolate (str):
                must be one of ["nearest", "box", "bilinear", "hamming", "bicubic", "lanczos"].
            as_uint16 (bool):
                If you specify this argument, you can use only False for pil backend.
            num_channels (int):
                channel size of output array.
                Default is -1 which preserves raw image shape.
            return_palette_indices (bool):
                Whether to return a raw palette indices without any conversion or not.
                If this flag is True and read Image has the mode "P",
                then this function returns 2-D array containing the indices into palette.
                We recommend that this flag should be False unless you intend to use the raw palette indices.

        Returns:
            numpy.ndarray
        """
        _imread_before(grayscale, num_channels)
        dicom_dataset = pydicom.dcmread(path)
        img = _apply_gamma_correction(dicom_dataset)
        return _imread_after(img, size, interpolate, channel_first, self.imresize) 
开发者ID:sony,项目名称:nnabla,代码行数:39,代码来源:dicom_backend.py

示例7: on_double_clicked

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def on_double_clicked(self, index: int):
        """Opens the inspect window when a source file in the file-tree tab is double-clicked"""
        sourcefile = Path(self.model.fileInfo(index).absoluteFilePath())
        if bids.is_dicomfile(sourcefile):
            sourcedata = pydicom.dcmread(str(sourcefile), force=True)
        elif bids.is_parfile(sourcefile):
            with open(sourcefile, 'r') as parfid:
                sourcedata = parfid.read()
        else:
            LOGGER.warning(f"Could not read {self.dataformat} file: {sourcefile}")
            return
        self.popup = InspectWindow(sourcefile, sourcedata, self.dataformat)
        self.popup.show()
        self.popup.scrollbar.setValue(0)  # This can only be done after self.popup.show() 
开发者ID:Donders-Institute,项目名称:bidscoin,代码行数:16,代码来源:bidseditor.py

示例8: load_vol

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def load_vol(self, path):
        """
            path : patient data path

            returns numpy array of patient data
        """
        self.patient = pydicom.dcmread(path)

        return self.patient.pixel_array 
开发者ID:koriavinash1,项目名称:DeepBrainSeg,代码行数:11,代码来源:dicom.py

示例9: is_dicom

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def is_dicom(path):
    """Whether the file is a readable DICOM file via pydicom."""
    try:
        ds = pydicom.dcmread(path, force=True)
        ds.pixel_array
        return True
    except:
        return False 
开发者ID:jrkerns,项目名称:pylinac,代码行数:10,代码来源:tools.py

示例10: retrieve_dicom_file

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def retrieve_dicom_file(file: str) -> pydicom.FileDataset:
    """Read and return the DICOM dataset.

    Parameters
    ----------
    file : str
        The path to the file.
    """
    img = pydicom.dcmread(file, force=True)
    if 'TransferSyntaxUID' not in img.file_meta:
        img.file_meta.TransferSyntaxUID = pydicom.uid.ImplicitVRLittleEndian
    return img 
开发者ID:jrkerns,项目名称:pylinac,代码行数:14,代码来源:io.py

示例11: is_CT_slice

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def is_CT_slice(file: str) -> bool:
        """Test if the file is a CT Image storage DICOM file."""
        try:
            ds = pydicom.dcmread(file, force=True, stop_before_pixels=True)
            return ds.SOPClassUID.name == 'CT Image Storage'
        except (InvalidDicomError, AttributeError, MemoryError):
            return False 
开发者ID:jrkerns,项目名称:pylinac,代码行数:9,代码来源:image.py

示例12: read_image_dicom

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def read_image_dicom(self,path,mode='image'):
        """ Read an image in dicom format.
        Args
            path: Path to the image.
            mode: image|image_sex_view
        """
        dicom_img = pydicom.dcmread(path)
        image = dicom_img.pixel_array
        #convert grayscale to rgb
        image = np.stack((image,)*3, -1) 
        if mode=='image_sex_view':
            #split image in patient sex
            if dicom_img.PatientSex == 'F':
                image[:,:,1] = 0
            elif dicom_img.PatientSex == 'M':
                image[:,:,1] = 1
            else:
                raise Exception('Invalid Sex on dicom {}.'.format(path))
            #split image in view position
            if dicom_img.ViewPosition == 'AP':
                image[:,:,2] = 0
            elif dicom_img.ViewPosition == 'PA':
                image[:,:,2] = 1
            else:
                raise Exception('Invalid View Position on dicom {}. View position is: {}'.format(path,dicom_img.ViewPosition))
        return image[:, :].copy() 
开发者ID:alessonscap,项目名称:rsna-challenge-2018,代码行数:28,代码来源:rsna_generator.py

示例13: _store_instances

# 需要导入模块: import pydicom [as 别名]
# 或者: from pydicom import dcmread [as 别名]
def _store_instances(client, args):
    '''Loads Instances from files on disk and stores them.'''
    datasets = [pydicom.dcmread(f) for f in args.files]
    client.store_instances(datasets) 
开发者ID:MGHComputationalPathology,项目名称:dicomweb-client,代码行数:6,代码来源:cli.py


注:本文中的pydicom.dcmread方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。