How Can Write Code With Python?

General discussion for MicroDicom viewer
Post Reply
admin2
Posts: 1
Joined: Mon Dec 22, 2014 11:15 pm

How Can Write Code With Python?

Post by admin2 » Mon Dec 22, 2014 11:29 pm

Hi Every body----- Happy New Year

I Want to Write python script to Convert .jpg format to .dcm format ,, but When I compile the Script ,it Work bad ,,, This is my script

Code: Select all

#===================================== Library ======================================
from dicom.dataset import Dataset, FileDataset
import os
import datetime
import time
import Image
import numpy
import socket
#=================================== Class =============================================
class Dicom:  
    def Setting(self, pixel_array, filename):
        try:
            #/////////////////////FileMeta\\\\\\\\\\\\\\\\\\\\  
            file_meta = Dataset()
            file_meta.MediaStorageSOPClassUID = 'Media Storage SOP Class UID'  
            file_meta.MediaStorageSOPInstanceUID = "Media Storage SOP Instance UID"  
            file_meta.ImplementationClassUID = "Implementation Class UID"
            print '[+] Complete Set FileMeta'
            #/////////////////////FileDataset\\\\\\\\\\\\\\\\\\\\  
            ds = FileDataset(filename, {}, file_meta = file_meta, preamble = "\0" * 128)
            ds.PatientName = "xxxxxxxxxxxxxxx" 
            ds.is_little_endian = True
            ds.is_implicit_VR = True
            ds.PatientID = "123456"
            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.8'
            print '[+] Complete Set FileDataset'
            #/////////////////////Fix-Pix\\\\\\\\\\\\\\\\\\\\  
            ds.PixelRepresentation = 0
            ds.BitsStored = 16
            ds.BitsAllocated = 16
            ds.Columns = pixel_array.shape[0]
            ds.Rows = pixel_array.shape[1]
            ds.PixelData = pixel_array.tostring()
            ds.save_as('p://aa.dcm')
            print '[+] Complete Set Picture Value '
        except :
            print '\t\t\t\t\t\t\t[-] Failed'
        return
##====================================== Main ==================================================
if __name__ == '__main__':
    d = Dicom()
    
    try:
        FileAddress = "p:/aa.dcm"
        src = Image.open("p://aa.jpg")
        pixel_array = numpy.asarray(src)

        d.Setting(pixel_array, FileAddress)
        
        os.system("pause")
    except:
        print "Error"
Please Help To Me To Solve Problem?
Thank you :P

waleeedijaz
Posts: 1
Joined: Wed Mar 02, 2016 6:55 am

Re: How Can Write Code With Python?

Post by waleeedijaz » Wed Mar 02, 2016 6:56 am

I Want to Write python script to Convert .jpg format to .dcm format ,, but When I compile the Script ,it Work bad.

__________________________
waleeed

Post Reply