Ejemplo n.º 1
0
 def onWIPButtonClicked(self):
   import urllib2
   reply = urllib2.urlopen('http://www.osa.sunysb.edu/erich.png')
   byte_array = reply.read()
   image = qt.QImage(qt.QImage.Format_RGB888)
   image.loadFromData(byte_array) 
   imageData = self.QImage2vtkImage(image)
   volumeNode = slicer.vtkMRMLVectorVolumeNode()
   volumeNode.SetName("WEB")
   volumeNode.SetAndObserveImageData(imageData)
   displayNode = slicer.vtkMRMLVectorVolumeDisplayNode()
   slicer.mrmlScene.AddNode(volumeNode)
   slicer.mrmlScene.AddNode(displayNode)
   volumeNode.SetAndObserveDisplayNodeID(displayNode.GetID())
   displayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeGrey')
   self.mutate() 
Ejemplo n.º 2
0
  def openTargetImage(self):
    import string
    p = self.v.page() 
    m = p.mainFrame()
    imageBound=m.evaluateJavaScript('viewer.viewport.viewportToImageRectangle(viewer.viewport.getBounds().x, viewer.viewport.getBounds().y, viewer.viewport.getBounds().width, viewer.viewport.getBounds().height)')
    x=imageBound[u'x']
    y=imageBound[u'y']
    width=imageBound[u'width']
    height=imageBound[u'height']
    self.j['x'] = x
    self.j['y'] = y
    self.j['width'] = width
    self.j['height'] = height
    imagedata = m.evaluateJavaScript('imagedata')
    tmpfilename=  imagedata[u'metaData'][1]
    imageFileName=string.rstrip(tmpfilename,'.dzi')
    self.tilename = imagedata[u'imageId']
    print self.tilename
    self.parameterNode.SetParameter("SlicerPathology,tilename", self.tilename)
    current_weburl ='http://quip1.uhmc.sunysb.edu/fcgi-bin/iipsrv.fcgi?IIIF=' + imageFileName +'/' + str(x) + ','+ str(y) + ',' + str(width) + ',' + str(height) + '/full/0/default.jpg'
    print current_weburl
    self.v.setUrl(qt.QUrl(current_weburl))
    self.v.show()

    reply = urllib2.urlopen(current_weburl)
    byte_array = reply.read()
    image = qt.QImage(qt.QImage.Format_RGB888)
    image.loadFromData(byte_array)
    imageData = self.QImage2vtkImage(image)
    volumeNode = slicer.vtkMRMLVectorVolumeNode()
    volumeNode.SetName("WEB")
    volumeNode.SetAndObserveImageData(imageData)
    displayNode = slicer.vtkMRMLVectorVolumeDisplayNode()
    slicer.mrmlScene.AddNode(volumeNode)
    slicer.mrmlScene.AddNode(displayNode)
    volumeNode.SetAndObserveDisplayNodeID(displayNode.GetID())
    displayNode.SetAndObserveColorNodeID('vtkMRMLColorTableNodeGrey')
    self.mutate()
Ejemplo n.º 3
0
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)
        self.logic = DataCollectionLogic()

        self.moduleDir = os.path.dirname(slicer.modules.datacollection.path)
        datasetDirectory = os.path.join(self.moduleDir, os.pardir, "Datasets")
        try:
            os.listdir(datasetDirectory)
        except FileNotFoundError:
            os.mkdir(datasetDirectory)

        #
        # Parameters Area
        #
        parametersCollapsibleButton = ctk.ctkCollapsibleButton()
        parametersCollapsibleButton.text = "Parameters"
        self.layout.addWidget(parametersCollapsibleButton)

        # Layout within the dummy collapsible button
        parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)

        #self.imageSaveDirectory = qt.QLineEdit("Select directory to save images")
        #parametersFormLayout.addRow(self.imageSaveDirectory)

        self.selectRecordingNodeComboBox = qt.QComboBox()
        self.selectRecordingNodeComboBox.addItems(["Select Image Node"])
        self.recordingNodes = slicer.util.getNodesByClass("vtkMRMLVolumeNode")
        recordingNodeNames = []
        for recordingNode in self.recordingNodes:
            recordingNodeNames.append(recordingNode.GetName())
        self.selectRecordingNodeComboBox.addItems(recordingNodeNames)
        parametersFormLayout.addRow(self.selectRecordingNodeComboBox)

        self.datasetSelector = qt.QComboBox()
        self.datasetSelector.addItems(["Select Dataset"])
        datasetDirectoryContents = os.listdir(
            os.path.join(self.moduleDir, os.pardir, "Datasets"))
        datasetNames = [
            dir for dir in datasetDirectoryContents if dir.find(".") == -1
        ]
        self.datasetSelector.addItems(["Create New Dataset"])
        self.datasetSelector.addItems(datasetNames)
        parametersFormLayout.addRow(self.datasetSelector)

        self.videoIDComboBox = qt.QComboBox()
        self.videoIDComboBox.addItems(
            ["Select video ID", "Create new video ID"])
        parametersFormLayout.addRow(self.videoIDComboBox)

        self.fileTypeComboBox = qt.QComboBox()
        self.fileTypeComboBox.addItems([".jpg", ".png", ".bmp", ".tiff"])
        parametersFormLayout.addRow(self.fileTypeComboBox)
        self.fileType = self.fileTypeComboBox.currentText

        self.collectFromSequenceCheckBox = qt.QCheckBox(
            "Collect from Sequence")
        self.collectingFromSequence = False
        parametersFormLayout.addRow(self.collectFromSequenceCheckBox)

        self.problemTypeComboBox = qt.QComboBox()
        self.problemTypeComboBox.addItems([
            "Select problem type", "Classification", "Detection",
            "Segmentation"
        ])
        parametersFormLayout.addRow(self.problemTypeComboBox)
        self.classificationFrame = qt.QFrame()
        self.classificationLayout()
        parametersFormLayout.addRow(self.classificationFrame)
        self.classificationFrame.visible = False
        self.detectionFrame = qt.QFrame()
        self.detectionLayout()
        parametersFormLayout.addRow(self.detectionFrame)
        self.detectionFrame.visible = False
        self.segmentationFrame = qt.QFrame()
        self.segmentationLayout()
        parametersFormLayout.addRow(self.segmentationFrame)
        self.segmentationFrame.visible = False

        #
        # Start/Stop Image Collection Button
        #
        self.startStopCollectingImagesButton = qt.QPushButton(
            "Start Image Collection")
        self.startStopCollectingImagesButton.toolTip = "Collect images."
        self.startStopCollectingImagesButton.enabled = False
        parametersFormLayout.addRow(self.startStopCollectingImagesButton)

        self.infoLabel = qt.QLabel("")
        parametersFormLayout.addRow(self.infoLabel)
        # connections
        self.fileTypeComboBox.connect('currentIndexChanged(int)',
                                      self.onFileTypeSelected)
        self.inputSegmentationSelector.connect(
            'currentIndexChanged(int)', self.onSegmentationInputSelected)
        self.selectRecordingNodeComboBox.connect("currentIndexChanged(int)",
                                                 self.onRecordingNodeSelected)
        self.datasetSelector.connect('currentIndexChanged(int)',
                                     self.onDatasetSelected)
        self.startStopCollectingImagesButton.connect(
            'clicked(bool)', self.onStartStopCollectingImagesButton)
        self.videoIDComboBox.connect('currentIndexChanged(int)',
                                     self.onVideoIDSelected)
        self.collectFromSequenceCheckBox.connect(
            'stateChanged(int)', self.onCollectFromSequenceChecked)
        self.problemTypeComboBox.connect('currentIndexChanged(int)',
                                         self.onProblemTypeSelected)

        # Add vertical spacer
        self.layout.addStretch(1)

        # Refresh Start/Stop Collecting Images Button state
        self.onSelect()
        try:
            self.webcamReference = slicer.util.getNode('Webcam_Reference')
        except slicer.util.MRMLNodeNotFoundException:
            #if not self.webcamReference:
            imageSpacing = [0.2, 0.2, 0.2]
            imageData = vtk.vtkImageData()
            imageData.SetDimensions(640, 480, 1)
            imageData.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
            thresholder = vtk.vtkImageThreshold()
            thresholder.SetInputData(imageData)
            thresholder.SetInValue(0)
            thresholder.SetOutValue(0)
            # Create volume node
            self.webcamReference = slicer.vtkMRMLVectorVolumeNode()
            self.webcamReference.SetName('Webcam_Reference')
            self.webcamReference.SetSpacing(imageSpacing)
            self.webcamReference.SetImageDataConnection(
                thresholder.GetOutputPort())
            # Add volume to scene
            slicer.mrmlScene.AddNode(self.webcamReference)
            displayNode = slicer.vtkMRMLVectorVolumeDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)
            self.webcamReference.SetAndObserveDisplayNodeID(
                displayNode.GetID())

        self.webcamConnectorNode = self.createWebcamPlusConnector()
        self.webcamConnectorNode.Start()
        self.setupWebcamResliceDriver()
  def setup(self):
    ScriptedLoadableModuleWidget.setup(self)
    self.logic = Collect_Training_ImagesLogic()

    self.moduleDir = os.path.dirname(slicer.modules.collect_training_images.path)

    #
    # Parameters Area
    #
    parametersCollapsibleButton = ctk.ctkCollapsibleButton()
    parametersCollapsibleButton.text = "Parameters"
    self.layout.addWidget(parametersCollapsibleButton)

    # Layout within the dummy collapsible button
    parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)

    #self.imageSaveDirectory = qt.QLineEdit("Select directory to save images")
    #parametersFormLayout.addRow(self.imageSaveDirectory)

    self.modelSelector = qt.QComboBox()
    self.modelSelector.addItems(["Select model"])
    modelDirectoryContents = os.listdir(os.path.join(self.moduleDir,os.pardir,"Models"))
    modelNames = [dir for dir in modelDirectoryContents if dir.find(".") == -1 and dir != "Dockerfile"]
    self.modelSelector.addItems(["Create new model"])
    self.modelSelector.addItems(modelNames)
    parametersFormLayout.addRow(self.modelSelector)

    #self.imageSaveDirectoryLabel = qt.QLabel("Training photo directory:")
    #parametersFormLayout.addRow(self.imageSaveDirectoryLabel)

    self.imageSaveDirectoryLineEdit = ctk.ctkPathLineEdit()
    #node = self.logic.getParameterNode()
    imageSaveDirectory = os.path.dirname(slicer.modules.collect_training_images.path)
    self.imageSaveDirectoryLineEdit.currentPath = imageSaveDirectory
    self.imageSaveDirectoryLineEdit.filters = ctk.ctkPathLineEdit.Dirs
    self.imageSaveDirectoryLineEdit.options = ctk.ctkPathLineEdit.DontUseSheet
    self.imageSaveDirectoryLineEdit.options = ctk.ctkPathLineEdit.ShowDirsOnly
    self.imageSaveDirectoryLineEdit.showHistoryButton = False
    self.imageSaveDirectoryLineEdit.setMinimumWidth(100)
    self.imageSaveDirectoryLineEdit.setMaximumWidth(500)
    #parametersFormLayout.addRow(self.imageSaveDirectoryLineEdit)

    self.imageClassComboBox = qt.QComboBox()
    self.imageClassComboBox.addItems(["Select image class","Create new image class"])

    parametersFormLayout.addRow(self.imageClassComboBox)

    #
    # Start/Stop Image Collection Button
    #
    self.startStopCollectingImagesButton = qt.QPushButton("Start Image Collection")
    self.startStopCollectingImagesButton.toolTip = "Collect training images."
    self.startStopCollectingImagesButton.enabled = False
    parametersFormLayout.addRow(self.startStopCollectingImagesButton)


    self.infoLabel = qt.QLabel("")
    parametersFormLayout.addRow(self.infoLabel)

    # connections
    self.modelSelector.connect('currentIndexChanged(int)',self.onModelSelected)
    self.startStopCollectingImagesButton.connect('clicked(bool)', self.onStartStopCollectingImagesButton)
    self.imageClassComboBox.connect('currentIndexChanged(int)',self.onImageClassSelected)

    # Add vertical spacer
    self.layout.addStretch(1)

    # Refresh Start/Stop Collecting Images Button state
    self.onSelect()
    try:
      self.webcamReference = slicer.util.getNode('Webcam_Reference')
    except slicer.util.MRMLNodeNotFoundException:
    #if not self.webcamReference:
      imageSpacing = [0.2, 0.2, 0.2]
      imageData = vtk.vtkImageData()
      imageData.SetDimensions(640, 480, 1)
      imageData.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
      thresholder = vtk.vtkImageThreshold()
      thresholder.SetInputData(imageData)
      thresholder.SetInValue(0)
      thresholder.SetOutValue(0)
      # Create volume node
      self.webcamReference = slicer.vtkMRMLVectorVolumeNode()
      self.webcamReference.SetName('Webcam_Reference')
      self.webcamReference.SetSpacing(imageSpacing)
      self.webcamReference.SetImageDataConnection(thresholder.GetOutputPort())
      # Add volume to scene
      slicer.mrmlScene.AddNode(self.webcamReference)
      displayNode = slicer.vtkMRMLVectorVolumeDisplayNode()
      slicer.mrmlScene.AddNode(displayNode)
      self.webcamReference.SetAndObserveDisplayNodeID(displayNode.GetID())

    self.webcamConnectorNode = self.createWebcamPlusConnector()
    self.webcamConnectorNode.Start()
    self.setupWebcamResliceDriver()
