airlab-unibas / airlab

Image registration laboratory for 2D and 3D image data
Apache License 2.0
419 stars 94 forks source link

A quick hack for warping RGB images #19

Open bsugerman opened 5 years ago

bsugerman commented 5 years ago

If you are willing to find the warp/displacement on a grayscale version of the image, but want to apply it to all 3 layers in the color version, then here is a simple hack to warp_image():

def warp_image(image, displacement):
    image_size = image.size
    grid = compute_grid(image_size[:2], dtype=image.dtype, device=image.device)
    out=image_from_numpy(np.empty(image_size),(),(),device=image.device,dtype=image.dtype)
    if len(image_size==2):
        out.image =  transformation.utils.F.grid_sample(image.image, displacement + grid)
    else:
        for i in range(image_size[-1]):
            out.image[...,i] = transformation.utils.F.grid_sample(image.image[...,i], displacement + grid)
return out
asmagen commented 4 years ago

@bsugerman I am using drop2 registration for histopathology images but the outputs are deformation_field_x.nii.gz and deformation_field_y.nii.gz deformation fields which I would like to apply on the RGB png image channels to get a registered png RGB image.

Is there a quick way to apply your function on an RGB png image and the deformation field gz field above?

Thanks