def openTiff(self, filename):
     Tiff = tifffile.TiffFile(str(filename))
     A = Tiff.asarray()
     Tiff.close()
     axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]
     if set(axes) == set(['series', 'height', 'width']):  # single channel, multi-volume
         target_axes = ['series', 'width', 'height']
         perm = get_permutation_tuple(axes, target_axes)
         A = np.transpose(A, perm)
     return A
Esempio n. 2
0
    def loadTiff_Display(self):
        t = time() 
        g.m.statusBar().showMessage("Loading movie...")
        
        if self.axes == 'IYX':
            #single channel (stk?)
            startPage = 0
            endPage = self.nPages
            stepSize = 1

            volume = 0

            series = list(range(startPage+volume, endPage+volume, stepSize))

            #for stk? file (axes == 'IYX')
            Page_series = tifffile.imread(self.fileName,key=series)
            print(Page_series.shape)
            self.displayWindow_0 = Window(Page_series, 'Loaded from pages - channel 0')
        
        
        
        elif self.axes == 'TZCYX':
            #multi-sweep (micromanager)
            volNum = shape[1]

            #2-channel - get channels serperately 
            #for micromanager file (axes == 'TZCYX')
            with tifffile.TiffFile(self.fileName) as tif:
                initiated_0 = False
                initiated_1 = False
                for page in tif.pages:
                    #print('ChannelIndex',page.tags.micromanager_metadata.value.ChannelIndex)
                    #print('ImageNumber',page.tags.micromanager_metadata.value.ImageNumber)
                    g.m.statusBar().showMessage("Loading movie...(Image #:{})".format(page.tags.micromanager_metadata.value.ImageNumber))
                    if page.tags.micromanager_metadata.value.ChannelIndex == 0 and int(page.tags.micromanager_metadata.value.ImageNumber)%volNum == 0:
                        image_0 = page.asarray()
                        if initiated_0 == False:
                            stack_0 = image_0
                            initiated_0 = True
                        else:
                            stack_0 = np.dstack((stack_0, image_0))

                    if page.tags.micromanager_metadata.value.ChannelIndex == 1 and int(page.tags.micromanager_metadata.value.ImageNumber)%volNum == 0:
                        image_1 = page.asarray()
                        if initiated_1 == False:
                            stack_1 = image_1
                            initiated_1 = True
                        else:
                            stack_1 = np.dstack((stack_1, image_1))



            print(stack_0.shape)
            print(stack_1.shape)
            stackAxes = ['y','x','t']
            target_axes = ['t', 'y', 'x']	
            perm = get_permutation_tuple(stackAxes, target_axes)
            stack_0 = np.transpose(stack_0, perm)
            stack_1 = np.transpose(stack_1, perm)

            stack_0.shape
            stack_1.shape
            
            self.displayWindow_0 = Window(stack_0,'Loaded Page series - channel 0')
            self.displayWindow_1 = Window(stack_1,'Loaded Page series - channel 1')
        
        elif self.axes == 'ZCYX':
        #single-sweep (micromanager)
        #2-channel 
        
            with tifffile.TiffFile(self.fileName) as tif:
                axes = [tifffile.AXES_LABELS[ax] for ax in tif.series[0].axes]
                print(axes)
                initiated_0 = False
                initiated_1 = False
                for page in tif.pages:
                    ##print('ChannelIndex',page.tags.micromanager_metadata.value.ChannelIndex)
                    ##print('ImageNumber',page.tags.micromanager_metadata.value.ImageNumber)
                    g.m.statusBar().showMessage("Loading movie...(Image #:{})".format(page.tags.micromanager_metadata.value.ImageNumber))
                    if page.tags.micromanager_metadata.value.ChannelIndex == 0:
                        image_0 = page.asarray()
                        if initiated_0 == False:
                            stack_0 = image_0
                            initiated_0 = True
                        else:
                            stack_0 = np.dstack((stack_0, image_0))

                    if page.tags.micromanager_metadata.value.ChannelIndex == 1:
                        image_1 = page.asarray()
                        if initiated_1 == False:
                            stack_1 = image_1
                            initiated_1 = True
                        else:
                            stack_1 = np.dstack((stack_1, image_1))

            tif.close()                  
            print(stack_0.shape)
            print(stack_1.shape)
            stackAxes = ['y','x','t']
            target_axes = ['t', 'y', 'x']	
            perm = get_permutation_tuple(stackAxes, target_axes)
            stack_0 = np.transpose(stack_0, perm)
            stack_1 = np.transpose(stack_1, perm)

            stack_0.shape
            stack_1.shape
            self.displayWindow_0 = Window(stack_0,'Loaded from pages - channel 0')
            self.displayWindow_1 = Window(stack_1,'Loaded from pages - channel 1')
 
        elif self.axes == 'TZYX':
        #single-sweep (micromanager)
        #2-channel 
        
            with tifffile.TiffFile(self.fileName) as tif:
                axes = [tifffile.AXES_LABELS[ax] for ax in tif.series[0].axes]
                print(axes)
                initiated_0 = False
                initiated_1 = False
                print('ok')
                for page in tif.pages:
                    ##print('ChannelIndex',page.tags.micromanager_metadata.value.ChannelIndex)
                    print('ImageNumber',page.tags.micromanager_metadata.value.ImageNumber)
                    g.m.statusBar().showMessage("Loading movie...(Image #:{})".format(page.tags.micromanager_metadata.value.ImageNumber))
                    if page.tags.micromanager_metadata.value.ChannelIndex == 0:
                        image_0 = page.asarray()
                        if initiated_0 == False:
                            stack_0 = image_0
                            initiated_0 = True
                        else:
                            stack_0 = np.dstack((stack_0, image_0))

                    if page.tags.micromanager_metadata.value.ChannelIndex == 1:
                        image_1 = page.asarray()
                        if initiated_1 == False:
                            stack_1 = image_1
                            initiated_1 = True
                        else:
                            stack_1 = np.dstack((stack_1, image_1))

            tif.close()                  
            print(stack_0.shape)
            print(stack_1.shape)
            stackAxes = ['y','x','t']
            target_axes = ['t', 'y', 'x']	
            perm = get_permutation_tuple(stackAxes, target_axes)
            stack_0 = np.transpose(stack_0, perm)
            stack_1 = np.transpose(stack_1, perm)

            stack_0.shape
            stack_1.shape
            self.displayWindow_0 = Window(stack_0,'Loaded from pages - channel 0')
            self.displayWindow_1 = Window(stack_1,'Loaded from pages - channel 1') 
        
        else:
            g.m.statusBar().showMessage("No Movie Generated")
            return
        
        g.m.statusBar().showMessage("Successfully generated movie ({} s)".format(round(time() - t)))
        return
