Ejemplo n.º 1
0
def correct_drift(img1, img2, display_cc=False):
    ''' Returns two ImagePlus objects that are drift corrected to each other.
    The first image is not changed.
    The second image is a new image that is shifted using ImageJ's Translate.
    :param img1: The reference image.
    :param img2: The image to be shifted.
    :param display_cc: Activate displaying the CrossCorrelation image (default False).
    '''
    img1_cc, img2_cc = cc.scale_to_power_of_two([img1, img2])
    result = cc.perform_correlation(img1_cc, img2_cc)
    x_off, y_off = cc.get_shift(result)
    # style after maximum detection
    if not display_cc:
        result.hide()
    else:
        result.copyScale(img1)
        cc.style_cc(result)
    if x_off == 0 and y_off == 0:
        print('No drift has been detected.')
        return img1, img2
    title = img2.getTitle()
    img2_dk = Duplicator().run(img2)
    img2_dk.setTitle('DK-' + title)
    IJ.run(img2_dk, 'Translate...', 'x=%d y=%d interpolation=None' % (-x_off, -y_off))
    img2_dk.copyScale(img2)
    img2_dk.show()
    return img1, img2_dk
Ejemplo n.º 2
0
 def get_drift(i, j, _images):
     '''Returns the drift of imagej compared to image i'''
     cc_img = cc.perform_correlation(_images[i], _images[j])
     offset = cc.get_drift(cc_img)
     ''' DEBUG
     print 'Reference: %s at index %i' % (images[i],i)
     print 'Drifted image: %s at index %i' % (images[j],j)
     print 'Offset: %d,%d\n' % offset
     '''
     return offset