예제 #1
0
def main():
    # make a tuple of strings - input file names
    t_input_files = ("CW2003_H14_M57_S54_msCam1_frame0to99.tiff",
                     )  # notice comma(!)
    for s_fname in t_input_files:
        print("Input file: %s" % s_fname)

    # create a multi-part movie object
    oc_movie = CMuPaMovieTiff(t_input_files)

    print("\nMovie information:")
    print(oc_movie.df_info)
    print()

    l_frames = []
    i_frame_id = 0

    # read first N frames
    while (oc_movie.read_next_frame()):
        print("%s" % oc_movie.get_frame_stat())
        l_frames.append(oc_movie.na_frame)
        i_frame_id += 1
        # if i_frame_id >= 30: break

    # show the frames
    print("\nUsage: (p)revious frame, (n)ext frame, (q)uit.")
    moshow("frames", l_frames)
예제 #2
0
def pre_filter_all_with_mocorr(s_in_fname, oc_rec_cfg):
    oc_movie = CMuPaMovieTiff((s_in_fname,))
    l_frames = []
    i_frame_id = 0
    oc_pw_ecc = None
    oc_motion_field = None
    i_median_flt_sz = int(oc_rec_cfg["median_blur"])

    while(oc_movie.read_next_frame()):
        # print("Frame number:", i_frame_id)

        # pre-filter each frame locally (used for debugging)
        # na_frame = pre_filter_single_frame(oc_movie.na_frame)

        na_frame = cv.medianBlur(oc_movie.na_frame, i_median_flt_sz)
        na_frame_to_register = cv.normalize(na_frame, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F)

        if oc_pw_ecc is None:
            oc_pw_ecc = CPieceWiseECC(
                na_frame.shape[0], # frame height!
                na_frame.shape[1], # frame width!
                na_frame.dtype,
                oc_rec_cfg
            )
            oc_motion_field = CMotionFieldDrawer(
                na_frame.shape[0], # frame height!
                na_frame.shape[1], # frame width!
                int(oc_rec_cfg["pw_ecc_nrow_tiles"]),
                int(oc_rec_cfg["pw_ecc_ncol_tiles"]),
                f_zoom_coef=10.0
            )
        oc_pw_ecc.process_frame(na_frame, b_verbose=True)
        # normal way to register the frames
        oc_pw_ecc.register_frame()
        # you can register frames with background left untouched, for debugging
        # oc_pw_ecc.register_frame(na_input=na_frame_to_register)

        if i_frame_id < 3:
            plt.subplot(221)
            plt.imshow(oc_pw_ecc.d_REG['PW_REG_corr_coef'][-1])
            plt.subplot(222)
            plt.imshow(oc_pw_ecc.d_REG['PW_REG_warp_matrix'][-1])
            plt.subplot(223)
            plt.imshow(oc_pw_ecc.d_REG['PW_REG_inter_patch_dist'][-1])
            plt.subplot(224)
            oc_motion_field.process_frame(oc_pw_ecc.oc_twM)
            plt.imshow(oc_motion_field.na_out)
            plt.show()

        # l_frames.append(oc_pw_ecc.na_out.copy())
        # l_frames.append(oc_pw_ecc.na_out_reg.copy())
        l_frames.append(np.hstack([na_frame_to_register, oc_pw_ecc.na_out_reg]))
        i_frame_id += 1
        # if i_frame_id >= 10: break
    print(oc_pw_ecc.d_REG['PW_REG_not_converged'])
    print(oc_pw_ecc.d_REG['PW_REG_high_jumps'])
    moshow("frames", l_frames)
예제 #3
0
def show_whole_input(s_in_fname):
    # create a multi-part movie object
    oc_movie = CMuPaMovieTiff((s_in_fname,))

    print("\nMovie information:")
    print(oc_movie.df_info)
    print()

    l_frames = []

    # read first N frames
    while(oc_movie.read_next_frame()):
        print("%s" % oc_movie.get_frame_stat())
        l_frames.append(oc_movie.na_frame)

    # show the frames
    print("\nUsage: (p)revious frame, (n)ext frame, (q)uit.")
    moshow("frames", l_frames)
예제 #4
0
def pre_filter_all_frames(s_in_fname):
    l_frames = []
    i_frame_id = 0
    i_niter = 3
    i_median_blur_sz = 5
    oc_filter = CFastGuidedFilter(3)
    oc_strel_kernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (7,7))
    oc_movie = CMuPaMovieTiff((s_in_fname,))

    while(oc_movie.read_next_frame()):
        na_frame = cv.medianBlur(oc_movie.na_frame, i_median_blur_sz)
        oc_filter.process_frame(cv.normalize(na_frame, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F))
        na_background = cv.morphologyEx(oc_filter.na_out, cv.MORPH_OPEN, oc_strel_kernel, iterations=i_niter)
        na_signal = cv.normalize(oc_filter.na_out - na_background, None, alpha=0, beta=255, norm_type=cv.NORM_MINMAX, dtype=cv.CV_8U)
        # l_frames.append(na_signal)
        l_frames.append(np.hstack([
            cv.normalize(na_frame,  None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F),
            cv.normalize(na_signal, None, alpha=0, beta=1, norm_type=cv.NORM_MINMAX, dtype=cv.CV_32F),
        ]))
        if i_frame_id % 10 == 0: print(i_frame_id)
        i_frame_id += 1
    moshow("frames", l_frames)
def main():
    # load local configuration file
    oc_rec_cfg = configparser.ConfigParser()
    oc_rec_cfg.read("CW2003_H14_M57_S54_msCam1_frame0to99.ini")

    # make a tuple of strings - input file names
    t_input_files = ("CW2003_H14_M57_S54_msCam1_frame0to99.tiff",
                     )  # notice comma(!)

    for s_fname in t_input_files:
        print("Input file: %s" % s_fname)

    # create a multi-part movie object
    oc_movie = CMuPaMovieTiff(t_input_files)

    print("\nMovie information:")
    print(oc_movie.df_info)
    print()

    oc_pc1_wiper = None
    oc_register = None

    l_frames = []
    i_frame_id = 0

    # read the movie frame by frame, register frames, stack with raw frame and add into the l_frames
    while (oc_movie.read_next_frame()):
        print("%s" % oc_movie.get_frame_stat())

        if i_frame_id == 0:
            oc_pc1_wiper = CPrinCompWiper(
                oc_movie.na_frame.shape[0],  # frame height!
                oc_movie.na_frame.shape[1]  # frame width!
            )
            oc_register = CFrameRegECC(
                oc_movie.na_frame.shape[0],  # frame height!
                oc_movie.na_frame.shape[1],  # frame width!
                oc_movie.na_frame.dtype,
                oc_rec_cfg["frame_registration"])

        oc_pc1_wiper.process_frame(oc_movie.na_frame)
        oc_register.process_frame(oc_pc1_wiper.na_out)
        oc_register.register_frame()

        na_frame_before = cv2.normalize(oc_movie.na_frame,
                                        None,
                                        alpha=0,
                                        beta=1,
                                        norm_type=cv2.NORM_MINMAX,
                                        dtype=cv2.CV_32F)
        na_frame_after = cv2.normalize(oc_register.na_out_reg,
                                       None,
                                       alpha=0,
                                       beta=1,
                                       norm_type=cv2.NORM_MINMAX,
                                       dtype=cv2.CV_32F)

        l_frames.append(np.vstack([na_frame_before, na_frame_after]))
        i_frame_id += 1
        # if i_frame_id >= 30: break

    # show the frames
    print("\nUsage: (p)revious frame, (n)ext frame, (q)uit.")
    moshow("frames", l_frames)