Skip to content

Commit

Permalink
More fixes for Julia v0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Sep 5, 2018
1 parent a0a2361 commit 565403e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 21 deletions.
2 changes: 0 additions & 2 deletions src/ImageInpainting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# Licensed under the ISC License. See LICENCE in the project root.
# ------------------------------------------------------------------

__precompile__()

module ImageInpainting

using ImageMorphology
Expand Down
10 changes: 4 additions & 6 deletions src/crimisini.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function inpaint_impl(img::AbstractArray{T,N}, mask::BitArray{N}, algo::Crimisin
padimg[isnan.(padimg)] .= zero(T)

# inpainting frontier
δΩ = find(dilate(ϕ) - ϕ)
δΩ = findall(dilate(ϕ) .& .!ϕ)

while !isempty(δΩ)
# update confidence values in frontier
Expand All @@ -73,10 +73,8 @@ function inpaint_impl(img::AbstractArray{T,N}, mask::BitArray{N}, algo::Crimisin
Δ[mask] .= Inf

# find index in padded arrays
idx = argmin(Δ)
sub = ind2sub(size(Δ), idx)
padsub = [sub[i] + (tilesize[i]-1)÷2 for i in 1:length(tilesize)]
q = sub2ind(size(padimg), padsub...)
sub = argmin(Δ)
q = ntuple(i -> sub[i] + (tilesize[i]-1)÷2, N)

# select best candidate
ψᵦ, bᵦ = selectpatch((padimg, ϕ), tilesize, q)
Expand All @@ -87,7 +85,7 @@ function inpaint_impl(img::AbstractArray{T,N}, mask::BitArray{N}, algo::Crimisin
bₚ[b] .= true

# update frontier
δΩ = find(dilate(ϕ) - ϕ)
δΩ = findall(dilate(ϕ) .& .!ϕ)
end

view(padimg, [1+prepad[i]:size(padimg,i)-postpad[i] for i=1:N]...)
Expand Down
5 changes: 2 additions & 3 deletions src/pointgradients.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ function pointgradients(img::AbstractArray, points::AbstractVector; method=:ando

A = zeros(size(kern))
shape = size(kern)
for (k, p) in enumerate(points)
icenter = CartesianIndex(ind2sub(extent, p))
i1 = CartesianIndex(tuple(ones(Int, ndirs)...))
for (k, icenter) in enumerate(points)
i1 = CartesianIndex(ntuple(i->1, ndirs))
for ii in CartesianIndices(shape)
A[ii] = padimg[ii + icenter - i1]
end
Expand Down
17 changes: 7 additions & 10 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,18 @@ function convdist(img::AbstractArray, kern::AbstractArray; weights=nothing)
end

"""
selectpatch(imgs, psize, p)
selectpatch(imgs, tilesize, center)
Helper function to extract a patch of size
`psize` from `imgs` centered at index `p`.
`tilesize` from `imgs` centered at Cartesian
index `center`.
"""
function selectpatch(imgs, psize, p)
imsize = size(imgs[1])
N = length(imsize)

# patch center
center = ind2sub(imsize, p)
function selectpatch(imgs, tilesize, center)
N = length(tilesize)

# patch corners
start = [center[i] - (psize[i]-1) ÷ 2 for i=1:N]
finish = [center[i] + psize[i] ÷ 2 for i=1:N]
start = ntuple(i -> center[i] - (tilesize[i]-1) ÷ 2, N)
finish = ntuple(i -> center[i] + tilesize[i] ÷ 2, N)

[view(img, [start[i]:finish[i] for i=1:N]...) for img in imgs]
end
Binary file modified test/data/Blobs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/data/LightHouse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 565403e

Please sign in to comment.