當前位置: 首頁>>代碼示例>>Python>>正文


Python Dataset.MediaStorageSOPInstanceUID方法代碼示例

本文整理匯總了Python中dicom.dataset.Dataset.MediaStorageSOPInstanceUID方法的典型用法代碼示例。如果您正苦於以下問題:Python Dataset.MediaStorageSOPInstanceUID方法的具體用法?Python Dataset.MediaStorageSOPInstanceUID怎麽用?Python Dataset.MediaStorageSOPInstanceUID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在dicom.dataset.Dataset的用法示例。


在下文中一共展示了Dataset.MediaStorageSOPInstanceUID方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: write_dicom

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def write_dicom(pixel_array, filename):
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = 'Secondary Capture Image Storage'
    file_meta.MediaStorageSOPInstanceUID = '1.3.6.1.4.1.9590.100.1.1.111165684'
    file_meta.MediaStorageSOPInstanceUID += '411017669021768385720736873780'
    file_meta.ImplementationClassUID = '1.3.6.1.4.1.9590.100.1.0.100.4.0'
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble=b"\0"*128)
    ds.Modality = 'MR'
    ds.ContentDate = str(date.today()).replace('-', '')
    ds.ContentTime = str(time())
    ds.StudyInstanceUID = '1.3.6.1.4.1.9590.100.1.1.1243139774123601752342712'
    ds.StudyInstanceUID += '87472804872093'
    ds.SeriesInstanceUID = '1.3.6.1.4.1.9590.100.1.1.369231118011061003403421'
    ds.SeriesInstanceUID += '859172643143649'
    ds.SOPInstanceUID = '1.3.6.1.4.1.9590.100.1.1.111165684411017669021768385'
    ds.SOPInstanceUID += '720736873780'
    ds.SOPClassUID = 'Secondary Capture Image Storage'
    ds.SecondaryCaptureDeviceManufctur = 'Python 3.3.5'
    # Options
    ds.InstitutionName = "Imperial College London"
    ds.RepetitionTime = 300
    # These are the necessary imaging components of the FileDataset object.
    ds.SamplesPerPixel = 1
    ds.PhotometricInterpretation = "MONOCHROME2"
    ds.PixelRepresentation = 0
    ds.HighBit = 15
    ds.BitsStored = 16
    ds.BitsAllocated = 16
    ds.Columns = pixel_array.shape[1]
    ds.Rows = pixel_array.shape[0]
    ds.PixelData = pixel_array.tostring()
    ds.save_as(filename)

    return 0
開發者ID:magicangleimperial,項目名稱:pyscanMRI,代碼行數:36,代碼來源:scanMRI_Other.py

示例2: WriteDCMFile

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def WriteDCMFile(pixel_array,filename):
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = 'RT Image Storage'
    file_meta.MediaStorageSOPInstanceUID = '1.3.6.1.4.1.9590.100.1.1.111165684411017669021768385720736873780'
    file_meta.ImplementationClassUID = '1.3.6.1.4.1.9590.100.1.0.100.4.0'
    ds = FileDataset(filename, {},file_meta = file_meta,preamble="\0"*128)
    ds.Modality = 'RTIMAGE'
    ds.ContentDate = str(datetime.date.today()).replace('-','')
    ds.ContentTime = str(time.time()) #milliseconds since the epoch
    ds.StudyInstanceUID =  '1.3.6.1.4.1.9590.100.1.1.124313977412360175234271287472804872093'
    ds.SeriesInstanceUID = '1.3.6.1.4.1.9590.100.1.1.369231118011061003403421859172643143649'
    ds.SOPInstanceUID =    '1.3.6.1.4.1.9590.100.1.1.111165684411017669021768385720736873780'
    ds.SOPClassUID = 'RT Image Storage'
    ds.SecondaryCaptureDeviceManufacturer = 'Varian Medical Systems'

    ## These are the necessary imaging components of the FileDataset object.
    ds.SamplesPerPixel = 1
    ds.ImagePlanePixelSpacing=[0.392,0.392]
    ds.PhotometricInterpretation = "MONOCHROME2"
    ds.PixelRepresentation = 0
    ds.HighBit = 15
    ds.BitsStored = 16
    ds.BitsAllocated = 16
    # ds.SmallestImagePixelValue = '\\x00\\x00'
    # ds.LargestImagePixelValue = '\\xff\\xff'
    ds.Columns =1024# pixel_array.shape[0]
    ds.Rows =764# pixel_array.shape[1]
    ds.RescaleSlope=1.0
    ds.RescaleIntercept=1.0
    # if type(pixel_array) != np.uint16:
    #     pixel_array =np.uint16(pixel_array)
    ds.PixelData = pixel_array
    ds.save_as(filename,write_like_original=True)
    return
