Beispiel #1
0
  def onSaveImage(self):
    '''called when Save Image is pressed'''
    reImg = self.ui.mImageDisplay.data
    if reImg is None:
      QtGui.QMessageBox.critical\
              (self, self.tr('Error'),\
               self.tr('Nothing reconstructed.'))
      return

    filterStr = 'Images (*.tiff *.h5)'
    if self.opts['recon']['out_format'] == 'hdf5':
      filterStr = 'Images (*.h5)'
    elif self.opts['recon']['out_format'] == 'tiff':
      filterStr = 'Images (*.tiff)'
    filename = QtGui.QFileDialog.getSaveFileName\
            (self, 'Save Image',\
             self.opts['extra']['dest_dir'], filterStr)
    filename = str(filename)
    basename, extname = splitext(filename)
    if extname == '.tiff':
      self.logText('Saving image data to ' + filename + '\n')
      imageList = [reImg[:,:,i] for i in range(reImg.shape[2])]
      fi.write_multipage(imageList, filename)
    elif extname == '.h5':
      self.logText('Saving image data to ' + filename)
      f = h5py.File(filename, 'w')
      f['reImg'] = reImg
      f.close()
    else:
      QtGui.QMessageBox.critical\
              (self.tr('Output format ' + extname[1:] +\
                      ' not supported'))
    self.logText('Done\n')
def test_write_multipage():
    shape = (64, 64, 64)
    x = np.ones(shape, dtype=np.uint8) * np.random.rand(*shape) * 255
    x = x.astype(np.uint8)
    f = NamedTemporaryFile(suffix='.tif')
    fname = f.name
    f.close()
    fi.write_multipage(x, fname)
    y = fi.read_multipage(fname)
    assert_array_equal(x, y)
Beispiel #3
0
def test_write_multipage():
    shape = (64, 64, 64)
    x = np.ones(shape, dtype=np.uint8) * np.random.random(shape) * 255
    x = x.astype(np.uint8)
    f = NamedTemporaryFile(suffix='.tif')
    fname = f.name
    f.close()
    fi.write_multipage(x, fname)
    y = fi.read_multipage(fname)
    assert_array_equal(x, y)
Beispiel #4
0
def writeFullFramesTiff(masked_image_file, tiff_file = -1, reduce_fractor = 8, base_name = '', status_queue = ''):
    '''
    write scale down the saved full frames, and put them into a tiff stack.
    requires either install skimage with the freeimage library plugin, or the tifffile module.
    '''
    #if no tiff_file is given, the save name will be derived from masked_image_file   
    if tiff_file == -1:
        tiff_file = os.path.splitext(masked_image_file)[0] + '_full.tiff';
    
    
    mask_fid = h5py.File(masked_image_file, "r");

    #determine the expected size of the full_data size with respect to the 
    #number of frames in full_data and the same interval (I only do that 
    #to correct for a bug in previously saved files)
    expected_size = int(np.floor(mask_fid["/mask"].shape[0]/float(mask_fid["/full_data"].attrs['save_interval']) + 1));
    if expected_size > mask_fid["/full_data"].shape[0]: 
        expected_size = mask_fid["/full_data"].shape[0]
    
    #initialized reduced array  
    im_size = tuple(np.array(mask_fid["/full_data"].shape)[1:]/reduce_fractor)
    reduce_factor = (im_size[-1], im_size[-2])
    I_worms = np.zeros((expected_size, im_size[0],im_size[1]), dtype = np.uint8)
    
    sendQueueOrPrint(status_queue, 'Reading for data the tiff file...', base_name);
    
    for frame_number in range(expected_size):
        I_worms[frame_number, :,:] = cv2.resize(mask_fid["/full_data"][frame_number,:,:], reduce_factor);
    
    sendQueueOrPrint(status_queue, 'Writing tiff file...', base_name);
    
    try: 
        #Requires the installation of freeimage library. 
        #On mac is trivial using brew (brew install freeimage), 
        #but i am not sure how to do it on windows
        from skimage.io._plugins import freeimage_plugin as fi
        fi.write_multipage(I_worms, tiff_file, fi.IO_FLAGS.TIFF_LZW) #the best way I found to write lzw compression on python
    
    except:
        import tifffile #pip intall tifffile
        #For some reason gzip compression appears as an inverted image in 
        #preview (both windows and mac), but it is read correctly in ImageJ
        tifffile.imsave(tiff_file, I_worms, compress=4) 
    
    sendQueueOrPrint(status_queue, 'Tiff file done.', base_name);
Beispiel #5
0
elif not os.path.isdir(bmpDir):
    os.mkdir(bmpDir)

chunk = 56
frameIni = 16449
NImages = 450

I = np.zeros((NImages, 2048, 2048), dtype=np.uint8)
for nn in range(NImages):
    filename = '/Users/ajaver/Desktop/DCR_D_56/DCR_D_%i_%i.BMP' % (chunk, nn +
                                                                   frameIni)
    I[nn, :, :] = smisc.imread(filename)[:, :, 0]  #change rgb to gray
    #plt.figure()
    #plt.imshow(I[:,:,nn])

