资源简介

使用python 自带的Tkinter编写的小工具,能够打开医学图像dicom或ima格式,显示两幅图像,并且计算感兴趣区域的均值和方差

资源截图

代码片段和文件信息

#-*-coding:utf-8 -*-
import dicom
import Tkinter
import tkFileDialog
import numpy as np
from PIL import ImageImageTk
import os

rec1=None
rec2=None

class calculate(object):
    Top=None
    file1=None
    file2=None
    def __init__(self):
        self.Top=Tkinter.Tk()
        self.Top.title(‘calculate mean of ROI‘)
        self.Menu=Tkinter.Menu(self.Top)
        self.Top.config(menu=self.Menu)
        self.Menu.add_command(label=‘OpenDicom‘command=self.OnButtonOpen)
        self.Menu.add_command(label=‘OpenAnotherDicom‘command=self.OnButtonOpenAnother)
        self.Menu.add_command(label=‘InputDicomPath‘command=self.OnInputDicomPath)
        self.Menu.add_command(label=‘calculate‘command=self.compute)
        self.Menu.add_command(label=‘Quit‘command=self.OnQuit)

        self.Dframe=Tkinter.frame(self.Top)
        self.Dframe.pack(fill=Tkinter.X)
        self.Canvas=Tkinter.Canvas(self.Dframewidth=512height=512)
        self.Canvas.pack(side=Tkinter.LEFTfill=Tkinter.Y)
        self.Canvas.bind(‘‘self.OnLeftMouseClick)
        self.Canvas.bind(‘‘self.onmousemove)
        self.Canvas2=Tkinter.Canvas(self.Dframewidth=512height=512)
        self.Canvas2.pack(side=Tkinter.LEFTfill=Tkinter.Y)

        self.variab1=Tkinter.StringVar(self.Top)
        self.label1=Tkinter.Entry(self.Toptextvariable=self.variab1width=160)


        self.label1.pack(side=Tkinter.LEFT)


    def OnButtonOpen(self):
        OpenFileName=tkFileDialog.askopenfilename()
        self.file1=dicom.read_file(OpenFileName).pixel_array.astype(np.float32)
        self.image1=ImageTk.PhotoImage(Image.fromarray(self.file1))
        self.Canvas.create_image(00image=self.image1anchor=Tkinter.NW)
        self.variab1.set(‘‘)
    def OnButtonOpenAnother(self):
        OpenFileName=tkFileDialog.askopenfilename()
        self.file2=dicom.read_file(OpenFileName).pixel_array.astype(np.float32)
        self.image2=ImageTk.PhotoImage(Image.fromarray(self.file2))
        self.Canvas2.create_image(00image=self.image1anchor=Tkinter.NW)
        self.variab1.set(‘‘)

    def OnInputDicomPath(selfev=None):
        top=Tkinter.Toplevel()
        self.TopDialog=top
        StringVar1=Tkinter.StringVar(top)
        StringVar2=Tkinter.StringVar(top)
        StringVar3=Tkinter.StringVar(top)
        label_in=Tkinter.Label(toptext=‘inputdir1:‘)
        label1=Tkinter.Entry(toptextvariable=StringVar1)
        label_in2=Tkinter.Label(toptext=‘inputdir2:‘)
        label2=Tkinter.Entry(toptextvariable=StringVar2)
        label_in3=Tkinter.Label(toptext=‘index‘)
        label3=Tkinter.Entry(toptextvariable=StringVar3)
        label_in.pack()
        label1.pack()
        label_in2.pack()
        label2.pack()
        label_in3.pack()
        label3.pack()
        def get_name(ev=Nonelabel1=label1label2=label2label3=label3self=self):
            dirname=label1.get()
            if os.path.exists(dirname):
                if os.path.isdir(dirname):
          

评论

共有 条评论