開發者ID:Jothy,項目名稱:RTQA,代碼行數:36,代碼來源:DCMReader.py

示例3: create_dicom

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def create_dicom(private_tag,payload,filename):
    """ Function creates minimal dicom file from scratch with required tags
        and stores payload (string) in the specified private tag.
    """

    # create empty dicomfile
    file_meta = Dataset()

    # Raw Data Storage
    file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.66'

    # unieke uid's
    file_meta.MediaStorageSOPInstanceUID = dicom.UID.generate_uid()
    file_meta.ImplementationClassUID = dicom.UID.generate_uid()

    ds = FileDataset(filename, {},file_meta = file_meta,preamble="\0"*128)

    ds.SOPClassUID = '1.2.840.10008.5.1.4.1.1.7' # secondary capture SOP UID
    ds.SOPInstanceUID = file_meta.MediaStorageSOPInstanceUID
    ds.StudyInstanceUID = dicom.UID.generate_uid()
    ds.SeriesInstanceUID = dicom.UID.generate_uid()

    ds.PatientID = PatientID
    ds.PatientName = PatientName
    ds.StudyDescription = StudyDescription
    ds.SeriesDescription = SeriesDescription
    ds.Modality = 'OT'
    ds.StudyDate = time.strftime('%Y%m%d')
    ds.SeriesDate = ds.StudyDate
    ds.ContentDate = ds.StudyDate
    ds.StudyTime = ds.SeriesTime = ds.ContentTime = time.strftime('%H%M%S')

    ds.add_new(private_tag,'OB', payload)

    ds.save_as(filename)
開發者ID:JaapGroen,項目名稱:WAD_Python,代碼行數:37,代碼來源:create_dicom.py

示例4: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
 def OnReceiveStore(self, SOPClass, DS):
     # sleep(0.1)
     rl.info('Received C-STORE')
     # do something with dataset. For instance, store it on disk.
     file_meta = Dataset()
     file_meta.MediaStorageSOPClassUID = DS.SOPClassUID
     file_meta.MediaStorageSOPInstanceUID = UID.generate_uid() #DS.SOPInstanceUID  # !! Need valid UID here
     file_meta.ImplementationClassUID = UID.pydicom_root_UID #"1.2.3.4"  # !!! Need valid UIDs here
     file_path = directory.joinPath([self.StorePath, str(DS.SeriesDate), str(DS.SeriesDescription)])
     if fmriQA.is_dicom_dict_QA(DS):
         directory.createPath(file_path)
         filename = directory.joinPath([file_path, "I%05d" % DS.get('InstanceNumber') + '.'+config.DATA_EXT])
         ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
         ds.update(DS)
         ds.is_little_endian = True
         ds.is_implicit_VR = True
         # print ds - prints all DICOM tags contained in the file prior its saving
         ds.save_as(filename)
         if directory.isFile(filename):
             rl.info('File %s written' % filename)
             # must return appropriate status
             return SOPClass.Success
         else:
             return SOPClass.UnableToProcess
             rl.error('File %s failed to write' % filename)
     else:
         return SOPClass.IdentifierDoesNotMatchSOPClass
         rl.warning('The sent file was not recognised as QA file (%s)' % filename)
開發者ID:pete-fab,項目名稱:fMRI_QA,代碼行數:30,代碼來源:pynet_DICOM_server.py

