Exemple #1
0
    def update(self, index):
        self.mi.update()
        if index == -1:
            index = self.mi.df.index.max()
        try:
            latest = self.mi.df.iloc[index]
        except (IndexError, KeyError):
            print "invalid index", index
            return
        if index == self.last_index:
            return
        self.last_index = index
        filename = latest['filename']
        filename = os.path.join(self.root_path, filename[1:])
        print filename
        if self.status_bar:
            self.status_bar.update_filename(filename)
        img, chunk = blosc_file.load_blosc_image(filename)
        if self.guiwrapper:
            self.autolevels = self.guiwrapper.toolbar.autolevel_checkbox.isChecked()
            self.absolute_levels = self.guiwrapper.toolbar.absolute_level_checkbox.isChecked()
            self.autorange = self.guiwrapper.toolbar.autorange_checkbox.isChecked()

        # m = np.ma.masked_where(img > 16383, img)
        # print m.mask

        self.setImage(img, autoLevels=self.autolevels, autoRange=self.autorange)
        if self.absolute_levels:
            self.setLevels(0, 16384)
Exemple #2
0
 def test_blosc_image_round_trip(self):
     filename = os.path.join(self.temp_dir,'blah2.blosc')
     image = np.zeros(dtypes.image_dimensions, dtype='uint16')
     chunk = np.zeros((1,), dtype=dtypes.chunk_dtype)
     data = image.tostring() + chunk.tostring()
     blosc_file.write_image_blosc(filename, data)
     image2,chunk2 = blosc_file.load_blosc_image(filename)
     assert np.all(image == image2)
     assert np.all(chunk2 == chunk)
     assert image.dtype == image2.dtype
Exemple #3
0
 def get_blobs_by_info(self,
                       index_row,
                       request_id,
                       stamp_size,
                       blob_threshold,
                       kernel_sigma,
                       kernel_size,
                       cell_size,
                       max_num_blobs,
                       quality=75,
                       format='jpeg'):
     image, chunk = load_blosc_image(index_row['filename'])
     tic = time.time()
     image = self.hot_pixel_masker.process(image)
     blob_finder = BlobFinder(image,
                              blob_threshold=blob_threshold,
                              kernel_size=kernel_size,
                              kernel_sigma=kernel_sigma,
                              cell_size=cell_size,
                              fit_blobs=False)
     logger.debug("Found %d blobs in %.2f seconds" %
                  (len(blob_finder.blobs), (time.time() - tic)))
     results = []
     for blob in blob_finder.blobs:
         if len(results) >= max_num_blobs:
             break
         row_offset = blob.x - stamp_size // 2
         column_offset = blob.y - stamp_size // 2
         stamp = image[row_offset:row_offset + stamp_size,
                       column_offset:column_offset + stamp_size]
         if stamp.size == 0:  # the blob was too close to an edge of the image, so don't bother returning it
             logger.debug(
                 "Skipping blob at (%d,%d) because it is too close to edge of image"
                 % (blob.x, blob.y))
             continue
         results.append(
             self.make_image_file(stamp,
                                  index_row_data=index_row,
                                  request_id=request_id,
                                  row_offset=row_offset,
                                  column_offset=column_offset,
                                  num_rows=stamp.shape[0],
                                  num_columns=stamp.shape[1],
                                  scale_by=1,
                                  quality=quality,
                                  format=format))
     return results
Exemple #4
0
 def update(self, index, autoLevels=False, autoRange=False):
     self.mi.update()
     if index == -1:
         index = self.mi.df.index.max()
     try:
         latest = self.mi.df.iloc[index]
     except (IndexError, KeyError):
         print "invalid index", index
         return
     if index == self.last_index:
         return
     self.last_index = index
     filename = latest['filename']
     filename = os.path.join(self.root_path, filename[1:])
     print filename
     if self.real_time_values:
         self.real_time_values.update_filename(filename)
     img, chunk = blosc_file.load_blosc_image(filename)
     self.setImage(img, autoLevels=autoLevels, autoRange=autoRange)
