1 year ago

#366877

test-img

Krunoslav Vinicki

Finding homography matrices for individual image tiles from a homography matrix that was calculated on the whole image

I'm trying to apply homography transformation on really large images (>30GB). So, my idea is to:

  1. Calculate the homography on the downscaled image.
  2. Do the matrix correction with [1, 1, F, 1, 1, F, 1/F, 1/F, 1] where F is the scaling factor.
  3. Apply "scaled" homography matrix on a full-size image.

Now, the problem with the third step is that I can't put the whole image in the RAM because during the transformation image data is converted from int8 to float, and the image size explodes. So, my question is:

Is there a way to divide the full-size image into separate tiles and then for every tile calculate new homography matrices from the homography calculated in step 2?

Here is the code (I hope it will make some thing clearer):

After calculating homography on downscaled image:

# "Scale" our homograpyhy matrix for the full size image
F = 2**base_lvl # scaling factor
S = [1, 1, F, 1, 1, F, 1/F, 1/F, 1]
S = np.array(S).reshape(3,3)
H_full_size = S * homography
tform = skimage.transform.ProjectiveTransform(matrix=H_full_size)

Here I'm doing transformations on separated channels to save on memory, but ideally I would like to do transformations on tiles:

# create temporary directory for saving single channel transformed arrays
path_tmp = Path('tmp')
path_tmp.mkdir(exist_ok=True)

height, width, channels = z_01[0].shape

zarr_paths = []
for color in range(channels):

    # do the transformation on single color channel
    # this saves RAM
    image = z_02[0][:, :, color]
    warped_img = (skimage.transform.warp(image, tform.inverse, output_shape=(height, width)) * 255.0).astype(np.uint8)

    zarr_paths.append(f'{path_tmp}/array_{color}.zarr')
    zarr.save(zarr_paths[-1], warped_img)

matrix = np.dstack((zarr.load(zarr_paths[0]), zarr.load(zarr_paths[1]), zarr.load(zarr_paths[2])))

Before anyone asks: of course I know how to divide an image into separate tiles. The problem is that, if I understood that correctly, in order to to the transformations on separate tiles, I need to modify homography array, in my case "tform", for every tile. Am I right?

python

opencv

scikit-image

homography

0 Answers

Your Answer

Accepted video resources