def OnlistboxClick(self, event):
        lstbx = event.widget
        selection=lstbx.curselection()
        if len(selection) > 0:
            value = lstbx.get(selection[0])
            #print "selection:", selection, ": '%s'" % value
            full_file_name = self.dicom_file_path + "/" + value
            self.dicom_data = dicom.read_file(full_file_name)

            dicom_img_data = DicomImgData(self.dicom_data)
            
            w_ratio = dicom_img_data.pixel_array.shape[1]/self.canvas_shape[1]
            h_ratio = dicom_img_data.pixel_array.shape[0]/self.canvas_shape[0]

            if ((h_ratio > 1) or (w_ratio > 1) ):

                if (w_ratio > h_ratio):
                    new_sz = (int(dicom_img_data.pixel_array.shape[1]/w_ratio),
                              int(dicom_img_data.pixel_array.shape[0]/w_ratio))
                else:
                    new_sz = (int(dicom_img_data.pixel_array.shape[1]/h_ratio),
                              int(dicom_img_data.pixel_array.shape[0]/h_ratio))                          
                dicom_img_data.pixel_array = cv2.resize(dicom_img_data.pixel_array, new_sz)

            self.dicom_photo_ref = pydicom_Tkinter.get_tkinter_photoimage_from_pydicom_image(dicom_img_data)
            
            if self.dicom_img_first:
                self.dicom_on_canvas = self.canvas.create_image(0,0,anchor='nw', image=self.dicom_photo_ref)
                self.dicom_img_first = False
            else:
                self.canvas.itemconfig(self.dicom_on_canvas, image=self.dicom_photo_ref)
                
        pass
Ejemplo n.º 2
0
    def loadFile(self):
        """
        Loads single DICOM image into the Tkinter python GUI, Zooms the image according to the space in the canvas
        
        Note: cannot load a stack of DICOM images

        Args: none

        Returns: nothing

        """

        self.removeAllWidgets()

        # Open file with dialog
        dicomImage = tkFileDialog.askopenfilename(
            initialdir="C:\"",
            title="choose DICOM file",
            filetypes=(("DICOM files", "*.dcm"), ("all files", "*.*")))

        # Read file into pydicom
        dFile = dicom.read_file(dicomImage)

        # Get the Tkinter photo image with pydicom_Tkinter
        dicomImage = pydicom_Tkinter.get_tkinter_photoimage_from_pydicom_image(
            dFile)

        # Zoom the photo image to match the window by rescaling for the longest side
        helperFunctions = HelperFunctions()
        self.zoomScale = helperFunctions.getZoomScale(
            dicomImage.width(), dicomImage.height(), self.canvas.winfo_width(),
            self.canvas.winfo_height())
        displayImage = dicomImage.subsample(self.zoomScale, self.zoomScale)
        self.scaledImageWidth = dicomImage.width() / self.zoomScale
        self.scaledImageHeight = dicomImage.height() / self.zoomScale

        # Update DICOM loaded property
        self.isDicomLoaded = True

        # Display image in canvas
        image1 = self.canvas.create_image(0, 0, image=displayImage, anchor=NW)
        self.mainloop()
Ejemplo n.º 3
0
    def OnlistboxClick(self, event):
        lstbx = event.widget
        selection = lstbx.curselection()
        if len(selection) > 0:
            value = lstbx.get(selection[0])
            #print "selection:", selection, ": '%s'" % value
            full_file_name = self.dicom_file_path + "/" + value
            self.dicom_data = dicom.read_file(full_file_name)

            dicom_img_data = DicomImgData(self.dicom_data)

            w_ratio = dicom_img_data.pixel_array.shape[1] / self.canvas_shape[1]
            h_ratio = dicom_img_data.pixel_array.shape[0] / self.canvas_shape[0]

            if ((h_ratio > 1) or (w_ratio > 1)):

                if (w_ratio > h_ratio):
                    new_sz = (int(dicom_img_data.pixel_array.shape[1] /
                                  w_ratio),
                              int(dicom_img_data.pixel_array.shape[0] /
                                  w_ratio))
                else:
                    new_sz = (int(dicom_img_data.pixel_array.shape[1] /
                                  h_ratio),
                              int(dicom_img_data.pixel_array.shape[0] /
                                  h_ratio))
                dicom_img_data.pixel_array = cv2.resize(
                    dicom_img_data.pixel_array, new_sz)

            self.dicom_photo_ref = pydicom_Tkinter.get_tkinter_photoimage_from_pydicom_image(
                dicom_img_data)

            if self.dicom_img_first:
                self.dicom_on_canvas = self.canvas.create_image(
                    0, 0, anchor='nw', image=self.dicom_photo_ref)
                self.dicom_img_first = False
            else:
                self.canvas.itemconfig(self.dicom_on_canvas,
                                       image=self.dicom_photo_ref)

        pass
Ejemplo n.º 4
0
    def loadFile(self):
        """
        Loads single DICOM image into the Tkinter python GUI, Zooms the image according to the space in the canvas
        
        Note: cannot load a stack of DICOM images

        Args: none

        Returns: nothing

        """

        self.removeAllWidgets()

        # Open file with dialog
        dicomImage = tkFileDialog.askopenfilename(initialdir = "C:\"", title = "choose DICOM file", filetypes = (("DICOM files","*.dcm"),("all files","*.*")))
        
        # Read file into pydicom
        dFile = dicom.read_file(dicomImage)

        # Get the Tkinter photo image with pydicom_Tkinter
        dicomImage = pydicom_Tkinter.get_tkinter_photoimage_from_pydicom_image(dFile)
        
        # Zoom the photo image to match the window by rescaling for the longest side
        helperFunctions = HelperFunctions()
        self.zoomScale = helperFunctions.getZoomScale(dicomImage.width(), dicomImage.height(), self.canvas.winfo_width(), self.canvas.winfo_height())
        displayImage = dicomImage.subsample(self.zoomScale, self.zoomScale)
        self.scaledImageWidth = dicomImage.width() / self.zoomScale
        self.scaledImageHeight = dicomImage.height() / self.zoomScale

        # Update DICOM loaded property
        self.isDicomLoaded = True

        # Display image in canvas
        image1 = self.canvas.create_image(0, 0, image = displayImage, anchor=NW)
        self.mainloop()