Example #1
0
  def read_ppm(self, rawfilename, filename):
    # This function reads the ppm/jpg file and extracts the features if the 
    # features pkl file doesn't exist. It is also compatible for extension 
    # of the feauture vector and doesn't compute the already computed features

    new_feature_string = []
    updated_feature = 0
    data = N.array([], dtype=int)
    if os.path.exists(filename):
      pkl_f = open(filename, 'r')
      (data, labels, feature_string, width, height, winsize, nbins)= pickle.load(pkl_f)
      self.winsize = winsize
      self.nbins = nbins
      new_feature_string = list(feature_string)
      pkl_f.close()      

    if not new_feature_string.count('dsift'):
      updated_feature = 1
      (sift_features, labels, width, height) = self.extract_dsift(rawfilename, self.winsize, self.nbins)
      if data.size:
        data = scipy.concatenate((data.transpose(), sift_features.transpose()), 1).transpose()
      else:
        data = sift_features
      new_feature_string.append('dsift')

    if not new_feature_string.count('histogram'):
      updated_feature = 1 
      (hist_features, labels, width, height) = self.extract_hist(rawfilename, self.winsize, self.nbins)
      hist_features = hist_features/(self.winsize)
      if data.size:
        data = scipy.concatenate((data.transpose(), hist_features.transpose()), 1).transpose()
      else:
        data = hist_features
      new_feature_string.append('histogram')

    '''
    if not new_feature_string.count('position'):
      updated_feature = 1 
      
      position_features = []
      for label in labels:
        (y,x) = map(int, label.strip('()').split(','))
        position_features.append([x,y]) 
      position_features = N.array(position_features)
    
      if data.size:
        data = scipy.concatenate((data.transpose(), position_features), 1).transpose()
      else:
        data = position_features
      new_feature_string.append('position')
    '''
    if updated_feature:
      outf = open(filename, 'w')
      pickle.dump((data, labels, new_feature_string, width, height, self.winsize, self.nbins),outf)
      outf.close()
      print 'Saved data to %s.' % filename
    
    return (data, labels, new_feature_string, width, height, self.winsize, self.nbins)
Example #2
0
  def si_read_ppm(self, rawfilename, filename):
    # This function reads the ppm/jpg file and extracts the features if the 
    # features pkl file doesn't exist. It is also compatible for extension 
    # of the feauture vector and doesn't compute the already computed features

    new_feature_string = []
    updated_feature = 0
    data = N.array([], dtype=int)
    if os.path.exists(filename):
      pkl_f = open(filename, 'r')
      (data, labels, feature_string, width, height, winsize, nbins)= pickle.load(pkl_f)
      self.winsize = winsize
      self.nbins = nbins
      new_feature_string = list(feature_string)
      pkl_f.close()      

    if not new_feature_string.count('sift'):
      updated_feature = 1
      (sift_features, labels, width, height) = self.extract_sift(rawfilename, self.winsize, self.nbins)

      if data.size:
        data = scipy.concatenate((data.transpose(), sift_features.transpose()), 1).transpose()
      else:
        data = sift_features
      new_feature_string.append('sift')

    if updated_feature:
      outf = open(filename, 'w')
      pickle.dump((data, labels, new_feature_string, width, height, self.winsize, self.nbins),outf)
      outf.close()
      print 'Saved data to %s.' % filename
    
    return (data, labels, new_feature_string, width, height, self.winsize, self.nbins)
Example #3
0
def runAOD(img):
    model = 'AOD_Net.caffemodel'

    net = caffe.Net('DeployT.prototxt', model, caffe.TEST)
    batchdata = []
    data = img / 255.0
    data = data.transpose((2, 0, 1))
    batchdata.append(data)
    net.blobs['data'].data[...] = batchdata

    net.forward()

    data = net.blobs['sum'].data[0]
    data = data.transpose((1, 2, 0))
    data = data * 255.0
    return data.astype(np.uint8)
Example #4
0
def plot_image(path):
    fig = go.Figure();
#     plt.figure(figsize=(12, 12));
    # path = image_fetcher.fetch('data/cells.tif')
    # path = image_fetcher.fetch('data/cells.tif')
    try:
        if path != None:
            path = path
    except:
        print(f"Default image:")
        path = 'ะก:/Users/Admin/Documents/JN/NN/COVID_detection_picture/MRI/sick_7c7160149aec1ebf15b28166f5458c49.nii'
