Beispiel #1
0
    allen_sec_begin, allen_sec_end = allen_sec_range[stack_id]
    delta = allen_sec_end - allen_sec_begin
    initial_allen_sec = int(allen_sec_begin + float(sec_num) / nsection * delta)
    initial_allen_sec_index = argmin(abs(array(allen_secs) - initial_allen_sec))
    initial_allen_sec = allen_secs[initial_allen_sec_index]
    print 'initial_allen_sec:', initial_allen_sec
    
    test_sections = allen_secs[max(0, initial_allen_sec_index - 10):min(initial_allen_sec_index + 10, len(allen_secs))]
    print 'test_sections:', test_sections

    image_from_name = '{0}_{1}.tif'.format(stack_id, sec_num)
    image_from_fullname = SECTION_FOLDER + str(stack_id) + '/' + image_from_name
    
    matchings, test_sections = \
    util.conditional_load(image_from_name[:-4] + '_matchings', \
                          allen.get_allen_matching_multisections, \
                          (image_from_fullname, dataset_id, test_sections), \
                          regenerate=False, append_obj=test_sections)
    
#    quit()
    
    err_list = [m[-1] if m is not None else inf for m in matchings]
    print 'err_list:', err_list
    best_section = test_sections[argmin(err_list)]
    print 'best_section:', best_section
    chosen_secs_idx = [i for i, m in enumerate(matchings) if m is not None and m[-1] < RELEVANCY_THRESH]
    chosen_secs = [test_sections[i] for i in chosen_secs_idx]
    print 'chosen_secs:', chosen_secs
    
    query_keypoints = [matchings[i][1] for i in chosen_secs_idx]
    query_descriptors = [matchings[i][2] for i in chosen_secs_idx]
    allen_keypoints = [matchings[i][3] for i in chosen_secs_idx]
    
    import time
    begin = time.time()
    
    nsections = {3:0, 4:40, 5:32, 6:34, 9:28, 10:80}
    stack_id = 4
    nsection = nsections[stack_id]
    start_sec = 0

#    stack_id = 10
#    nsection = 50
#    start_sec = 30

    sections = range(start_sec, start_sec + nsection)
    
    d = util.conditional_load('_'.join(['d', 'stack',str(stack_id), 'start', str(start_sec)]), \
                            detect_keypoints, (stack_id, sections), regenerate=True)
    
    A, err, skip = util.conditional_load('_'.join(['A', 'model', str(MODEL), 'stack', str(stack_id),\
                                                    'start', str(start_sec)]), \
                                   find_transforms, [d], regenerate=True)
    
    print 'skipped:', skip
    
    #    k = 5; sift.draw_registration(ims[k], H[k][:2, :], ims[0])

    H, ims_reg = accumulate_transforms(d, A,reverse=False)
        
    print time.time() - begin
        
#    util.Plotter('Stack '+str(stack_id), ims_reg, 0)