示例5: write_dicom

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def write_dicom(pixel_array, filename, ds_copy, ds_ori, volume_number,
                series_number, sop_id):
    """Write data in dicom file and copy the header from different dicoms.

    :param pixel_array: data to write in a dicom
    :param filename: file name for the dicom
    :param ds_copy: pydicom object of the dicom to copy info from
    :param ds_ori: pydicom object of the dicom where the array comes from
    :param volume_number: numero of volume being processed
    :param series_number: number of the series being written
    :param sop_id: SOPID for the dicom
    :return: None
    """
    # Set to zero negatives values in the image:
    pixel_array[pixel_array < 0] = 0

    # Set the DICOM dataset
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = 'Secondary Capture Image Storage'
    file_meta.MediaStorageSOPInstanceUID = ds_ori.SOPInstanceUID
    file_meta.ImplementationClassUID = ds_ori.SOPClassUID
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0"*128)

    # Copy the tag from the original DICOM
    for tag, value in ds_ori.items():
        if tag != ds_ori.data_element("PixelData").tag:
            ds[tag] = value

    # Other tags to set
    ds.SeriesNumber = series_number
    ds.SeriesDescription = ds_ori.SeriesDescription + ' reg_f3d'
    sop_uid = sop_id + str(datetime.datetime.now()).replace('-', '')\
                                                   .replace(':', '')\
                                                   .replace('.', '')\
                                                   .replace(' ', '')
    ds.SOPInstanceUID = sop_uid[:-1]
    ds.ProtocolName = ds_ori.ProtocolName
    ds.InstanceNumber = volume_number+1

    # Copy from T2 the orientation tags:
    ds.PatientPosition = ds_copy.PatientPosition
    ds[0x18, 0x50] = ds_copy[0x18, 0x50]  # Slice Thicknes
    ds[0x18, 0x88] = ds_copy[0x18, 0x88]  # Spacing Between Slices
    ds[0x18, 0x1312] = ds_copy[0x18, 0x1312]  # In-plane Phase Encoding
    ds[0x20, 0x32] = ds_copy[0x20, 0x32]  # Image Position
    ds[0x20, 0x37] = ds_copy[0x20, 0x37]  # Image Orientation
    ds[0x20, 0x1041] = ds_copy[0x20, 0x1041]  # Slice Location
    ds[0x28, 0x10] = ds_copy[0x28, 0x10]  # rows
    ds[0x28, 0x11] = ds_copy[0x28, 0x11]  # columns
    ds[0x28, 0x30] = ds_copy[0x28, 0x30]  # Pixel spacing

    # Set the Image pixel array
    if pixel_array.dtype != np.uint16:
        pixel_array = pixel_array.astype(np.uint16)
    ds.PixelData = pixel_array.tostring()

    # Save the image
    ds.save_as(filename)
開發者ID:byvernault,項目名稱:scripts,代碼行數:60,代碼來源:Ben_functions.py

示例6: WriteDICOM_slice

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
    def WriteDICOM_slice(self, pixel_array,filename, itemnumber=0, PhotometricInterpretation="MONOCHROME2"):
        from dicom.dataset import Dataset, FileDataset
        import numpy as np
        import datetime, time
        """
        INPUTS:
        pixel_array: 2D numpy ndarray.  If pixel_array is larger than 2D, errors.
        filename: string name for the output file.
        """
        ## This code block was taken from the output of a MATLAB secondary
        ## capture.  I do not know what the long dotted UIDs mean, but
        ## this code works.
        file_meta = Dataset()
        file_meta.MediaStorageSOPClassUID = 'Secondary Capture Image Storage'
        file_meta.MediaStorageSOPInstanceUID = '1.3.6.1.4.1.9590.100.1.1.111165684411017669021768385720736873780'
        file_meta.ImplementationClassUID = '1.3.6.1.4.1.9590.100.1.0.100.4.0'
        ds = FileDataset(filename, {},file_meta = file_meta,preamble="\0"*128)
        ds.Modality = 'WSD'
        ds.ContentDate = str(datetime.date.today()).replace('-','')
        ds.ContentTime = str(time.time()) #milliseconds since the epoch
        ds.StudyInstanceUID =  '1.3.6.1.4.1.9590.100.1.1.124313977412360175234271287472804872093'
        ds.SeriesInstanceUID = '1.3.6.1.4.1.9590.100.1.1.369231118011061003403421859172643143649'
        ds.SOPInstanceUID =    '1.3.6.1.4.1.9590.100.1.1.111165684411017669021768385720736873780'
        ds.SOPClassUID = 'Secondary Capture Image Storage'
        ds.SecondaryCaptureDeviceManufctur = 'Python 2.7.3'
        ## These are the necessary imaging components of the FileDataset object.
        ds.SamplesPerPixel = 1
        if PhotometricInterpretation=="MONOCHROME2":
            ds.PhotometricInterpretation = "MONOCHROME2"
            ds.PixelRepresentation = 0
            ds.HighBit = 15
            ds.BitsStored = 16
            ds.BitsAllocated = 16
            ds.SmallestImagePixelValue = '\\x00\\x00'
            ds.LargestImagePixelValue = '\\xff\\xff'
        elif PhotometricInterpretation=="RGB":
            ds.PhotometricInterpretation = "MONOCHROME2"
            ds.PixelRepresentation = 0
            ds.HighBit = 15
            ds.BitsStored = 16
            ds.BitsAllocated = 16
            ds.SmallestImagePixelValue = '\\x00\\x00'
            ds.LargestImagePixelValue = '\\xff\\xff'    
            pixel_array = pixel_array[0]
            print pixel_array.shape
        ds.Columns = pixel_array.shape[0]
        ds.ItemNumber = str(itemnumber)
        ds.InstanceNumber = str(itemnumber)
        ds.SliceLocation = str(itemnumber)
        ds.Rows = pixel_array.shape[1]
        if pixel_array.dtype != np.uint16:
            pixel_array = pixel_array.astype(np.uint16)
            ds.PixelData = pixel_array.tostring()
        ds.save_as(filename)

        return filename