#     print(type(path))
    data = nib.load(path);
    print(type(data))
    
    data = data.get_data();
    print(type(data[0]), data[0].shape)
    data = data.transpose(2,1,0)
    print(type(data), data.shape)
    
    data = ndimage.zoom(data, (1, 1, 1), order = 1)
    print(data.shape)
    img = data[:]
    fig = px.imshow(img, 
                    animation_frame = 0, 
                    binary_string = True, 
                    labels = dict(animation_frame = "slice"),    
                    width = 512,
                    height = 512, 
#                     title = "NIFTI Detection scanner"
                   )
#     fig.show()    
    return fig
Example #5
0
    def si_read_ppm(self, rawfilename, filename):
        # This function reads the ppm/jpg file and extracts the features if the
        # features pkl file doesn't exist. It is also compatible for extension
        # of the feauture vector and doesn't compute the already computed features

        new_feature_string = []
        updated_feature = 0
        data = N.array([], dtype=int)
        if os.path.exists(filename):
            pkl_f = open(filename, 'r')
            (data, labels, feature_string, width, height, winsize,
             nbins) = pickle.load(pkl_f)
            self.winsize = winsize
            self.nbins = nbins
            new_feature_string = list(feature_string)
            pkl_f.close()

        if not new_feature_string.count('sift'):
            updated_feature = 1
            (sift_features, labels, width,
             height) = self.extract_sift(rawfilename, self.winsize, self.nbins)

            if data.size:
                data = scipy.concatenate(
                    (data.transpose(), sift_features.transpose()),
                    1).transpose()
            else:
                data = sift_features
            new_feature_string.append('sift')

        if updated_feature:
            outf = open(filename, 'w')
            pickle.dump((data, labels, new_feature_string, width, height,
                         self.winsize, self.nbins), outf)
            outf.close()
            print 'Saved data to %s.' % filename

        return (data, labels, new_feature_string, width, height, self.winsize,
                self.nbins)
Example #6
0
    def read_ppm(self, rawfilename, filename):
        # This function reads the ppm/jpg file and extracts the features if the
        # features pkl file doesn't exist. It is also compatible for extension
        # of the feauture vector and doesn't compute the already computed features

        new_feature_string = []
        updated_feature = 0
        data = N.array([], dtype=int)
        if os.path.exists(filename):
            pkl_f = open(filename, 'r')
            (data, labels, feature_string, width, height, winsize,
             nbins) = pickle.load(pkl_f)
            self.winsize = winsize
            self.nbins = nbins
            new_feature_string = list(feature_string)
            pkl_f.close()

        if not new_feature_string.count('dsift'):
            updated_feature = 1
            (sift_features, labels, width,
             height) = self.extract_dsift(rawfilename, self.winsize,
                                          self.nbins)
            if data.size:
                data = scipy.concatenate(
                    (data.transpose(), sift_features.transpose()),
                    1).transpose()
            else:
                data = sift_features
            new_feature_string.append('dsift')

        if not new_feature_string.count('histogram'):
            updated_feature = 1
            (hist_features, labels, width,
             height) = self.extract_hist(rawfilename, self.winsize, self.nbins)
            hist_features = hist_features / (self.winsize)
            if data.size:
                data = scipy.concatenate(
                    (data.transpose(), hist_features.transpose()),
                    1).transpose()
            else:
                data = hist_features
            new_feature_string.append('histogram')
        '''
    if not new_feature_string.count('position'):
      updated_feature = 1 
      
      position_features = []
      for label in labels:
        (y,x) = map(int, label.strip('()').split(','))
        position_features.append([x,y]) 
      position_features = N.array(position_features)
    
      if data.size:
        data = scipy.concatenate((data.transpose(), position_features), 1).transpose()
      else:
        data = position_features
      new_feature_string.append('position')
    '''
        if updated_feature:
            outf = open(filename, 'w')
            pickle.dump((data, labels, new_feature_string, width, height,
                         self.winsize, self.nbins), outf)
            outf.close()
            print 'Saved data to %s.' % filename

        return (data, labels, new_feature_string, width, height, self.winsize,
                self.nbins)