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