Пример #1
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')
Пример #2
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')