Exemple #1
0
def load_movie_chain(file_list,
                     fr=None,
                     start_time=0,
                     meta_data=None,
                     subindices=None,
                     bottom=0,
                     top=0,
                     left=0,
                     right=0):
    ''' load movies from list of file names
    file_list: list of file names in string format
    other parameters as in load_movie except
    bottom, top, left, right to load only portion of the field of view
    '''
    mov = []
    for f in tqdm(file_list):
        m = load(f,
                 fr=fr,
                 start_time=start_time,
                 meta_data=meta_data,
                 subindices=subindices)
        if m.ndim == 2:
            m = m[np.newaxis, :, :]
        tm, h, w = np.shape(m)
        m = m[:, top:h - bottom, left:w - right]
        mov.append(m)
    return ts.concatenate(mov, axis=0)
Exemple #2
0
    def resize(self,fx=1,fy=1,fz=1,interpolation=cv2.INTER_AREA):
        """
        resize movies along axis and interpolate or lowpass when necessary
        it will not work without opencv

        Parameters
        -------------------
        fx,fy,fz:fraction/multiple of dimension (.5 means the image will be half the size)
        interpolation=cv2.INTER_AREA. Set to none if you do not want interpolation or lowpass


        """
        T,d1,d2 =self.shape
        d=d1*d2
        elm=d*T
        max_els=2**31-1
        if elm > max_els:
            chunk_size=(max_els)/d   
            new_m=[]
            print('Resizing in chunks because of opencv bug')
            for chunk in range(0,T,chunk_size):
                print([chunk,np.minimum(chunk+chunk_size,T)])                
                m_tmp=self[chunk:np.minimum(chunk+chunk_size,T)].copy()
                m_tmp=m_tmp.resize(fx=fx,fy=fy,fz=fz,interpolation=interpolation)
                if len(new_m) == 0:
                    new_m=m_tmp
                else:
                    new_m=timeseries.concatenate([new_m,m_tmp],axis=0)
                
            return new_m
        else:
            if fx!=1 or fy!=1:
                print "reshaping along x and y"
                t,h,w=self.shape
                newshape=(int(w*fy),int(h*fx))
                mov=[];
                print(newshape)
                for frame in self:
                    mov.append(cv2.resize(frame,newshape,fx=fx,fy=fy,interpolation=interpolation))
                self=movie(np.asarray(mov),**self.__dict__)
            if fz!=1:
                print "reshaping along z"
                t,h,w=self.shape
                self=np.reshape(self,(t,h*w))
                mov=cv2.resize(self,(h*w,int(fz*t)),fx=1,fy=fz,interpolation=interpolation)
    #            self=cv2.resize(self,(h*w,int(fz*t)),fx=1,fy=fz,interpolation=interpolation)
                mov=np.reshape(mov,(np.maximum(1,int(fz*t)),h,w))
                self=movie(mov,**self.__dict__)
                self.fr=self.fr*fz

        return self
Exemple #3
0
def load_movie_chain(file_list,fr=None,start_time=0,meta_data=None,subindices=None,bottom=0,top=0,left=0,right=0):
    ''' load movies from list of file names
    file_list: list of file names in string format
    other parameters as in load_movie except
    bottom, top, left, right to load only portion of the field of view
    '''

    mov=[];    
    for f in file_list:
        m=load(f,fr=fr,start_time=start_time,meta_data=meta_data,subindices=subindices);
        tm,h,w=np.shape(m)
        m=m[:,top:h-bottom,left:w-right]
        mov.append(m)
        
    return ts.concatenate(mov,axis=0)
Exemple #4
0
    def resize(self, fx=1, fy=1, fz=1, interpolation=cv2.INTER_AREA):
        """
        resize movies along axis and interpolate or lowpass when necessary
        it will not work without opencv

        Parameters
        -------------------
        fx,fy,fz:fraction/multiple of dimension (.5 means the image will be half the size)
        interpolation=cv2.INTER_AREA. Set to none if you do not want interpolation or lowpass


        """
        T, d1, d2 = self.shape
        d = d1 * d2
        elm = d * T
        max_els = 2**31 - 1
        if elm > max_els:
            chunk_size = (max_els) / d
            new_m = []
            print('Resizing in chunks because of opencv bug')
            for chunk in range(0, T, chunk_size):
                print([chunk, np.minimum(chunk + chunk_size, T)])
                m_tmp = self[chunk:np.minimum(chunk + chunk_size, T)].copy()
                m_tmp = m_tmp.resize(fx=fx,
                                     fy=fy,
                                     fz=fz,
                                     interpolation=interpolation)
                if len(new_m) == 0:
                    new_m = m_tmp
                else:
                    new_m = timeseries.concatenate([new_m, m_tmp], axis=0)

            return new_m
        else:
            if fx != 1 or fy != 1:
                print "reshaping along x and y"
                t, h, w = self.shape
                newshape = (int(w * fy), int(h * fx))
                mov = []
                print(newshape)
                for frame in self:
                    mov.append(
                        cv2.resize(frame,
                                   newshape,
                                   fx=fx,
                                   fy=fy,
                                   interpolation=interpolation))
                self = movie(np.asarray(mov), **self.__dict__)
            if fz != 1:
                print "reshaping along z"
                t, h, w = self.shape
                self = np.reshape(self, (t, h * w))
                mov = cv2.resize(self, (h * w, int(fz * t)),
                                 fx=1,
                                 fy=fz,
                                 interpolation=interpolation)
                #            self=cv2.resize(self,(h*w,int(fz*t)),fx=1,fy=fz,interpolation=interpolation)
                mov = np.reshape(mov, (np.maximum(1, int(fz * t)), h, w))
                self = movie(mov, **self.__dict__)
                self.fr = self.fr * fz

        return self
Exemple #5
0
def load_movie_chain(file_list,fr=None,start_time=0,meta_data=None,subindices=None):
    mov=[];    
    for f in file_list:
        mov.append(load(f,fr=fr,start_time=start_time,meta_data=meta_data,subindices=subindices))
        
    return ts.concatenate(mov,axis=0)