fi.write_multipage(I, saveDir + 'Tiff_LZW.tiff', fi.IO_FLAGS.TIFF_LZW)
fi.write_multipage(I, saveDir + 'Tiff_Uncompressed.tiff',
                   fi.IO_FLAGS.TIFF_NONE)

for nn in range(I.shape[0]):
    fi.write(I[nn, :, :], bmpDir + '%03i.bmp' % nn)

# Change John's BMP into index-value arrays

FID = open(saveDir + 'reduced_indexes', "wb")

# Find list of indexes and pixel values
for nn in range(I.shape[0]):
    Isingle = I[nn, :, :]
    mask = (Isingle != 200) & (Isingle != 0)
    indexList = np.where(mask)
#    else:
#        for frame in range(expected_size):
#            I_worms[frame, :,:] = cv2.resize(mask_fid["/full_data"][frame,:,:], im_size);
#
#
#    fi.write_multipage(I_worms, tiff_file, fi.IO_FLAGS.TIFF_LZW)

root_dir = '/Users/ajaver/Downloads/wetransfer-2af646/'  #'/Volumes/ajaver$/GeckoVideo/Compressed/'
base_file = 'CaptureTest_90pc_Ch3_21022015_205929'

masked_image_file = root_dir + base_file + '.hdf5'
tiff_file = root_dir + base_file + '_mask_deflate.tiff'

mask_fid = h5py.File(masked_image_file, "r")

fi.write_multipage(mask_fid["/mask"], tiff_file, fi.IO_FLAGS.TIFF_DEFLATE)

#masked_image_file = rootDir + 'Capture_Ch3_26022015_161436.hdf5'
#masked_image_file = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150218/CaptureTest_90pc_Ch2_18022015_230213.hdf5'

#root_dir = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150218/';
#base_file = 'CaptureTest_90pc_Ch%i_18022015_230213'

#root_dir = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150216/';
#base_file = 'CaptureTest_90pc_Ch%i_16022015_174636'
#root_dir = '/Volumes/ajaver$/GeckoVideo/Compressed/'
#base_file = 'CaptureTest_90pc_Ch1%i_20022015_183607'
#
#for ch_ind in range(1,2):
#    channel_file = (base_file % ch_ind)
#    masked_image_file = root_dir + channel_file + '.hdf5'
#        for frame in range(expected_size):
#            I_worms[frame, :,:] = cv2.resize(mask_fid["/full_data"][frame,:,:], im_size);
#        
#        
#    fi.write_multipage(I_worms, tiff_file, fi.IO_FLAGS.TIFF_LZW)


root_dir = '/Users/ajaver/Downloads/wetransfer-2af646/' #'/Volumes/ajaver$/GeckoVideo/Compressed/'
base_file = 'CaptureTest_90pc_Ch3_21022015_205929'

masked_image_file = root_dir + base_file + '.hdf5'
tiff_file = root_dir + base_file + '_mask_deflate.tiff'
    
mask_fid = h5py.File(masked_image_file, "r");
    
fi.write_multipage(mask_fid["/mask"], tiff_file, fi.IO_FLAGS.TIFF_DEFLATE)


#masked_image_file = rootDir + 'Capture_Ch3_26022015_161436.hdf5'
#masked_image_file = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150218/CaptureTest_90pc_Ch2_18022015_230213.hdf5'

#root_dir = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150218/';
#base_file = 'CaptureTest_90pc_Ch%i_18022015_230213'

#root_dir = '/Volumes/behavgenom$/GeckoVideo/Compressed/20150216/';
#base_file = 'CaptureTest_90pc_Ch%i_16022015_174636'
#root_dir = '/Volumes/ajaver$/GeckoVideo/Compressed/'
#base_file = 'CaptureTest_90pc_Ch1%i_20022015_183607'
#
#for ch_ind in range(1,2):
#    channel_file = (base_file % ch_ind)
Beispiel #8
0
def saveTiff3d(filepath, img):
    nx, ny, nz = img.shape
    imglist = [img[:, :, idx] for idx in xrange(nz)]
    fi.write_multipage(imglist, filepath)
Beispiel #9
0
                    if ma > norm[channel]['Max']:
                        norm[channel]['Max'] = ma

                if options.min:
                    norm[channel]['Min'] = options.min[c]
                else:
                    mi = np.min(im)
                    if mi > norm[channel]['Min']:
                        norm[channel]['Min'] = mi
            else:
                norm[channel]['Max'] = options.max[c]
                norm[channel]['Min'] = options.min[c]
    print("Normalization values: {}".format(norm))

print("Extracting ...")


for c in range(len(channels)):
    print("Extracting channel: {}".format(channels[c]))
    channel = channels[c]
    for timepoint in timepoints:
        print("Extracting timepoint: {}".format(timepoint))
        im = hdf5.get('t{0:05d}/{1}/{2}/cells'.format(timepoint, channel, L)).value.astype(np.int16)
        if options.crop:
            c = int(options.crop)
            im = im[c:-c, c:-c, c:-c]
        if options.normalize:
            im = rescale(im, Min=norm[channel]['Min'], Max=norm[channel]['Max'])
        freeimg.write_multipage(im, outfiles[c] + '_{}_{}.tiff'.format(timepoint, L))
print("Cube Dimensions: | x {} | y {} | z {} |".format(im.shape[0], im.shape[1], im.shape[2]))