def __init__(self, staining_type, input_file, output_dir, training_type,
                 conf_threshold, annotation_dir, overlap_threshod):
        '''Merge when common area ratio of two individual rectangles is this threshold or more.'''
        self.OVERLAP_THRESHOLD = overlap_threshod
        '''When the common area ratios for both rectangles are equal to or more than this value,
        they are merged regardless of the size.'''
        self.UNCONDITIONAL_MERGE_THRESHOLD = 0.6
        '''If one side of rectangles is nearly the same, merge them regardless of their size.'''
        self.SIDE_LENGTH_MERGE_THRESHOLD = 30  # unit is micrometer
        '''The glomerulus diameter is assumed to be 350 micrometers at the maximum.
        If the merge result exceeds the following value, do not merge them.'''
        #self.MAX_GLOMUS_SIZE = 240.0
        #self.MAX_GLOMUS_AREA = 220.0 * 220.0
        self.MAX_GLOMUS_SIZE = 350.0
        self.MAX_GLOMUS_AREA = 300.0 * 300.0

        self.png = ['.png', '.PNG']
        self.rect_list = [[]]
        self.input_file = input_file
        self.output_dir = output_dir

        self.staining_type = staining_type
        self.staining_dir = GlomusHandler.get_staining_type(staining_type)
        self.training_type = training_type

        self.CONF_THRESH = conf_threshold

        self.annotation_dir = annotation_dir
        '''variable for opening ndpi image file for mpp value check.'''
        self.slide = None
        '''variable for recording mpp value of PNG image recorded in the target list file.'''
        self.target_list = {}
Пример #2
0
    def __init__(self, annotation_dir, staining_type):
        self.gt_list = []
        self.gt_name_list = []
        self.annotation_dir = annotation_dir
        self.staining_type = staining_type
        self.staining_dir = GlomusHandler.get_staining_type(self.staining_type)
        if self.staining_dir is None:
            raise AnnotationHandlerException('Unknown Argument is given.:' +
                                             self.staining_type)

        self.annotation_file_pattern = '(.*)_pw(\d{2})_ds(\d{1,2})'
        self.repattern = re.compile(self.annotation_file_pattern,
                                    re.IGNORECASE)

        self.set_sheet_index()
Пример #3
0
    def __init__(self, data_category, target_list, data_dir, output_dir, output_file_ext,
                 window_size, overlap_ratio, conf_threshold):
        """
        Class Initializer
        :param data_category: The symbol representing the observation and staining method.(write like "OPT_PAS")
        :param target_list: The path of text file in which the procession target file list is written.
        :param data_dir: The path of the file folder in which there are whole slide images.
        :param output_dir: The path of the file folder in which this process write output files.
        :param output_file_ext: This parameter is used to extend the result file name to distinguish execution results.
        :param window_size: The size of a sliding window for detection.
        :param overlap_ratio: The overlapping ration of the sliding windows.
        :param conf_threshold: The minimum confidence value of adopt for candidates ot region of glomerulus.
        """

        '''identifier of a image file type'''
        self.ndpi_image_ext = ['.ndpi']
        self.png_image_ext = ['.PNG', '.png']
        self.image_type = None

        '''The target file identifier is set according to the saining category.(set_type set in GlomusHander)'''
        self.data_category = data_category
        self.set_type(data_category)

        '''Sliding window size(The unit is micrometre.)'''
        if window_size is None or window_size == '':
            self.STD_SIZE = 500  # original -> 200
            self.OVERLAP_RATIO = 0.5
        else:
            self.STD_SIZE = window_size
            self.OVERLAP_RATIO = overlap_ratio

        self.COPY_EXEC = False

        self.CONF_THRESH = conf_threshold
        self.NMS_THRESH = 0.3

        self.CLASSES = ('__background__',  # always index 0
                        'glomerulus')

        self.staining_dir = GlomusHandler.get_staining_type(self.data_category)
        self.target_list = target_list
        self.data_dir = data_dir

        self.output_root_dir = output_dir
        '''Preparing a directory to write the output file'''
        head, _ = os.path.split(self.output_root_dir)
        head2, _ = os.path.split(head)
        if not os.path.isdir(head2):
            os.mkdir(head2)
        if not os.path.isdir(head):
            os.mkdir(head)
        if not os.path.isdir(self.output_root_dir):
            os.mkdir(self.output_root_dir)
        self.output_file_path = os.path.join(self.output_root_dir, self.TYPE + output_file_ext + '.csv')

        self.log_file = os.path.join(self.output_root_dir, self.TYPE + output_file_ext + '_log.csv')

        '''information of each slide'''
        self.org_slide_width = 0
        self.org_slide_height = 0
        self.org_slide_objective_power = 0.0
        self.slide_downsample = 0.0
        self.mpp_x = 0.0
        self.mpp_y = 0.0
Пример #4
0
    parser.add_argument('--overlap_ratio', dest='overlap_ratio', help="Please set --overlap_ratio", type=float)
    parser.add_argument('--conf_threshold', dest='conf_threshold', help="Please set --conf_threshold", type=float,
                        default=0.6)

    return parser.parse_args()


if __name__ == '__main__':
    print('Tensorflow version:{}'.format(tf.__version__))
    args = parse_args()

    # load network
    body, ext = os.path.splitext(os.path.basename(args.target_list))
    TEST_SET = body
    TRAIN_SET = body.replace('test', 'train')
    staining_dir = GlomusHandler.get_staining_type(args.data_category)
    TRAIN_MODEL = args.model
    PATH_TO_CKPT = os.path.join(args.model,  'frozen_inference_graph.pb')
    '''Load Tensorflow Model into Memory'''
    detection_graph = tf.Graph()
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')

    # init session
    # sess = tf.Session(config=tf.ConfigProto(allow_soft_placement=True))
    # The setting of visible_device_list does not work(?).
    # If you want to limit the GPU to be used, set the environment variable CUDA_VISIBLE_DEVICES to limit it.