You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use ForwardDiff to compute the gradient of a cost function defined as the Sum of Square Differences (SSD) between two images with respect to the parameters of an image transformation. In the code shown below, one of the images has been translated by a small amount. This is basically just a toy problem that I designed to understand if ForwardDiff.jl and ImageTransformations.jl play well together. Eventually, I will compute derivatives relative the parameters of different image warps. Notice that I do not want to compute gradients of the pixel intensities, but, say, the 2x2 Jacobian of the translation, like:
using Images
using TestImages
using ImageTransformations
using ForwardDiff
img1 = testimage("cameraman.tif")
y_shift = 0.33
x_shift = -1.76
t = ImageTransformations.Translation(y_shift, x_shift)
img2 = ImageTransformations.warp(img1, t, ImageTransformations.indices_spatial(img1), 0)
function cost(Δ::Vector{T}) where T <: Real
t = ImageTransformations.Translation(Δ[2], Δ[1])
img2 = ImageTransformations.warp(img1, t, ImageTransformations.indices_spatial(img1), 0)
imgg1 = Gray.(img1)
imgg2 = Gray.(img2)
mat1 = convert(Array{Float64}, imgg1)
mat2 = convert(Array{Float64}, imgg2)
@. mat1 = (mat1 - mat2)^2
SSD = sum(vec(mat1))
return SSD
end
I am trying to use ForwardDiff to compute the gradient of a cost function defined as the Sum of Square Differences (SSD) between two images with respect to the parameters of an image transformation. In the code shown below, one of the images has been translated by a small amount. This is basically just a toy problem that I designed to understand if ForwardDiff.jl and ImageTransformations.jl play well together. Eventually, I will compute derivatives relative the parameters of different image warps. Notice that I do not want to compute gradients of the pixel intensities, but, say, the 2x2 Jacobian of the translation, like:
I’m getting this error:
Any ideas?
The text was updated successfully, but these errors were encountered: