Ejemplo n.º 1
0
 def __init__(self, mainWindow=None, histologyAnalyser=None):
     self.mainWindow = mainWindow
     self.ha = histologyAnalyser
     
     self.hr = HistologyReport()
     self.hr.data = self.ha.stats
     self.hr.generateStats()
     
     QDialog.__init__(self)
     self.initUI()
     
     self.mainWindow.setStatusBarText('Finished')
Ejemplo n.º 2
0
def processData(args):
    """
    Processing data without gui
    """
    inputfile=args.inputfile
    threshold=args.threshold
    mask_file=args.maskfile
    crop=args.crop
    voxelsize=args.voxelsize
    binaryClosing=args.binaryopening
    binaryOpening=args.binaryclosing
    
    # Reading/Generating data
    if inputfile is None:  # # Using generated sample data
        logger.info('Generating sample data...')
        metadata = {'voxelsize_mm': [1, 1, 1]}
        data3d = generate_sample_data(1, 0, 0)
    else:  # Normal runtime
        dr = datareader.DataReader()
        data3d, metadata = dr.Get3DData(inputfile)

    # Custom voxel size
    if voxelsize is not None:
        metadata['voxelsize_mm'] = voxelsize

    # Crop data
    if crop is not None:
        logger.debug('Croping data: %s', str(crop))
        data3d = data3d[crop[0]:crop[1], crop[2]:crop[3], crop[4]:crop[5]].copy()

    # Init HistologyAnalyser object
    logger.debug('Init HistologyAnalyser object')
    ha = HistologyAnalyser(data3d, metadata, threshold, 
             binaryClosing=binaryClosing, binaryOpening=binaryOpening, 
             nogui=True)

    # Remove Area = Load mask from file
    if mask_file is not None:
        logger.debug('Loading mask from file...')
        mask = misc.obj_from_file(filename=mask_file, filetype='pickle')
        if ha.data3d.shape == mask.shape:
            ha.data3d_masked = mask
            ha.data3d[mask == 0] = np.min(ha.data3d)
        else:
            raise ValueError('Mask file has wrong dimensions '+str(mask.shape))
    
    # Segmentation
    logger.debug('Segmentation')
    ha.data_to_skeleton()

    # Computing statistics
    logger.info("# ## ## ## ## statistics")
    ha.data_to_statistics()

    # Saving files
    logger.info("# ## ## write stats to file")
    ha.writeStatsToCSV()
    ha.writeStatsToYAML()
    
    # ## Histology report
    logger.info("# ## ## Histology report")
    hr = HistologyReport()
    hr.data = ha.stats
    hr.generateStats()
    hr.writeReportToCSV()
    hr.writeReportToYAML()
    
    # Add results Record
    if crop is not None:
        label = str(crop[0])+"-"+str(crop[1])
    else:
        label = "0-end"
    if inputfile is None:
        hr.addResultsRecord(label=label)
    else:
        hr.addResultsRecord(label=label, datapath=inputfile)

    # ## End
    logger.info('Finished')
