| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 
 |  
from Tkinter import *
import struct
import numpy
import matplotlib.pyplot as plt
import math
from PIL import Image,ImageTk
 
 
 
#Reglages de la fenetre
fenetreseg=Tk()
frameImageseg = LabelFrame(fenetreseg, text="")
frameImageseg.pack(side = LEFT,fill="both", expand="yes")
frameBoutonseg = LabelFrame(frameImageseg, text="Images segmentée",width=512, height=60)
frameBoutonseg.pack(side = BOTTOM,fill="both", expand="yes")
canvasDicomseg = Canvas(frameImageseg, width=100, height=100, bg='ivory')
canvasDicomseg.pack(side=TOP, padx=5, pady=5)
 
 
 
#Ouverture et lecture des images en binaire
pathopen="C:/Users/pc/Documents/Projet2015/lesfichiersok"
f = open (pathopen+"/slicesseg2.dat", "rb")
cote1=100
cote2=100
coupe=numpy.zeros([cote1,cote2])
i=0
j=0
 
try:
    while i<cote1-1:
        data = f.read(4) # read the next /byte/
        if data == "":
            break;
        string=str(struct.unpack('i', data))
        string=string.replace("(","")
        string=string.replace(",","")
        string=string.replace(")","")
        coupe[i,j]=int(string)
        if j==cote2-1:
            j=0
            i=i+1
        j=j+1
 
 
except IOError:
    # The error handling here
    # Nothing for this example
    pass
finally:
    f.close()
 
 
#Affichage de l'image lue dans le canavas et sous pyplot
imseg = Image.fromarray(coupe)
imseg = imseg.resize((500,500), Image.ANTIALIAS)
photoseg=ImageTk.PhotoImage(imseg)
canvasDicomseg.config(width=photoseg.width(), height=photoseg.height())
imageseg = canvasDicomseg.create_image(0, 0, anchor=NW, image=photoseg)
plt.figure()                                     
plt.imshow(coupe[:,:],cmap='gray')
plt.show()
 
fenetreseg.mainloop() |