Beispiel #1
0
    def show_ret(self, query, n_top=None, method='mean'):
        if n_top == None: n_top = self.n
        assert n_top <= self.n

        nn, dd = self.ret(query, n_top=n_top, return_distance=True)
        print("N: {}".format(nn))

        print([self.meta_data[n] for n in nn])
        print([
            calc_rating(self.meta_data[n],
                        nodule_ids=self.nod_ids[n],
                        method=method) for n in nn
        ])

        self.show('Query', self.images[query], self.labels[query],
                  self.meta_data[query], self.nod_ids[query])
        for idx in range(n_top):
            self.show('Ret#{} [d{:.2f}]'.format(idx, dd[idx]),
                      self.images[nn[idx]], self.labels[nn[idx]],
                      self.meta_data[nn[idx]], self.nod_ids[nn[idx]])

        if self.nod_ids[query] is not None:
            return self.meta_data[query], self.nod_ids[query]
        else:
            return self.meta_data[query]
Beispiel #2
0
    def show(self,
             title,
             image,
             label,
             rating=None,
             meta=None,
             plot_handle=None,
             nods=None):
        L = 'BMU'
        #ann = getAnnotation(meta)
        #ann.visualize_in_scan()
        #if nods is None:
        #    feature_vals = calc_rating(meta, method='single')
        #    print('single -> {}'.format(feature_vals))
        #else:
        feature_vals = calc_rating(
            meta, nodule_ids=nods) if rating is None else np.mean(rating,
                                                                  axis=0)
        print('mean ->: {}'.format(feature_vals))

        if plot_handle is None:
            plt.figure()
            plot_handle = plt.subplot(111)
        plot_handle.axes.title.set_text("{} - {} ({})".format(
            title, L[label],
            np.round(feature_vals).astype('int')))
        plot_handle.imshow(image, cmap='gray')
    def show(self,
             title,
             image,
             label,
             rating=None,
             meta=None,
             plot_handle=None,
             nods=None,
             full_text=True):
        L = 'BMU'
        #ann = getAnnotation(meta)
        #ann.visualize_in_scan()
        #if nods is None:
        #    feature_vals = calc_rating(meta, method='single')
        #    print('single -> {}'.format(feature_vals))
        #else:
        if rating is None:
            from LIDC.lidcUtils import calc_rating
        feature_vals = calc_rating(
            meta, nodule_ids=nods) if rating is None else np.mean(rating,
                                                                  axis=0)
        print('mean ->: {}'.format(feature_vals))

        if plot_handle is None:
            plt.figure()
            plot_handle = plt.subplot(111)
        plot_title = \
            "{} - {} ({})".format(title, L[label], np.round(feature_vals).astype('int')) if full_text \
                else "{} - {}".format(title, L[label])
        plot_handle.axes.title.set_text(plot_title)
        plot_handle.axes.get_xaxis().set_visible(False)
        plot_handle.axes.get_yaxis().set_visible(False)
        plot_handle.imshow(image, cmap='gray')
Beispiel #4
0
    def evaluate_rating_space(self, norm='none', ignore_labels=False):
        if np.concatenate(self.labels).ndim == 1 or ignore_labels:
            print('calc_from_meta')
            self.rating = [rating_normalize(calc_rating(meta, method='raw'), method=norm) for meta in self.meta_data]

        else:
            print('calc_from_labels')
            self.rating = [rating_normalize(lbl, method=norm) for lbl in self.labels]
        self.rating_distance_matrix = None  # reset after recalculating the ratings
Beispiel #5
0
 def load(self, name):
     if name is 'embed':
         xVec = self.embedding
     elif name is 'rating':
         xVec = np.array(self.rating)
     elif name is 'malig':
         xVec = [calc_rating(meta, 'malig') for meta in self.meta_data]
         xVec = np.array(xVec).reshape(-1, 1).astype('float64')
         xVec += 0.1*np.random.random([xVec.shape[0], xVec.shape[1]])
     else:
         assert False
     return xVec
Beispiel #6
0
    def show(self, title, image, label, meta, nods=None):
        L = 'BM'
        #ann = getAnnotation(meta)
        #ann.visualize_in_scan()
        #if nods is None:
        #    feature_vals = calc_rating(meta, method='single')
        #    print('single -> {}'.format(feature_vals))
        #else:
        feature_vals = calc_rating(meta, nodule_ids=nods)
        print('mean ->: {}'.format(feature_vals))

        plt.figure()
        plt.title("{} - {} ({})".format(title, L[label],
                                        np.round(feature_vals, 1)))
        plt.imshow(image, cmap='gray')
Beispiel #7
0
    def malig_regression(self, method = 'correlation'):
        #size = self.embed_distance_matrix.shape[0]
        malig_rating = [calc_rating(meta, 'malig') for meta in self.meta_data]
        malig_rating = np.array(malig_rating).reshape(-1,1)
        malig_rating_distance_matrix = calc_distance_matrix(malig_rating, method)

        malig_dist  = flatten_dm(malig_rating_distance_matrix)
        embed_dist  = flatten_dm(self.embed_distance_matrix)
        rating_dist = flatten_dm(self.rating_distance_matrix)

        plt.figure()
        plt.subplot(211)
        plt.title('embed-malig')
        plt.scatter(malig_dist, embed_dist, color='black')
        plt.subplot(212)
        plt.title('rating-malig')
        plt.scatter(malig_dist, rating_dist, color='black')
Beispiel #8
0
 def load_distance_matrix(self, name, flat=True):
     if name == 'embed':
         xVec = self.embed_distance_matrix
         xMet = self.embed_metric
     elif name == 'rating':
         xVec = self.rating_distance_matrix
         xMet = self.rating_metric
     elif name == 'malig':
         malig_rating = [
             calc_rating(meta, method='malig') for meta in self.meta_data
         ]
         malig_rating = np.array(malig_rating).reshape(-1,
                                                       1).astype('float64')
         xVec = calc_distance_matrix(malig_rating, method='euclidean')
         xMet = 'euclidean'
     else:
         assert False
     if flat:
         return flatten_dm(xVec), xMet
     else:
         return xVec, xMet
Beispiel #9
0
 def evaluate_rating_space(self, norm='none'):
     self.rating = [
         rating_normalize(calc_rating(meta, method='mean'), method=norm)
         for meta in self.meta_data
     ]
     self.rating_distance_matrix = None  # reset after recalculating the ratings