Reference
Index
FastCUDASSIM.FastCUDASSIMFastCUDASSIM.dssimFastCUDASSIM.dssim!FastCUDASSIM.dssim_gradientFastCUDASSIM.dssim_gradient!FastCUDASSIM.dssim_with_gradientFastCUDASSIM.dssim_with_gradient!FastCUDASSIM.ssimFastCUDASSIM.ssim!FastCUDASSIM.ssim_gradientFastCUDASSIM.ssim_gradient!FastCUDASSIM.ssim_with_gradientFastCUDASSIM.ssim_with_gradient!
Reference
FastCUDASSIM.FastCUDASSIM — Module
Package for computing the Structural Similarity Index Measure (SSIM) and its gradients on NVIDIA GPUs.
Quick start
julia> using FastCUDASSIM, CUDA
julia> img1 = CUDA.rand(Float32, 3, 512, 768); img2 = similar(img1);
julia> ssim(img1, img2) # Actual value depends on RNG above
4.7778763f-6Key points
- CUDA only
- We use zero-padding in the convolutions. The convolution kernel is the typical Gaussian with standard deviation $\sigma = 1.5$ and window size 11 x 11. We represent it using
Float32. - We expect Float-like image intensities in [0, 1]. This includes
N0f8. - Internally we use
channels x height x width x batch sizeformat for the input image batches, andheight x channels x width x batch sizefor internal buffers (N_dssims_dQand friends). Supplied inputs need not have this explicitsize, but must have an equivalent memory layout.
Image formats
- To expand on the last point, consider a
CuMatrix{RGB{N0f8}}of size(256, 384). It is equivalent (viachannelview) to aCuArray{N0f8, 3}of size(3, 256, 384), and (via a furtherreshape) to aCuArray{N0f8, 4}with size(3, 256, 384, 1). We will perform these conversions automatically. Therefore, this input is supported. - In these conversions we will (if necessary) first expand the channels dimension, followed by the batch dimension. Therefore, a
CuArray{Float32}ofsize(x, y, z)will be considered to be a singlex-channel image of heightyand widthz. To input a grayscale batch consisting ofzimages ofsize(x, y), either use aCuArray{Gray{Float32}, 3}withsize(x, y, z), or explicitly set the number of color channels to 1 via aCuArray{Float32, 4}ofsize(1, x, y, z). - When we internally allocate an output (D)SSIM or gradient batch (either because an allocating method like
dssim_with_gradientis called, or because in one of the mutating methods likedssim_with_gradient!the supplied value wasnothing), we will convert this back to a format similar to that of the first input image (batch). For example, if no batch axis appears here, then we will return a scalar (D)SSIM value instead of aCuVectoroflength1. There might be some promotions, though. For example,ssim_gradient(imgs1, imgs2)forimgs1aCuArray{RGB{N0f8}, 3}ofsize(256, 384, 16)andimgs2similar, will return aCuArray{RGB{Float32}, 3}gradient batch, again ofsize(256, 384, 16).
FastCUDASSIM.dssim — Function
dssim(
imgs1, imgs2,
divide_by_two_in_dssim = false
)Compute the Structural DisSimilarity Index Measure (DSSIM) values between two image batches.
Like dssim_with_gradient, but without the gradient.
See also ssim, and dssim! for the non-allocating version of dssim.
FastCUDASSIM.dssim! — Function
dssim!(
dssims,
imgs1, imgs2,
should_zero = true,
divide_by_two_in_dssim = false
)
-> dssimsCompute the DSSIMs between two image batches.
Like ssim!, but for the structural dissimilarity DSSIM = 1 - SSIM if !divide_by_two_in_dssim (the default) or DSSIM = (1 - SSIM) / 2 otherwise.
See also dssim_with_gradient!.
FastCUDASSIM.dssim_gradient — Function
dssim_gradient(
imgs1, imgs2,
divide_by_two_in_dssim = false
)Compute the gradients of the DSSIMs between two image batches with respect to the first.
Like dssim_with_gradient, but does not compute the DSSIM itself.
Similar to ssim_gradient, but for the DSSIM = 1 - SSIM when !divide_by_two_in_dssim (the default), or DSSIM = (1 - SSIM) / 2 otherwise. This method allocates (and frees) a number of buffers and of course also allocates the output gradient 'image' batch. See dssim_gradient! for the non-allocating version.
FastCUDASSIM.dssim_gradient! — Function
dssim_gradient!(
dL_dimgs1,
imgs1, imgs2,
N_dssims_dQ, N_dssims_dM, N_dssims_dP,
divide_by_two_in_dssim = false
)
-> dL_dimgs1Compute the gradients of the DSSIMs between two image batches with respect to the first one.
Like dssim_with_gradient!, but without the computation of the DSSIM itself, and like ssim_gradient!, but for the DSSIM = 1 - SSIM when !divide_by_two_in_dssim (the default) or DSSIM = (1 - SSIM) / 2 otherwise.
FastCUDASSIM.dssim_with_gradient — Function
dssim_with_gradient(
imgs1, imgs2,
divide_by_two_in_dssim = false
)Compute the DSSIMs between two image batches, as well as their gradients with respect to the first one.
Like ssim_with_gradient, but for the structural dissimilarity DSSIM = 1 - SSIM when !divide_by_two_in_dssim (the default), or DSSIM = (1 - SSIM) / 2 otherwise. See also dssim_with_gradient! for the non-allocating version.
FastCUDASSIM.dssim_with_gradient! — Function
dssim_with_gradient!(
dssims, dL_dimgs1,
imgs1, imgs2,
N_dssims_dQ, N_dssims_dM, N_dssims_dP,
should_zero = true,
divide_by_two_in_dssim = true
)
-> (dssims, dL_dimgs1)Compute the DSSIMs between two image batches, as well as the gradients with respect to the first one.
Like ssim_with_gradient!, but for the structural dissimilarity DSSIM = 1 - SSIM when !divide_by_two_in_dssim (by default), or DSSIM = (1 - SSIM) / 2.
FastCUDASSIM.ssim! — Function
ssim!(
ssims,
imgs1, imgs2,
should_zero = true
)
-> ssimsCompute the SSIMs between two image batches.
Like ssim_with_gradient! but does not compute the gradient. See this function for the meaning of the arguments.
FastCUDASSIM.ssim — Method
ssim(imgs1, imgs2)Compute the Structural Similarity Index Measure (SSIM) values between two image batches.
Like ssim_with_gradient, but without the gradient.
See the module documentation for the input and output formats. Also see ssim! for the non-allocating version.
FastCUDASSIM.ssim_gradient! — Method
ssim_gradient!(
dL_dimgs1,
imgs1, imgs2,
N_dssims_dQ, N_dssims_dM, N_dssims_dP,
)
-> dL_dimgs1Compute the gradients of the SSIM between two image batches with respect to the first one.
Like ssim_with_gradient!, but without the computation of the SSIM itself.
FastCUDASSIM.ssim_gradient — Method
ssim_gradient(imgs1, imgs2)Compute the gradients of the SSIMs between two image batches with respect to the first.
Like ssim_with_gradient, but does not compute the SSIM itself.
This method allocates (and frees) a number of buffers and of course also allocates the output gradient 'image' batch. See ssim_gradient! for the non-allocating version.
FastCUDASSIM.ssim_with_gradient! — Function
ssim_with_gradient!(
ssims, dL_dimgs1,
imgs1, imgs2,
N_dssims_dQ, N_dssims_dM, N_dssims_dP,
should_zero = true
)
-> (ssims, dL_dimgs1)Compute the SSIMs between two image batches, as well as the gradients with respect to the first one.
See the module documentation for the input and output formats.
Arguments
ssims: The (output)CuVectorwhich will contain the SSIM values.dL_dimgs1: The (output) gradients ofimgs1with respect to the SSIM value L.imgs1: The first image batch, with respect to which we compute the gradients.imgs2: The second image batch.N_dssims_dQ,N_dssims_dMandN_dssims_dP: Internal buffers for intermediate gradients.should_zero: To get the correct SSIM value we needssimsto start with values of0. When set totruewe will perform this zeroing inside the method. Otherwise it is the responsibility of the caller to have done this in advance. Defaults totrue.
Returns
(ssims, dL_dimgs1)
FastCUDASSIM.ssim_with_gradient — Method
ssim_with_gradient(imgs1, imgs2)Compute the SSIMs between two image batches, as well as the gradients with respect to the first one.
This method allocates (and frees) a number of buffers and of course also allocates the output gradient 'image' batch. See ssim_with_gradient! for the non-allocating version.
See the module documentation for expected formats for the inputs and output.
Arguments
imgs1: The first image batch.imgs2: The second image batch.
Returns
- The SSIM values.
- The gradients of these values with respect to
imgs1.