How to use the tifffile.TiffWriter function in tifffile

To help you get started, we’ve selected a few tifffile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fedebarabas / tormenta / tormenta / control / control.py View on Github external
def twoColorTIFF(self):

        cropName = utils.insertSuffix(self.savename, '_corrected')

        with tiff.TiffWriter(self.savename, software='Tormenta') as storeFile,\
                tiff.TiffWriter(cropName, software='Tormenta') as cropFile:

            while self.j < self.shape[0] and self.pressed:

                time.sleep(self.t_exp.magnitude)
                if self.andor.n_images_acquired > self.j:
                    i, self.j = self.andor.new_images_index
                    newImages = self.andor.images16(i, self.j, self.frameShape,
                                                    1, self.n)
                    self.sigUpdate.emit(np.transpose(newImages[-1]))
#                    self.sigUpdate.emit(newImages[-1])
                    newData = newImages[:, ::-1]

                    # This is done frame by frame in order to have contiguously
                    # saved tiff files so they're correctly opened in ImageJ
                    # or in python through tifffile
github ZhuangLab / storm-analysis / storm_analysis / multi_plane / fitting_mp.py View on Github external
self.mfinder.resetTaken()

        # Save reference to images.
        self.images = new_images

        # For checking that we're doing the transform correctly and / or have
        # the correct transform.
        if self.check_mode:
            at_images = []
            for i in range(self.n_channels):
                if self.atrans[i] is None:
                    at_images.append(new_images[i].copy())
                else:
                    at_images.append(self.atrans[i].transform(new_images[i]))

            with tifffile.TiffWriter("transform.tif") as tf:
                for at_image in at_images:
                    tf.save(at_image.astype(numpy.float32))
github ZhuangLab / storm-control / storm_control / hal4000 / halLib / imagewriters.py View on Github external
def __init__(self, bigtiff = False, **kwds):
        super().__init__(**kwds)
        self.metadata = {'unit' : 'um'}
        if bigtiff:
            self.resolution = (25400.0/self.film_settings.getPixelSize(),
                               25400.0/self.film_settings.getPixelSize())
            self.tif = tifffile.TiffWriter(self.filename,
                                           bigtiff = bigtiff)
        else:
            self.resolution = (1.0/self.film_settings.getPixelSize(), 1.0/self.film_settings.getPixelSize())
            self.tif = tifffile.TiffWriter(self.filename,
                                           imagej = True)
github ZhuangLab / storm-analysis / storm_analysis / sa_library / fitting.py View on Github external
#    Spliner) will sometimes return this array with negative values. This is
        #    still probably not the correct way to handle this.
        #
        bg_var = self.background + numpy.abs(fit_peaks_image)

        # Add camera variance if set.
        if self.camera_variance is not None:
            bg_var += self.camera_variance
            
        #
        # Find peaks in image convolved with the PSF at different z values.
        #
        if self.check_mode:
            bg_tif = tifffile.TiffWriter("background.tif")
            fg_tif = tifffile.TiffWriter("foreground.tif")
            fg_bg_ratio_tif = tifffile.TiffWriter("fg_bg_ratio.tif")

        masked_images = []
        for i in range(len(self.fg_mfilter)):

            # Estimate background variance at this particular z value.
            background = self.fg_vfilter[i].convolve(bg_var)

            # Remove problematic values.
            #
            mask = (background <= 0.1)
            if (numpy.sum(mask) > 0):
                if self.check_mode:
                    print("Warning! small and/or negative values detected in background variance!")
                background[mask] = 0.1
                    
            # Convert to standard deviation.
github ZhuangLab / storm-analysis / storm_analysis / multi_plane / psf_zstack.py View on Github external
#
        frame = frame - numpy.median(frame)
            
        for j in range(x.size):
            xf = x[j] + driftx * float(i)
            yf = y[j] + drifty * float(i)
            z_stacks[j][:,:,i] = measurePSFUtils.extractAOI(frame, aoi_size, xf, yf)

    # Save z_stacks.
    numpy.save(zstack_name + ".npy", z_stacks)

    # Save a (normalized) z_stack as tif for inspection purposes.
    z_stack = z_stacks[0]
    z_stack = z_stack/numpy.amax(z_stack)
    z_stack = z_stack.astype(numpy.float32)
    with tifffile.TiffWriter(zstack_name + ".tif") as tf:
        for i in range(movie_len):
            tf.save(z_stack[:,:,i])