開發者ID:haanme,項目名稱:FinnBrain,代碼行數:58,代碼來源:DicomIO.py

示例7: get_file_meta

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
    def get_file_meta(self):
        """generate the dicom file meta data.
        """
        file_meta = Dataset()
        file_meta.FileMetaInformationVersion = '\x00\x01'
        file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' # CT Image Storage
        
        file_meta.MediaStorageSOPInstanceUID = ''  # !! Need valid UID here for real work
        file_meta.TransferSyntaxUID = '1.2.840.10008.1.2'
 
        file_meta.ImplementationClassUID = pydicom_root_UID + "1" # !!! Need valid UIDs here
    
        return  file_meta
開發者ID:zoulianmp,項目名稱:mftm,代碼行數:15,代碼來源:dicom_exporter.py

示例8: write_dicom

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def write_dicom(pixel_array, filename, ds_copy, ds_ori, volume_number,
                series_number, sop_id):
    """Write a dicom from a pixel_array (numpy).

    :param pixel_array: 2D numpy ndarray.
                        If pixel_array is larger than 2D, errors.
    :param filename: string name for the output file.
    :param ds_copy: pydicom object with the header that need to be copy
    :param ds_ori: original pydicom object of the pixel_array
    :param volume_number: number of the volume being processed
    :param series_number: number of the series being processed
    :param sop_id: SOPInstanceUID for the DICOM
    """
    # Set to zero negatives values in the image:
    pixel_array[pixel_array < 0] = 0

    # Set the DICOM dataset
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = 'Secondary Capture Image Storage'
    file_meta.MediaStorageSOPInstanceUID = ds_ori.SOPInstanceUID
    file_meta.ImplementationClassUID = ds_ori.SOPClassUID
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0"*128)

    # Copy the tag from the original DICOM
    for tag, value in ds_ori.items():
        if tag != ds_ori.data_element("PixelData").tag:
            ds[tag] = value

    # Other tags to set
    ds.SeriesNumber = series_number
    ds.SeriesDescription = ds_ori.SeriesDescription + ' reg_f3d'
    sop_uid = sop_id + str(datetime.datetime.now()).replace('-', '')\
                                                   .replace(':', '')\
                                                   .replace('.', '')\
                                                   .replace(' ', '')
    ds.SOPInstanceUID = sop_uid[:-1]
    ds.ProtocolName = ds_ori.ProtocolName
    ds.InstanceNumber = volume_number+1

    # Copy from T2 the orientation tags:
    for tag in TAGS_TO_COPY:
        if tag in ds_copy:
            ds[tag] = ds_copy[tag]

    # Set the Image pixel array
    if pixel_array.dtype != np.uint16:
        pixel_array = pixel_array.astype(np.uint16)
    ds.PixelData = pixel_array.tostring()

    # Save the image
    ds.save_as(filename)