Exemple #5
0
    def update_img(n):
        elapsed = time.time() - start_at
        if n:
            time_per_frame = elapsed / (n)
        else:
            time_per_frame = 1
        sys.stdout.flush()
        try:
            # npz = np.load(files[n])
            # imall = npz['image']

            imall, chunk = blosc_file.load_blosc_image(files[n])

        except Exception:
            return
        nblobs = 0
        # data = scipy.ndimage.gaussian_filter(imd,2)[::4,::4]
        if downsample:
            data = cv2.GaussianBlur(imall, (3, 3), 0)[::4, ::4]
        else:
            data = cv2.GaussianBlur(imall, (3, 3), 0)
        im.set_data(data)
        mn = data.mean(dtype='float64')
        if mn < 1000:
            mx = 1000
        else:
            mx = data.max() + 1000
            # mx = 14000
        #        im.set_clim(mn-200,mn+200)
        im.set_clim(0, mx)
        try:
            time_string = files[n].split('/')[-1].split('_')[1]
            time_string = time_string[0:2] + ':' + time_string[
                2:4] + ':' + time_string[4:]
            txt.set_text(time_string)
        except Exception:
            pass
        print(
            "\r%d of %d %.1f minutes elapsed, %.1f minutes remaining, %d blobs"
            % (n, len(files), elapsed / 60,
               (len(files) - n) * time_per_frame / 60., nblobs)),

        return im, txt
Exemple #6
0
    def update(self, index):
        if index == -1:
            index = len(self.filenames)
        self.guiwrapper.status_bar.update_index(index)
        filename = self.filenames[index]
        self.last_index = index
        print filename
        self.guiwrapper.status_bar.update_filename(filename)
        img, chunk = blosc_file.load_blosc_image(filename)
        self.autolevels = self.guiwrapper.toolbar.autolevel_checkbox.isChecked(
        )
        self.absolute_levels = self.guiwrapper.toolbar.absolute_level_checkbox.isChecked(
        )
        self.autorange = self.guiwrapper.toolbar.autorange_checkbox.isChecked()

        self.setImage(img,
                      autoLevels=self.autolevels,
                      autoRange=self.autorange)
        if self.absolute_levels:
            self.setLevels(0, 16384)
Exemple #7
0
def solve_img(filename, solutions_path='./solutions'):
    camera = int(re.findall('camera-\d', filename)[0][-1])
    img, meta = load_blosc_image(filename)
    work_dir = os.path.abspath(
        os.path.join(solutions_path,
                     os.path.split(filename)[1]))
    print work_dir
    try:
        os.makedirs(work_dir)
    except OSError:
        pass
    timestamp = int(filename[-19:])
    #bf = blobs.BlobFinder(by_camera[camera].process(img),blob_threshold=7,fit_blobs=False)
    bf = blobs.BlobFinder(img,
                          blob_threshold=12,
                          fit_blobs=False,
                          kernel_size=32,
                          kernel_sigma=5)
    xcoords = np.array([blob.x for blob in bf.blobs[:20]])
    ycoords = np.array([blob.y for blob in bf.blobs[:20]])
    res = pyadn.solve_xy(xcoords, ycoords, work_dir=work_dir)
    res['timestamp'] = timestamp
    return res
Exemple #8
0
 def get_image_by_info(self,
                       index_row_data,
                       request_id,
                       row_offset=0,
                       column_offset=0,
                       num_rows=3232,
                       num_columns=4864,
                       scale_by=1 / 8.,
                       quality=75,
                       format='jpeg'):
     image, chunk = load_blosc_image(index_row_data['filename'])
     image = self.hot_pixel_masker.process(image)
     image = image[row_offset:row_offset + num_rows + 1,
                   column_offset:column_offset + num_columns + 1]
     return self.make_image_file(image,
                                 index_row_data=index_row_data,
                                 request_id=request_id,
                                 row_offset=row_offset,
                                 column_offset=column_offset,
                                 num_rows=num_rows,
                                 num_columns=num_columns,
                                 scale_by=scale_by,
                                 quality=quality,
                                 format=format)
Exemple #9
0
def make_jpeg_from_blosc(filename, **kwargs):
    img, chunk = blosc_file.load_blosc_image(filename)
    img_jpeg, offset, scale = jpeg.simple_jpeg(img, **kwargs)
    image_name = filename.split('/')[-1]
    with open('/home/pmc/%s.jpeg' % image_name, 'wb') as f:
        f.write(img_jpeg)
Exemple #10
0
 def test_blosc_image_write(self):
     filename = os.path.join(self.temp_dir,'blah3.blosc')
     image = np.random.random_integers(0,2**14-1,size=(31440952//2,)).astype('uint16')
     blosc_file.write_image_blosc(filename, image)
     image2,chunk2 = blosc_file.load_blosc_image(filename)