Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more fixes for v0.7/v1.0 #29

Merged
merged 2 commits into from
Aug 19, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
script:
- julia -e 'import Pkg; Pkg.clone(pwd()); Pkg.build("ImageMetadata")'
- julia -e 'import Pkg; Pkg.add("Documenter")'
- julia -e 'import ImageCore; ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs","make.jl"))'
- julia -e 'import ImageMetadata; ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs","make.jl"))'

after_success:
# push coverage results to Codecov
Expand Down
30 changes: 16 additions & 14 deletions src/ImageMetadata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ using ColorVectorSpace # for overriding math operations with Gray/RGB
using Compat
import AxisArrays

import Base: +, .+, -, .-, *, .*, /, ./, .^, .<, .>, .==
import Base: +, -, *, /
import Base: permutedims

Expand Down Expand Up @@ -163,16 +162,8 @@ Base.delete!(img::ImageMeta, propname::AbstractString) = delete!(img.properties,

# Iteration
# Defer to the array object in case it has special iteration defined
if isdefined(Base, :LegacyIterationCompat)
# Base.iterate(img::ImageMeta{Array{T,N}}, s=1) where {T,N} = iterate(data(img), s)
# Base.iterate(img::ImageMeta, s=(eachindex(img),)) = iterate(data(img), s)
Base.iterate(img::ImageMeta) = Base.iterate(data(img))
Base.iterate(img::ImageMeta, s) = Base.iterate(data(img), s)
else
Base.start(img::ImageMeta) = start(data(img))
Base.next(img::ImageMeta, s) = next(data(img), s)
Base.done(img::ImageMeta, s) = done(data(img), s)
end
Base.iterate(img::ImageMeta) = Base.iterate(data(img))
Base.iterate(img::ImageMeta, s) = Base.iterate(data(img), s)

# Show
const emptyset = Set()
Expand All @@ -184,8 +175,11 @@ end
Base.show(io::IO, img::ImageMeta) = showim(io, img)
Base.show(io::IO, ::MIME"text/plain", img::ImageMeta) = showim(io, img)

Base.reinterpret(::Type{T}, img::ImageMetaArray) where {T} = shareproperties(img, reinterpret(T, img.data))
Base.reinterpret(::Type{T}, img::ImageMeta) where {T} = error("reinterpret method not defined for $(typeof(img)). Consider a MappedArray instead.")
function ImageCore.reinterpret(::Type{T}, img::ImageMeta{T2,N,A}) where {T,T2,N,A}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reinterpret really belongs to Base, not ImageCore. (reinterpretc belongs to ImageCore)

(A <: Array) || error("reinterpret method not defined for $(typeof(img)). Consider a MappedArray instead.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the new reinterpret doesn't have this limitation anymore (?)
That said, I don't know this. This will need someone like Prof Holy to review (which I saw you already pinged, so I won't ping again)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it's not a limitation anymore.

shareproperties(img, reinterpret(T, img.data))
end


"""
data(img::ImageMeta) -> array
Expand All @@ -204,6 +198,7 @@ function ImageCore.permuteddimsview(A::ImageMeta, perm)
end
ImageCore.channelview(A::ImageMeta) = shareproperties(A, channelview(A.data))
ImageCore.colorview(::Type{C}, A::ImageMeta{T,N}) where {C<:Colorant,T,N} = shareproperties(A, colorview(C, A.data))
ImageCore.colorview(::Type{ARGB32}, A::ImageMeta{T,N}) where {T,N} = shareproperties(A, colorview(ARGB32, A.data))
ImageCore.rawview(A::ImageMeta{T}) where {T<:Real} = shareproperties(A, rawview(A.data))
ImageCore.normedview(::Type{T}, A::ImageMeta{S}) where {T<:FixedPoint,S<:Unsigned} = shareproperties(A, normedview(T, A.data))

Expand Down Expand Up @@ -317,7 +312,14 @@ function permutedims(img::ImageMeta, perm)
permutedims_props!(copyproperties(img, permutedims(img.data, perm)), ip)
end

Base.adjoint(img::ImageMeta{T,2}) where {T<:Real} = permutedims(img, (2,1))
"""
Note: `adjoint` does not recurse into ImageMeta properties.
"""
function Base.adjoint(img::ImageMeta{T,2}) where {T<:Real}
ip = sortperm([2,1][[coords_spatial(img)...]])
permutedims_props!(copyproperties(img, adjoint(img.data)), ip)
end

function Base.adjoint(img::ImageMeta{T,1}) where T<:Real
check_empty_spatialproperties(img)
copyproperties(img, img.data')
Expand Down
26 changes: 13 additions & 13 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ end
@test convert(ImageMeta{Gray}, A) == A
end

# @testset "reinterpret" begin
# # It's possible that reinterpret shouldn't be defined for ImageMeta, but...
# A = rand(Float32, 4, 5)
# M = ImageMeta(A, meta=true)
# Mr = reinterpret(Gray, M)
# @test eltype(Mr) == Gray{Float32}
# @test Mr["meta"] = true
# # Ensure that it never gets defined for the un-reinterpretable
# M = ImageMeta(view(A, 1:2:3, 1:4), meta=true)
# @test_throws ErrorException reinterpret(Gray, M)
# @test_throws ErrorException reinterpret(Gray{Float32}, M)
# end
@testset "reinterpret" begin
# It's possible that reinterpretc shouldn't be defined for ImageMeta, but...
A = rand(Float32, 4, 5)
M = ImageMeta(A, meta=true)
Mr = reinterpretc(Gray, M)
@test eltype(Mr) == Gray{Float32}
@test Mr["meta"] = true
# Ensure that it never gets defined for the un-reinterpretable
M = ImageMeta(view(A, 1:2:3, 1:4), meta=true)
@test_throws ErrorException reinterpretc(Gray, M)
@test_throws ErrorException reinterpretc(Gray{Float32}, M)
end

@testset "copy/similar" begin
img = ImageMeta(rand(3,5); prop1 = 1, prop2 = [1,2,3])
Expand Down Expand Up @@ -264,7 +264,7 @@ end
@test axisvalues(M) == (1:3, 1:5)
@test M[Axis{:y}(2:3)] == A[Axis{:y}(2:3)]
@test view(M, Axis{:y}(2:3)) == A[Axis{:y}(2:3)]
M[Axis{:y}(2:3), Axis{:x}(1)] = -5
M[Axis{:y}(2:3), Axis{:x}(1)] .= -5
@test all(A[2:3,1] .== -5)
end

Expand Down
2 changes: 0 additions & 2 deletions test/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,5 @@ Ms = dropdims(Mp, dims=1)

img = convert(ImageMeta{Gray{N0f16}}, [0.01164 0.01118; 0.01036 0.01187])
@test all((1 .- img) .== (1 .- img))
@info "Two Warnings expected for test"
@test all(1 - img .== 1 - img)

nothing