github ZhuangLab / storm-analysis / storm_analysis / diagnostics / drift_correction / collate.py View on Github external
# We assume that there are two directories, the first with xy correction
    # only and the second with xyz correction.
    #

    # Make 2D images of the drift corrected data.
    if False:
        for adir in ["test_01/", "test_02/"]:
            im = hdf5ToImage.render2DImage(adir + "test.hdf5", sigma = 0.5)
            tifffile.imsave(adir + "test_im_2d.tif", im.astype(numpy.float32))

    # Make 3D images of the drift corrected data.
    if False:
        z_edges = numpy.arange(-0.5, 0.55, 0.1)
        for adir in ["test_01/", "test_02/"]:
            images = hdf5ToImage.render3DImage(adir + "test.hdf5", z_edges, sigma = 0.5)
            with tifffile.TiffWriter(adir + "test_im_3d.tif") as tf:
                for elt in images:
                    tf.save(elt.astype(numpy.float32))

    # Measure error in drift measurements.
    if True:
        print("Drift correction RMS error (nanometers):")
        for i, elt in enumerate(["drift_xy.txt", "drift_xyz.txt"]):

            print(" ", elt)
    
            ref = numpy.loadtxt(elt)
            exp = numpy.loadtxt("test_{0:02}/test_drift.txt".format(i+1))
        
            max_len = exp.shape[0]
            for j, elt in enumerate(["X", "Y", "Z"]):
                refv = ref[:max_len,j]
github macronucleus / Chromagnon / PriCommon / imgfileIO.py View on Github external
def openFile(self):
        """
        open a file for reading
        """
        self.fp = tifffile.TiffWriter(self.fn, bigtiff=not(self.imagej), imagej=self.imagej)

        self.handle = self.fp._fh
        self.dataOffset = self.handle.tell()
        self.imgSequence = 2 # my code uses t->w->z, suite yourself...
        
        self.setParameters()
github ZhuangLab / storm-control / storm_control / hal4000 / halLib / imagewriters.py View on Github external
def __init__(self, bigtiff = False, **kwds):
        super().__init__(**kwds)
        self.metadata = {'unit' : 'um'}
        if bigtiff:
            self.resolution = (25400.0/self.film_settings.getPixelSize(),
                               25400.0/self.film_settings.getPixelSize())
            self.tif = tifffile.TiffWriter(self.filename,
                                           bigtiff = bigtiff)
        else:
            self.resolution = (1.0/self.film_settings.getPixelSize(), 1.0/self.film_settings.getPixelSize())
            self.tif = tifffile.TiffWriter(self.filename,
                                           imagej = True)
github stevenrobertson / cuburn / cuburn / output.py View on Github external
def __init__(self, alpha=False):
        import tifffile
        if 'filename' in tifffile.TiffWriter.__init__.__func__.func_doc:
            raise EnvironmentError('tifffile version too old!')
        super(TiffOutput, self).__init__()
        self.alpha = alpha
github ZhuangLab / storm-analysis / storm_analysis / diagnostics / measure_psf / measure_psf.py View on Github external
def psfDiffCheck(psf1, psf2, atol = 1.0e-3, rtol = 1.0e-6):
    is_different = False
    for i in range(psf1.shape[0]):
        #print(i, numpy.max(numpy.abs(psf1[i,:,:] - psf2[i,:,:])))
        if not numpy.allclose(psf1[i,:,:], psf2[i,:,:], atol = atol, rtol = rtol):
            is_different = True
            print("Difference of",
                  numpy.max(numpy.abs(psf1[i,:,:] - psf2[i,:,:])),
                  "at z section", i)

    if is_different:
        with tifffile.TiffWriter("diff.tif") as tf:
            for i in range(psf1.shape[0]):
                tf.save((psf1[i,:,:] - psf2[i,:,:]).astype(numpy.float32))
            
    return is_different