Пример #1
0
def readLIF(filepath, maxZ=False):
    reader = read_lif.Reader(filepath)
    series = reader.getSeries()
    r = series[0].getFrame(
        T=0,
        channel=0)  # image is a numpy array, first time point & first channel
    b = series[0].getFrame(T=0, channel=2)
    if maxZ == False:
        r1 = np.zeros([r.shape[0], r.shape[1]])
        b1 = np.zeros([b.shape[0], b.shape[1]])
        for i in range(8):
            r1 += r[:, :, i]
            b1 += b[:, :, i]
        img = skimage.transform.rotate(
            np.stack([r1, b1], axis=2) / (8 * 255), 270)
        img = cv2.flip(img, 1)
    else:
        meanR = np.zeros(8)
        for i in range(8):
            meanR[i] = np.mean(r[:, :, i])
        maxR = np.argmax(meanR)
        r1 = r[:, :, maxR]
        b1 = b[:, :, maxR]
        img = skimage.transform.rotate(np.stack([r1, b1], axis=2) / (255), 270)
        img = cv2.flip(img, 1)

    return (img[:, :, 0], img[:, :, 1])
Пример #2
0
    def read_lif_to_series(self, lif, outpath=None):
        basepath, filename = os.path.split(lif)
        if outpath == None:
            outpath = basepath

        reader = read_lif.Reader(lif)
        series = reader.getSeries()
        kwargs = {"outpath": outpath, "lif": lif}
        results = []
        for s in series:
            results.append(self.convert_series(s, **kwargs))
#        results = Parallel(n_jobs = self.n_jobs, verbose = 5)(delayed(self.convert_series)(x, **kwargs) for x in series)
        return results
Пример #3
0
def get_lif_images(img_name):
    reader = read_lif.Reader(img_name)
    series = reader.getSeries()
    imgs = []
    for s in series:
        chosen = s
        image = chosen.getFrame()
        img = np.max(image, axis=2)
        p2, p98 = np.percentile(img, (10, 99))
        img_rescale = exposure.rescale_intensity(img, in_range=(p2, p98))
        img_rescale = exposure.equalize_adapthist(img_rescale)
        imgs.append(img)
    return imgs
Пример #4
0
#ProgramRoot = os.path.dirname(sys.argv[0]) + '/'
ProgramRoot = '/Users/matteo/Documents/Uni/TESI/_python/ProgrammaMatteo/'

print('Program root: ' + str(ProgramRoot))


exec(open(str(ProgramRoot) + 'var_names.py').read())
exec(open(str(ProgramRoot) + 'functions.py').read())

#initialize variables and dictionaries
exec(open(str(ProgramRoot) + 'config/config_Pois.py').read())

#loading .lif file

lif_reader = read_lif.Reader(InputFolder + LIF_file_name)


series = lif_reader.getSeries()

flow = []

profile = []

for i in range(LIF_info[K_LIF_SERIES_NUM]):
    
    print('Calculating profile for data sets number %s' % (i+1))
    
    hyperstack = series[LIF_info[K_LIF_SERIES_LIST][i]]
    
    flow_matrix = np.zeros([LIF_info[K_LIF_FRAMES_NUMBER][i]-1, LIF_info[K_LIF_STACK_HEIGHT]-2])
Пример #5
0
    def parse(self, fname, z, series=None, reopen=True):
        ''' Parses file

        Saves parsed file in self.orig_data
        self.data is the array to be displayed
        '''
        if '.tif' in fname or '.tiff' in fname:
            self.tif_data = np.array(io.imread(fname)).astype('f4')
            self.num_slices = self.tif_data.shape[0]

            self.orig_data = self.tif_data[z, :, :, :]
            self.num_channels = self.orig_data.shape[-1]
            for i in range(self.num_channels):
                self.orig_data[:,:,:,i] = (self.orig_data[:,:,:,i] - self.orig_data[:,:,:,i].min()) / \
                                          (self.orig_data[:,:,:,i].max() - self.orig_data[:,:,:,i].min())
                self.orig_data[:, :, :, i] *= self.norm_factor
                self.log(self.orig_data.shape)
            self.data = np.copy(self.orig_data)
            self.old_fname = fname
            self.selected_slice = z
        else:
            if reopen:
                self.base_reader = read_lif.Reader(fname)
                if len(self.base_reader.getSeries()) == 1:
                    self.reader = self.base_reader.getSeries()[0]
                elif series is not None:
                    self.reader = self.base_reader.getSeries()[series]
                else:
                    return [s.getName() for s in self.base_reader.getSeries()]

                self.num_slices = self.reader.getFrameShape()[0]
                self.num_channels = len(self.reader.getChannels())
                md = self.reader.getMetadata()
                self.voxel_size = np.array([
                    md['voxel_size_x'], md['voxel_size_y'], md['voxel_size_z']
                ]) * 1e-6
                self.print('Voxel size: ', self.voxel_size)
                self.old_fname = fname

            #z = self.num_slices - 1 - z #flip z axis, now z=0 is the most upper slice
            # TODO: Look into modifying read_lif to get
            # a single Z-slice with all channels rather than all slices for a single channel
            self.orig_data = np.array([
                self.reader.getFrame(channel=i,
                                     dtype='u2')[z, :, :].astype('f4')
                for i in range(self.num_channels)
            ])
            self.orig_data = self.orig_data.transpose(1, 2, 0)
            #normalize to 100
            for i in range(self.orig_data.shape[-1]):
                self.orig_data[:, :, i] = (self.orig_data[:, :, i] - self.orig_data[:, :, i].min()) / \
                                             (self.orig_data[:, :, i].max() - self.orig_data[:, :, i].min())
                self.orig_data[:, :, i] *= self.norm_factor

            self.data = np.copy(self.orig_data)
            self.selected_slice = z
            [
                self._aligned_channels.append(False)
                for i in range(self.num_channels)
            ]
            [
                self._color_matrices.append(np.identity(3))
                for i in range(self.num_channels)
            ]

        if self._transformed:
            self.apply_transform(shift_points=False)
            self._update_data()
Пример #6
0
if not os.path.exists(folderOut+'/deconv/mip_c1'):
    os.makedirs(folderOut+'/deconv/mip_c1')
if not os.path.exists(folderOut+'/deconv/mip_c2'):
    os.makedirs(folderOut+'/deconv/mip_c2')
if not os.path.exists(folderOut+'/raw/c1'):
    os.makedirs(folderOut+'/raw/c1')
if not os.path.exists(folderOut+'/raw/c2'):
    os.makedirs(folderOut+'/raw/c2')

nb_channels = 1


for filename in os.listdir(folderIn):
    if filename.endswith(".lif") and filename[0] != ".":
        print(filename)
        reader = rl.Reader(os.path.join(folderIn, filename))
        lifImgSeries = reader.getSeries()
        idImg = 0
        idFn = 1
        for lifImg in lifImgSeries:
            print(len(lifImg.getChannels()))
            if len(lifImg.getChannels()) == 1:
                idImg = idImg + 1;
                if idImg%2==0: # Deconv
                    # Save tif volumes
                    for c in range(nb_channels):
                        imgC = lifImg.getFrame(T=0,channel=c,dtype=np.uint16)
                        imageio.mimwrite(os.path.join(folderOut, f'deconv/c{c+1}/',
                                                      os.path.splitext(filename)[0] + '_' + str(idFn) + '.tiff'), imgC)

                        mipC1 = np.amax(imgC, axis=0).astype('float32')