開發者ID:byvernault,項目名稱:ucl_processing,代碼行數:53,代碼來源:Spider_Registration_Prostate_v1_0_0.py

示例9: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def OnReceiveStore(SOPClass, DS):
    #print "Received C-STORE"
    # do something with dataset. For instance, store it on disk.
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = DS.SOPClassUID
    file_meta.MediaStorageSOPInstanceUID = "1.2.3"  # !! Need valid UID here
    file_meta.ImplementationClassUID = "1.2.3.4"  # !!! Need valid UIDs here
    filename = '%s/%s.dcm' % (tempfile.gettempdir(), DS.SOPInstanceUID)
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
    ds.update(DS)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    #print "File %s written" % filename
    # must return appropriate status
    return SOPClass.Success
開發者ID:AlfiyaZi,項目名稱:pynetdicom,代碼行數:18,代碼來源:storescp.py

示例10: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def OnReceiveStore(SOPClass, DS):
    print "Received C-STORE"
    # do something with dataset. For instance, store it.
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.2' # CT Image Storage
    file_meta.MediaStorageSOPInstanceUID = "1.2.3" # !! Need valid UID here for real work
    file_meta.ImplementationClassUID = "1.2.3.4" # !!! Need valid UIDs here
    filename = '/tmp/%s.dcm' % DS.SOPInstanceUID
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0"*128)
    ds.update(DS)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    print "File %s written" % filename
    # must return appropriate status
    return 0
開發者ID:IMAGE-ET,項目名稱:pynetdicom,代碼行數:18,代碼來源:storescp.py

示例11: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def OnReceiveStore(SOPClass, DS):
    print "Received C-STORE", DS.PatientName
    try:
        # do something with dataset. For instance, store it.
        file_meta = Dataset()
        file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.2'
        file_meta.MediaStorageSOPInstanceUID = "1.2.3"  # !! Need valid UID here
        file_meta.ImplementationClassUID = "1.2.3.4"  # !!! Need valid UIDs here
        filename = '%s/%s.dcm' % (tempfile.gettempdir(), DS.SOPInstanceUID)
        ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
        ds.update(DS)
        ds.save_as(filename)
        print "File %s written" % filename
    except:
        pass
    # must return appropriate status
    return SOPClass.Success
開發者ID:olivierjaubert,項目名稱:dicomDB,代碼行數:19,代碼來源:do_results_DB.py

示例12: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def OnReceiveStore(SOPClass, DS):
    print "Received C-STORE"
    # do something with dataset. For instance, store it on disk.
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = DS.SOPClassUID
    file_meta.MediaStorageSOPInstanceUID = DS.SOPInstanceUID # Change to my own UID via dicom.UID.generate_uid() though I should make sure such genereated UIDs use my orgroot.
    file_meta.ImplementationClassUID = "1.2.826.0.1.3680043.9.5066.0"  # My UID for my implementation, with a '.0' appended to it to represent development testing, ie the UID I got from Medical Connections.
    file_meta.ImplementationVersionName = "DICOMMETRICS-DEV" # My implementation version name. Remember to change this for each version. Remember to correspondingly change the ImplementationClassUID too.
    filename = '%s/%s.dcm' % (tempfile.gettempdir(), DS.SOPInstanceUID)
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0" * 128)
    ds.update(DS)
    ds.is_little_endian = True
    ds.is_implicit_VR = True
    ds.save_as(filename)
    print "File %s written" % filename
    # must return appropriate status
    return SOPClass.Success
開發者ID:lynch829,項目名稱:dicommetrics,代碼行數:19,代碼來源:storescp-dev.py

示例13: OnReceiveStore

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
        def OnReceiveStore(SOPClass, DS):
            file_meta = Dataset()
            file_meta.MediaStorageSOPClassUID = DS.SOPClassUID
            file_meta.MediaStorageSOPInstanceUID = DS.SOPInstanceUID
            file_meta.ImplementationClassUID = DS.SOPClassUID
            filename = os.path.join(
                constants.dicom_dir, foldername, DS.SOPInstanceUID + ".dcm")
            print "making file ", filename
            ds = FileDataset(
                filename, {}, file_meta=file_meta, preamble="\0" * 128)
            ds.update(DS)
            ds.is_little_endian = True
            ds.is_implicit_VR = True

            ds.save_as(filename)
            # print "File %s written" % filename
            # must return appropriate status
            return SOPClass.Success
