I’m referring to the WarpedView function from ImageTransformations.jl: ImageTransformations.jl · ImageTransformations. I can use imresize to interpolate a 3D image naively like: imresize(image, ratio=(1,1,z_res/xy_res))
, where z_res/xy_res
is the ratio of the z to the xy resolution. I think WarpedView is the appropriate function to do this operation lazily but I cannot tell from the documentation how to actually do it. Anyone know how to do so? Thanks.
imresize
defined by the given ratio can be defined as an image warping by the linear transformation of matrix:
[ 1 0 0 ;
0 1 0;
0 0 z_res/xy_res]
But the image warping is implemented via backward transformation:
using Images, ImageTransformations, CoordinateTransformations, Interpolations
function invtform(xy_res, z_res) #inverse transformation
M=[1 0 0 ; 0 1 0; 0 0 xy_res/z_res]
LinearMap(M)
end
img = load("image-3d.tif");
xy_res = 120
a, b, c= size(img)
imgw = warpedview(img, invtform(xy_res, c),
(1:a, 1:b, 1:round(Int, c^2/xy_res)); method=Lanczos(4))
Hi, thanks for the response. I should have clarified: what I meant by xy_res and z_res was the physical resolution per pixel in each direction. So, for example, 1 micron as the xy_res and 4 microns as the z_res. In your usage, these refer to the height, width, and number of slices of the image.
I interpreted xy_res
as DPI, and z_res
as number of slices.You shoud derive the image transformation and its inverse in the case of the right interpretation of the two parameters.
Okay, got it. Just wondering though – where did c^2/xy_res
come from as the third index?
c is the last element in 1:c. This value multiplied by z_res/xy_res, and rounded, gives the last value of the third index in the warped image. I stress again, the image transformation/warping is performed by the initial linear map. Its inverse is used only in the implementation of warpedview
.