Ejemplo n.º 3
0
class StatsResultDialog(QDialog):
    def __init__(self, mainWindow=None, histologyAnalyser=None):
        self.mainWindow = mainWindow
        self.ha = histologyAnalyser
        
        self.hr = HistologyReport()
        self.hr.data = self.ha.stats
        self.hr.generateStats()
        
        QDialog.__init__(self)
        self.initUI()
        
        self.mainWindow.setStatusBarText('Finished')
    
    def initUI(self):
        self.ui_gridLayout = QGridLayout()
        self.ui_gridLayout.setSpacing(15)

        rstart = 0
        
        font_info = QFont()
        font_info.setBold(True)
        font_info.setPixelSize(20)
        label = QLabel('Finished')
        label.setFont(font_info)
        
        self.ui_gridLayout.addWidget(label, rstart + 0, 0, 1, 1)
        rstart +=1
        
        ### histology report
        report = self.hr.stats['Report']
        report_label = QLabel('Total length mm: '+str(report['Total length mm'])+'\n'
                        +'Avg length mm: '+str(report['Avg length mm'])+'\n'
                        +'Avg radius mm: '+str(report['Avg radius mm'])
                        )
        histogram_radius = HistogramMplCanvas(report['Radius histogram'][0],
                                        report['Radius histogram'][1],
                                        title='Radius histogram',
                                        xlabel="Blood-vessel radius [mm]",
                                        ylabel="Number"
                                        )
        histogram_length = HistogramMplCanvas(report['Length histogram'][0],
                                        report['Length histogram'][1],
                                        title='Length histogram',
                                        xlabel="Blood-vessel length [mm]",
                                        ylabel="Number"
                                        )
        
        self.ui_gridLayout.addWidget(report_label, rstart + 0, 0, 1, 3)
        self.ui_gridLayout.addWidget(histogram_radius, rstart + 1, 0, 1, 3)
        self.ui_gridLayout.addWidget(histogram_length, rstart + 2, 0, 1, 3)
        rstart +=3
        
        ### buttons
        btn_yaml = QPushButton("Write statistics to YAML", self)
        btn_yaml.clicked.connect(self.writeYAML)
        btn_csv = QPushButton("Write statistics to CSV", self)
        btn_csv.clicked.connect(self.writeCSV)
        btn_rep_yaml = QPushButton("Write report to YAML", self)
        btn_rep_yaml.clicked.connect(self.writeReportYAML)
        btn_rep_csv = QPushButton("Write report to CSV", self)
        btn_rep_csv.clicked.connect(self.writeReportCSV)
        
        self.ui_gridLayout.addWidget(btn_yaml, rstart + 0, 0)
        self.ui_gridLayout.addWidget(btn_csv, rstart + 0, 1)
        self.ui_gridLayout.addWidget(btn_rep_yaml, rstart + 1, 0)
        self.ui_gridLayout.addWidget(btn_rep_csv, rstart + 1, 1)
        rstart +=2
        
        ### Stretcher
        self.ui_gridLayout.addItem(QSpacerItem(0,0), rstart + 0, 0,)
        self.ui_gridLayout.setRowStretch(rstart + 0, 1)
        rstart +=1
        
        ### Setup layout
        self.setLayout(self.ui_gridLayout)
        self.show()
    
    def writeYAML(self):
        # TODO - choose save path
        logger.info("Writing statistics YAML file")
        self.mainWindow.setStatusBarText('Statistics - writing YAML file')
        self.ha.writeStatsToYAML()
        self.mainWindow.setStatusBarText('Ready')
    
    def writeCSV(self):
        # TODO - choose save path
        logger.info("Writing statistics CSV file")
        self.mainWindow.setStatusBarText('Statistics - writing CSV file')
        self.ha.writeStatsToCSV()
        self.mainWindow.setStatusBarText('Ready')
        
    def writeReportYAML(self):
        # TODO - choose save path
        logger.info("Writing report YAML file")
        self.mainWindow.setStatusBarText('Report - writing YAML file')
        self.hr.writeReportToYAML()
        self.mainWindow.setStatusBarText('Ready')
        
    def writeReportCSV(self):
        # TODO - choose save path
        logger.info("Writing report CSV file")
        self.mainWindow.setStatusBarText('Report - writing CSV file')
        self.hr.writeReportToCSV()
        self.mainWindow.setStatusBarText('Ready')
Ejemplo n.º 4
0
    def test_synthetic_data_vessel_tree_evaluation(self):
        """
        Generovani umeleho stromu do 3D a jeho evaluace.
        V testu dochazi ke kontrole predpokladaneho objemu a deky cev


        """
        from gen_volume_tree import TreeVolumeGenerator
        from histology_analyser import HistologyAnalyser
        from histology_report import HistologyReport
        import segmentation
        import misc
        
        # generate 3d data from yaml for testing
        tvg = TreeVolumeGenerator()
        yaml_path = os.path.join(path_to_script, "./hist_stats_test.yaml")
        tvg.importFromYaml(yaml_path)
        tvg.voxelsize_mm = [1,1,1]
        tvg.shape = [100,100,100]
        tvg.generateTree()
        
        # init histology Analyser
        metadata = {'voxelsize_mm': tvg.voxelsize_mm}
        data3d = tvg.data3d*10
        threshold = 2.5
        ha = HistologyAnalyser(data3d, metadata, threshold)
        
        # modifited ha.data_to_skeleton() function
        data3d_thr = segmentation.vesselSegmentation(
            data3d,
            segmentation=np.ones(tvg.data3d.shape, dtype='int8'),
            threshold=threshold,
            inputSigma=0.15,
            dilationIterations=2,
            nObj=1,
            biggestObjects=False,
            interactivity=False,
            binaryClosingIterations=5,
            binaryOpeningIterations=1)
        data3d_skel = ha.binar_to_skeleton(data3d_thr)
        
        # get statistics
        ha.skeleton_to_statistics(data3d_thr, data3d_skel)
        yaml_new = "hist_stats_new.yaml"
        ha.writeStatsToYAML(filename=yaml_new)
        
        # get histology reports
        hr = HistologyReport()
        hr.importFromYaml(yaml_path)
        hr.generateStats()
        stats_orig = hr.stats
        
        hr = HistologyReport()
        hr.importFromYaml(os.path.join(path_to_script, yaml_new))
        hr.generateStats()
        stats_new = hr.stats
        
        # compare
        self.assertGreater(stats_orig['Total length mm'],stats_new['Total length mm']*0.9)
        self.assertLess(stats_orig['Total length mm'],stats_new['Total length mm']*1.1)
        
        self.assertGreater(stats_orig['Avg length mm'],stats_new['Avg length mm']*0.9)
        self.assertLess(stats_orig['Avg length mm'],stats_new['Avg length mm']*1.1)
        
        self.assertGreater(stats_orig['Avg radius mm'],stats_new['Avg radius mm']*0.9)
        self.assertLess(stats_orig['Avg radius mm'],stats_new['Avg radius mm']*1.1)