開發者ID:wonkykludge,項目名稱:fsspmnl_webinterface,代碼行數:20,代碼來源:views.py

示例14: create_dcm

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
def create_dcm(filename,patname='BarcoQC',patid='112233'):


    textfile = open(filename,'rb')

    filename = os.path.splitext(filename)[0]+'.dcm'
    print "Output filename:", filename

    # Populate required values for file meta information
    file_meta = Dataset()
    file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.104.1' # NM Image Storage misschien beter OT
    file_meta.MediaStorageSOPInstanceUID = "1.2.3" # !! Need valid UID here for real work
    file_meta.ImplementationClassUID = "1.2.3.4" # !!! Need valid UIDs here
   
    print "Setting dataset values..."
   
    # Create the FileDataset instance (initially no data elements, but file_meta supplied)
    ds = FileDataset(filename, {}, file_meta=file_meta, preamble="\0"*128)
   
    # Add the data elements -- not trying to set all required here. Check DICOM standard
    ds.PatientName = patname
    ds.PatientID = patid
    
    #datestring = extract_date(textfile)
    #print datestring
    
    #ds.InstanceCreationDate = datestring
    # Set the transfer syntax
    ds.is_little_endian = True
    ds.is_implicit_VR = True

    #doctag = dicom.tag.Tag(("0042","0011"))
    doctag = dicom.tag.Tag(("0001","9999"))
    ds.add_new(doctag,'OB', textfile.read())

   
    print "Writing test file", filename
    ds.save_as(filename)
    print "File saved."
開發者ID:jhuguetn,項目名稱:WAD_Python,代碼行數:41,代碼來源:barcotxt2dcm.py

示例15: copyCTtoRTDose