Esempio n. 3
0
def openTiff(filename):
    Tiff = tifffile.TiffFile(str(filename))

    A = Tiff.asarray()
    B = []
    C = []
    Tiff.close()
    axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]
    print(axes)

    if set(axes) == set(['time', 'depth', 'height',
                         'width']):  # single channel, multi-volume
        target_axes = ['time', 'depth', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        nScans, nFrames, x, y = A.shape
        A = A.reshape(nScans * nFrames, x, y)
        #newWindow = Window(A,'Loaded Tiff')

    elif set(axes) == set(['series', 'height',
                           'width']):  # single channel, single-volume
        target_axes = ['series', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        nFrames, x, y = A.shape
        A = A.reshape(nFrames, x, y)
        #newWindow = Window(A,'Loaded Tiff')

    elif set(axes) == set(['time', 'height',
                           'width']):  # single channel, single-volume
        target_axes = ['time', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        nFrames, x, y = A.shape
        A = A.reshape(nFrames, x, y)
        #newWindow = Window(A,'Loaded Tiff')

    elif set(axes) == set(['time', 'depth', 'channel', 'height',
                           'width']):  # multi-channel, multi-volume
        target_axes = ['channel', 'time', 'depth', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        B = A[0]
        C = A[1]

        n1Scans, n1Frames, x1, y1 = B.shape
        n2Scans, n2Frames, x2, y2 = C.shape

        B = B.reshape(n1Scans * n1Frames, x1, y1)
        C = C.reshape(n2Scans * n2Frames, x2, y2)

        #channel_1 = Window(B,'Channel 1')
        #channel_2 = Window(C,'Channel 2')

    elif set(axes) == set(['depth', 'channel', 'height',
                           'width']):  # multi-channel, single volume
        target_axes = ['channel', 'depth', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        B = A[0]
        C = A[1]

        #channel_1 = Window(B,'Channel 1')
        #channel_2 = Window(C,'Channel 2')

    elif set(axes) == set(['time', 'channel', 'height',
                           'width']):  # multi-channel, single volume
        target_axes = ['channel', 'time', 'width', 'height']
        perm = get_permutation_tuple(axes, target_axes)
        A = np.transpose(A, perm)
        B = A[0]
        C = A[1]

        #channel_1 = Window(B,'Channel 1')
        #channel_2 = Window(C,'Channel 2')

    return A, B, C
Esempio n. 4
0
    def openTiff(self, filename):
        Tiff = tifffile.TiffFile(str(filename))

        A = Tiff.asarray()
        Tiff.close()
        axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]
        print(axes)

        if set(axes) == set(['time', 'depth', 'height', 'width']):  # single channel, multi-volume
            target_axes = ['time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nScans, nFrames, x, y = A.shape

            #interleaved = np.zeros((nScans*nFrames,x,y))
            #
            #z = 0
            #for i in np.arange(nFrames):
            #    for j in np.arange(nScans):
            #        interleaved[z] = A[j%nScans][i] 
            #        z = z +1
            #newWindow = Window(interleaved,'Loaded Tiff')

            A = A.reshape(nScans*nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')
            
            
        elif set(axes) == set(['series', 'height', 'width']):  # single channel, single-volume
            target_axes = ['series', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')

        elif set(axes) == set(['depth', 'height', 'width']):  # single channel, single-volume
            target_axes = ['depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')                      
            
        elif set(axes) == set(['time', 'height', 'width']):  # single channel, single-volume
            target_axes = ['time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')
            
        elif set(axes) == set(['time', 'depth', 'channel', 'height', 'width']):  # multi-channel, multi-volume
            target_axes = ['channel','time','depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            n1Scans, n1Frames, x1, y1 = B.shape
            n2Scans, n2Frames, x2, y2 = C.shape

            B = B.reshape(n1Scans*n1Frames,x1,y1)
            C = C.reshape(n2Scans*n2Frames,x2,y2)

            channel_1 = Window(B,'Channel 1')
            channel_2 = Window(C,'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2,2))            
            
        elif set(axes) == set(['depth', 'channel', 'height', 'width']):  # multi-channel, single volume
            target_axes = ['channel','depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            channel_1 = Window(B,'Channel 1')
            channel_2 = Window(C,'Channel 2')
            
            #clear A array to reduce memory use
            A = np.zeros((2,2))
            
        elif set(axes) == set(['time', 'channel', 'height', 'width']):  # multi-channel, single volume
            target_axes = ['channel','time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            channel_1 = Window(B,'Channel 1')
            channel_2 = Window(C,'Channel 2')
            
            #clear A array to reduce memory use
            A = np.zeros((2,2))
    def openTiff(self, filename):
        Tiff = tifffile.TiffFile(str(filename))
        A = Tiff.asarray()
        Tiff.close()
        axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]

        if set(axes) == set(['time', 'depth', 'height',
                             'width']):  # single channel, multi-volume
            target_axes = ['time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nScans, nFrames, x, y = A.shape

            A = A.reshape(nScans * nFrames, x, y)
            #newWindow = Window(A,'Loaded Tiff')
            return A, None

        elif set(axes) == set(['series', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['series', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames, x, y)
            #newWindow = Window(A,'Loaded Tiff')
            return A, None

        elif set(axes) == set(['time', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames, x, y)
            #newWindow = Window(A,'Loaded Tiff')
            return A, None

        elif set(axes) == set(['time', 'depth', 'channel', 'height',
                               'width']):  # multi-channel, multi-volume
            target_axes = ['channel', 'time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            n1Scans, n1Frames, x1, y1 = B.shape
            n2Scans, n2Frames, x2, y2 = C.shape

            B = B.reshape(n1Scans * n1Frames, x1, y1)
            C = C.reshape(n2Scans * n2Frames, x2, y2)

            #channel_1 = Window(B,'Channel 1')
            #channel_2 = Window(C,'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return B, C

        elif set(axes) == set(['depth', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            #channel_1 = Window(B,'Channel 1')
            #channel_2 = Window(C,'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return B, C

        elif set(axes) == set(['time', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            nChannels, nFrames, x, y = A.shape

            n1Frames, x1, y1 = B.shape
            n2Frames, x2, y2 = C.shape

            #uncomment to display original
            #self.channel_1 = Window(B,'Channel 1')
            #self.channel_2 = Window(B,'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return B, C
from flika.utils.io import tifffile
from flika.process.file_ import get_permutation_tuple

filename = r"C:\Users\George\Dropbox\UCI\multiColor\2bin_200slices_0.11slicestep_2sweep_MMStack_Pos0.ome.tif"

Tiff = tifffile.TiffFile(str(filename))

A = Tiff.asarray()
Tiff.close()
axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]
target_axes = ['channel','time','depth', 'width', 'height']
perm = get_permutation_tuple(axes, target_axes)
A = np.transpose(A, perm)

B = A[0]
C = A[1]


n1Scans, n1Frames, x1, y1 = B.shape
n2Scans, n2Frames, x2, y2 = C.shape

B = B.reshape(n1Scans*n1Frames,x1,y1)
C = C.reshape(n2Scans*n2Frames,x2,y2)

channel_1 = Window(B,'Channel 1')
channel_2 = Window(C,'Channel 2')
Esempio n. 7
0
    def openTiff(self, filename):
        ext = os.path.splitext(filename)[-1]

        if ext in ['.tif', '.tiff', 'stk']:
            Tiff = tifffile.TiffFile(str(filename))

            A = Tiff.asarray()
            Tiff.close()

            axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]

        elif ext == '.czi':
            #import czifile
            czi = CziFile(filename)
            A = czi.asarray()
            czi.close()

            axes = [ax for ax in czi.axes]

            ##remove axes length ==1
            #get shape
            shape = A.shape
            #squeeze array to remove length ==1
            A = A.squeeze()
            #remove axis length 1 labels
            toRemove = []
            for n, i in enumerate(shape):
                if i == 1:
                    toRemove.append(n)

            delete_multiple_element(axes, toRemove)

            #convert labels to tiff format
            for n, i in enumerate(axes):
                if i == 'T':
                    axes[n] = 'time'
                elif i == 'C':
                    axes[n] = 'channel'
                elif i == 'Y':
                    axes[n] = 'height'
                elif i == 'X':
                    axes[n] = 'width'
                elif i == 'Z':
                    axes[n] = 'depth'

        else:
            msg = "Could not open.  Filetype for '{}' not recognized".format(
                filename)
            g.alert(msg)
            if filename in g.settings['recent_files']:
                g.settings['recent_files'].remove(filename)
            # make_recent_menu()
            return

        print(axes)

        if set(axes) == set(['time', 'depth', 'height',
                             'width']):  # single channel, multi-volume
            target_axes = ['time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nScans, nFrames, x, y = A.shape

            #interleaved = np.zeros((nScans*nFrames,x,y))
            #
            #z = 0
            #for i in np.arange(nFrames):
            #    for j in np.arange(nScans):
            #        interleaved[z] = A[j%nScans][i]
            #        z = z +1
            #newWindow = Window(interleaved,'Loaded Tiff')

            A = A.reshape(nScans * nFrames, x, y)
            newWindow = Window(A, 'Loaded Tiff')

        elif set(axes) == set(['series', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['series', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames, x, y)
            newWindow = Window(A, 'Loaded Tiff')

        elif set(axes) == set(['time', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames, x, y)
            newWindow = Window(A, 'Loaded Tiff')

        elif set(axes) == set(['time', 'depth', 'channel', 'height',
                               'width']):  # multi-channel, multi-volume
            target_axes = ['channel', 'time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            n1Scans, n1Frames, x1, y1 = B.shape
            n2Scans, n2Frames, x2, y2 = C.shape

            B = B.reshape(n1Scans * n1Frames, x1, y1)
            C = C.reshape(n2Scans * n2Frames, x2, y2)

            channel_1 = Window(B, 'Channel 1')
            channel_2 = Window(C, 'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))

        elif set(axes) == set(['depth', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            channel_1 = Window(B, 'Channel 1')
            channel_2 = Window(C, 'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))

        elif set(axes) == set(['time', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            channel_1 = Window(B, 'Channel 1')
            channel_2 = Window(C, 'Channel 2')

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
    def openTiff(self, filename):
        Tiff = tifffile.TiffFile(str(filename))

        A = Tiff.asarray()
        Tiff.close()
        axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]
        print(axes)

        if set(axes) == set(['time', 'depth', 'height',
                             'width']):  # single channel, multi-volume
            target_axes = ['time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nScans, nFrames, x, y = A.shape

            self.channel1_array = A.reshape(nScans * nFrames, x, y)
            #newWindow = Window(self.channel1_array,'Loaded Tiff')

            nFrames, x, y = self.channel1_array.shape

            self.nChannels = 1
            self.nVolumes = nScans
            self.nFrames = nFrames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['series', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['series', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape

            self.channel1_array = A.reshape(nFrames, x, y)

            #uncomment to display original
            #newWindow = Window(self.channel1_array,'Loaded Tiff')

            self.nChannels = 1
            self.nVolumes = 1
            self.nFrames = nFrames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['time', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape

            self.channel1_array = A.reshape(nFrames, x, y)

            #uncomment to display original
            #newWindow = Window(self.channel1_array,'Loaded Tiff')

            self.nChannels = 1
            self.nVolumes = 1
            self.nFrames = nFrames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['time', 'depth', 'channel', 'height',
                               'width']):  # multi-channel, multi-volume
            target_axes = ['channel', 'time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            self.channel1_array = A[0]
            self.channel2_array = A[1]

            nChannels, nScans, nFrames, x, y = A.shape

            n1Scans, n1Frames, x1, y1 = self.channel1_array.shape
            n2Scans, n2Frames, x2, y2 = self.channel2_array.shape

            self.channel1_array = self.channel1_array.reshape(
                n1Scans * n1Frames, x1, y1)
            self.channel2_array = self.channel2_array.reshape(
                n2Scans * n2Frames, x2, y2)

            n1Frames, x1, y1 = self.channel1_array.shape
            n2Frames, x2, y2 = self.channel2_array.shape

            #uncomment to display original
            #self.channel_1 = Window(self.channel1_array,'Channel 1')
            #self.channel_2 = Window(self.channel2_array,'Channel 2')

            #original shape before splitting channel
            self.nChannels = nChannels
            self.nVolumes = nScans
            self.nFrames = n1Frames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['depth', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            self.channel1_array = A[0]
            self.channel2_array = A[1]

            nChannels, nFrames, x, y = A.shape

            n1Frames, x1, y1 = self.channel1_array.shape
            n2Frames, x2, y2 = self.channel2_array.shape

            #uncomment to display original
            #self.channel_1 = Window(self.channel1_array,'Channel 1')
            #self.channel_2 = Window(self.channel2_array,'Channel 2')

            #original shape before splitting channel
            self.nChannels = nChannels
            self.nVolumes = 1
            self.nFrames = n1Frames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['time', 'channel', 'height',
                               'width']):  # multi-channel, single volume
            target_axes = ['channel', 'time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            self.channel1_array = A[0]
            self.channel2_array = A[1]

            nChannels, nFrames, x, y = A.shape

            n1Frames, x1, y1 = self.channel1_array.shape
            n2Frames, x2, y2 = self.channel2_array.shape

            #uncomment to display original
            #self.channel_1 = Window(self.channel1_array,'Channel 1')
            #self.channel_2 = Window(self.channel2_array,'Channel 2')

            #original shape before splitting channel
            self.nChannels = nChannels
            self.nVolumes = 1
            self.nFrames = n1Frames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        elif set(axes) == set(['depth', 'height',
                               'width']):  # single channel, single-volume
            target_axes = ['depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape

            self.channel1_array = A.reshape(nFrames, x, y)

            #uncomment to display original
            #newWindow = Window(self.channel1_array,'Loaded Tiff')

            self.nChannels = 1
            self.nVolumes = 1
            self.nFrames = nFrames
            self.sclicesPerVolume = int(self.nFrames / self.nVolumes)

            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return

        else:
            print('tif axes header not recognized')
            self.errorFlag = True
            #clear A array to reduce memory use
            A = np.zeros((2, 2))
            return
Esempio n. 9
0
    def openTiff(self, filename):
        Tiff = tifffile.TiffFile(str(filename))

        A = Tiff.asarray()
        Tiff.close()
        axes = [tifffile.AXES_LABELS[ax] for ax in Tiff.series[0].axes]

        if set(axes) == set(['time', 'depth', 'height', 'width']):  # single channel, multi-volume
            target_axes = ['time', 'depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nScans, nFrames, x, y = A.shape

            A = A.reshape(nScans*nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')
            
            self.nChannels = 1
            self.nVolumes = nScans
            self.nFrames = nFrames
            return 
            
        elif set(axes) == set(['series', 'height', 'width']):  # single channel, single-volume
            target_axes = ['series', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')
            
            self.nChannels = 1
            self.nVolumes = 1
            self.nFrames = nFrames
            
            return 
            
        elif set(axes) == set(['time', 'height', 'width']):  # single channel, single-volume
            target_axes = ['time', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            nFrames, x, y = A.shape
            A = A.reshape(nFrames,x,y)
            newWindow = Window(A,'Loaded Tiff')  
                        
            self.nChannels = 1
            self.nVolumes = 1
            self.nFrames = nFrames
            
            return
            
        elif set(axes) == set(['time', 'depth', 'channel', 'height', 'width']):  # multi-channel, multi-volume
            target_axes = ['channel','time','depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]

            nChannels, nScans, nFrames, x, y = A.shape
            
            n1Scans, n1Frames, x1, y1 = B.shape
            n2Scans, n2Frames, x2, y2 = C.shape

            B = B.reshape(n1Scans*n1Frames,x1,y1)
            C = C.reshape(n2Scans*n2Frames,x2,y2)

            self.channel_1 = Window(B,'Channel 1')
            self.channel_2 = Window(C,'Channel 2')
            
            #original shape before splitting channel
            self.nChannels = nChannels
            self.nVolumes = nScans
            self.nFrames = nFrames

            return 

        elif set(axes) == set(['depth', 'channel', 'height', 'width']):  # multi-channel, single volume
            target_axes = ['channel','depth', 'width', 'height']
            perm = get_permutation_tuple(axes, target_axes)
            A = np.transpose(A, perm)
            B = A[0]
            C = A[1]
            
            nChannels, nFrames, x, y = A.shape
            
            n1Frames, x1, y1 = B.shape
            n2Frames, x2, y2 = C.shape

            self.channel_1 = Window(B,'Channel 1')
            self.channel_2 = Window(C,'Channel 2')
            
            #original shape before splitting channel            
            self.nChannels = nChannels
            self.nVolumes = 1
            self.nFrames = nFrames
            
            return