Ejemplo n.º 5
0
    def setup(self):
        ScriptedLoadableModuleWidget.setup(self)
        self.logic = CNN_Image_ClassifierLogic()
        self.moduleDir = os.path.dirname(
            slicer.modules.collect_training_images.path)

        # Instantiate and connect widgets ...

        #
        # Parameters Area
        #
        parametersCollapsibleButton = ctk.ctkCollapsibleButton()
        parametersCollapsibleButton.text = "Parameters"
        self.layout.addWidget(parametersCollapsibleButton)

        # Layout within the dummy collapsible button
        parametersFormLayout = qt.QFormLayout(parametersCollapsibleButton)

        self.modelSelector = qt.QComboBox()
        self.modelSelector.addItems(["Select model"])
        modelDirectoryContents = os.listdir(
            os.path.join(self.moduleDir, os.pardir, "Models/retrainContainer"))
        modelNames = [
            dir for dir in modelDirectoryContents
            if dir.find(".") == -1 and dir != "Dockerfile"
        ]
        self.modelSelector.addItems(["Create new model"])
        self.modelSelector.addItems(modelNames)
        parametersFormLayout.addRow(self.modelSelector)

        #
        # Apply Button
        #
        self.applyButton = qt.QPushButton("Start")
        self.applyButton.toolTip = "Run the algorithm."
        self.applyButton.enabled = False
        parametersFormLayout.addRow(self.applyButton)

        #
        # Object table
        #
        self.objectTable = qt.QTableWidget()
        self.objectTable.setColumnCount(3)
        self.objectTable.setHorizontalHeaderLabels(
            ["Name", "Found", "Confidence"])
        parametersFormLayout.addRow(self.objectTable)

        #
        # Adjust Confidence Thresholds
        #
        confidenceThresholdsCollapsibleButton = ctk.ctkCollapsibleButton()
        confidenceThresholdsCollapsibleButton.text = "Confidence Thresholds"
        self.layout.addWidget(confidenceThresholdsCollapsibleButton)

        confidenceFormLayout = qt.QFormLayout(
            confidenceThresholdsCollapsibleButton)

        self.confidenceSlider = qt.QSlider(0x1)  #horizontal slider
        self.confidenceSlider.setRange(0, 100)
        self.confidenceSlider.setTickInterval(5)
        self.confidenceSlider.setTickPosition(2)  #Ticks appear below slider
        self.confidenceSlider.setSliderPosition(80)
        self.confidenceSlider.setToolTip(
            "Set the minimum degree of confidence that must be met for an object to be considered found"
        )
        confidenceFormLayout.addRow("Confidence: ", self.confidenceSlider)
        self.confidenceLabel = qt.QLabel("80%")
        confidenceFormLayout.addRow(self.confidenceLabel)

        # connections
        self.applyButton.connect('clicked(bool)', self.onApplyButton)
        self.modelSelector.connect('currentIndexChanged(int)',
                                   self.onModelSelected)
        self.confidenceSlider.connect('sliderMoved(int)',
                                      self.onConfidenceChanged)

        # Add vertical spacer
        self.layout.addStretch(1)

        # Refresh Apply button state
        self.onSelect()

        self.webcamReference = slicer.util.getNode('Webcam_Reference')
        if not self.webcamReference:
            imageSpacing = [0.2, 0.2, 0.2]
            imageData = vtk.vtkImageData()
            imageData.SetDimensions(640, 480, 1)
            imageData.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1)
            thresholder = vtk.vtkImageThreshold()
            thresholder.SetInputData(imageData)
            thresholder.SetInValue(0)
            thresholder.SetOutValue(0)
            # Create volume node
            self.webcamReference = slicer.vtkMRMLVectorVolumeNode()
            self.webcamReference.SetName('Webcam_Reference')
            self.webcamReference.SetSpacing(imageSpacing)
            self.webcamReference.SetImageDataConnection(
                thresholder.GetOutputPort())
            # Add volume to scene
            slicer.mrmlScene.AddNode(self.webcamReference)
            displayNode = slicer.vtkMRMLVectorVolumeDisplayNode()
            slicer.mrmlScene.AddNode(displayNode)
            self.webcamReference.SetAndObserveDisplayNodeID(
                displayNode.GetID())

        self.webcamConnectorNode = self.createWebcamPlusConnector()
        self.webcamConnectorNode.Start()
        self.setupWebcamResliceDriver()