# 需要導入模塊: from dicom.dataset import Dataset [as 別名]
# 或者: from dicom.dataset.Dataset import MediaStorageSOPInstanceUID [as 別名]
    def copyCTtoRTDose(self, path, ds, doseData, imageRow, imageCol, sliceCount, dgs):
        
        # Create a RTDose file for broadcasting.
        file_meta = Dataset()
        file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.481.2' # CT Image Storage
        # Needs valid UID
        file_meta.MediaStorageSOPInstanceUID = ds.file_meta.MediaStorageSOPInstanceUID
        file_meta.ImplementationClassUID = ds.file_meta.ImplementationClassUID

        #create DICOM RT-Dose object.
        rtdose = FileDataset(path + '/rtdose.dcm', {}, file_meta=file_meta, preamble="\0"*128)
        
        #No DICOM object standard. Use only required to avoid errors with viewers.
        rtdose.SOPInstanceUID = ds.SOPInstanceUID
        rtdose.SOPClassUID = '1.2.840.10008.5.1.4.1.1.481.2'
        rtdose.file_meta.TransferSyntaxUID = ds.file_meta.TransferSyntaxUID
        rtdose.PatientsName = ds.PatientsName
        rtdose.PatientID = ds.PatientID
        rtdose.PatientsBirthDate = ds.PatientsBirthDate
        #Crashed caused if no sex.
        try:
            rtdose.PatientsSex = ds.PatientsSex
        except:
            rtdose.PatientsSex, ds.PatientsSex = 'O', 'O'
            self.data.update({'images':ds})
            
        rtdose.StudyDate                  = ds.StudyDate
        rtdose.StudyTime                  = ds.StudyTime
        rtdose.StudyInstanceUID           = ds.StudyInstanceUID
        rtdose.SeriesInstanceUID          = ds.SeriesInstanceUID
        rtdose.StudyID                    = ds.StudyID
        rtdose.SeriesNumber               = ds.SeriesNumber
        rtdose.Modality                   = 'RTDOSE'
        rtdose.ImagePositionPatient       = ds.ImagePositionPatient
        rtdose.ImageOrientationPatient    = ds.ImageOrientationPatient
        rtdose.FrameofReferenceUID        = ds.FrameofReferenceUID
        rtdose.PositionReferenceIndicator = ds.PositionReferenceIndicator
        rtdose.PixelSpacing               = ds.PixelSpacing
        rtdose.SamplesperPixel            = 1
        rtdose.PhotometricInterpretation  = 'MONOCHROME2'
        rtdose.NumberofFrames             = sliceCount
        rtdose.Rows                       =  imageRow
        rtdose.Columns                    = imageCol
        rtdose.BitsAllocated              = 32
        rtdose.BitsStored                 = 32
        rtdose.HighBit                    = 31
        rtdose.PixelRepresentation        = 0
        rtdose.DoseUnits                  = 'GY'
        rtdose.DoseType                   = 'PHYSICAL'
        rtdose.DoseSummationType          = 'FRACTION'
        #In case spaceing tag is missing.
        if not ds.has_key('SpacingBetweenSlices'):
            ds.SpacingBetweenSlices = ds.SliceThickness
        #Ensure patient pos is on "Last slice".
        if fnmatch.fnmatch(ds.PatientPosition, 'FF*'):
            #For compliance with dicompyler update r57d9155cc415 which uses a reverssed slice ordering.
            doseData = doseData[::-1]
            rtdose.ImagePositionPatient[2] = ds.ImagePositionPatient[2]
        elif fnmatch.fnmatch(ds.PatientPosition, 'HF*'):
            rtdose.ImagePositionPatient[2] = ds.ImagePositionPatient[2] - (sliceCount-1)*ds.SpacingBetweenSlices
        #Create Type A(Relative) GFOV.
        rtdose.GridFrameOffsetVector = list(np.arange(0., sliceCount*ds.SpacingBetweenSlices,ds.SpacingBetweenSlices))
        #Scaling from int to physical dose
        rtdose.DoseGridScaling = dgs

        #Store images in pixel_array(int) & Pixel Data(raw).  
        rtdose.pixel_array = doseData
        rtdose.PixelData   = doseData.tostring()

        #Tag required by dicompyler.
        plan_meta = Dataset()
        rtdose.ReferencedRTPlans = []
        rtdose.ReferencedRTPlans.append([])
        rtdose.ReferencedRTPlans[0] = plan_meta
        rtdose.ReferencedRTPlans[0].ReferencedSOPClassUID = 'RT Plan Storage'
        rtdose.ReferencedRTPlans[0].ReferencedSOPInstanceUID = ds.SOPInstanceUID


        #Create RTPlan to acticate DVH
        file_meta = Dataset()
        file_meta.MediaStorageSOPClassUID = '1.2.840.10008.5.1.4.1.1.481.5' # RT Plan Storage
        file_meta.MediaStorageSOPInstanceUID = ds.file_meta.MediaStorageSOPInstanceUID
        file_meta.ImplementationClassUID = ds.file_meta.ImplementationClassUID

        #create DICOM RT-Plan object.
        rtPlan = FileDataset(path + '/rtplan.dcm', {}, file_meta=file_meta, preamble="\0"*128)
        
        #No DICOM object standard. Use only required to avoid errora with viewers.
        rtPlan.SOPInstanceUID              = ds.SOPInstanceUID
        rtPlan.SOPClassUID                 = '1.2.840.10008.5.1.4.1.1.481.5'
        rtPlan.ReferencedSOPInstanceUID    = ds.SOPInstanceUID #Need to change
        rtPlan.file_meta.TransferSyntaxUID = ds.file_meta.TransferSyntaxUID
        rtPlan.PatientsName                = ds.PatientsName
        rtPlan.PatientID                   = ds.PatientID
        rtPlan.PatientsSex                 = ds.PatientsSex
        rtPlan.PatientsBirthDate           = ds.PatientsBirthDate
        rtPlan.RTPlanLabel                 = 'Simulation'
        rtPlan.RTPlanDate                  = ds.StudyDate
        rtPlan.RTPlanTime                  = ds.StudyTime
        rtPlan.Modality                    = 'RTPLAN'
#.........這裏部分代碼省略.........
開發者ID:JimWink,項目名稱:dicompyler-plugins,代碼行數:103,代碼來源:g4dose.py


注:本文中的dicom.dataset.Dataset.MediaStorageSOPInstanceUID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。