From e0ca030e10190290148c55b5a83d13c04721d2ec Mon Sep 17 00:00:00 2001 From: Jesper Stemann Andersen Date: Mon, 15 May 2023 16:26:06 +0200 Subject: [PATCH 1/2] Constrained image type for annotate to being an AbstractArray{<:Colorant, 2} --- Project.toml | 2 ++ src/ImageAnnotations.jl | 1 + src/abstract_image_annotator.jl | 2 +- src/static_image_annotator.jl | 2 +- 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 9ab8fbe..e7f6f1d 100644 --- a/Project.toml +++ b/Project.toml @@ -4,9 +4,11 @@ authors = ["IHP Systems R&D "] version = "0.6.0" [deps] +ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" [compat] +ColorTypes = "0.11.0" GeometryBasics = "0.4.1" julia = "1" diff --git a/src/ImageAnnotations.jl b/src/ImageAnnotations.jl index 521eab8..70622c5 100644 --- a/src/ImageAnnotations.jl +++ b/src/ImageAnnotations.jl @@ -1,5 +1,6 @@ module ImageAnnotations +using ColorTypes using GeometryBasics export AbstractConcept, AbstractConceptAttribute, CategoricalConceptAttribute, Concept diff --git a/src/abstract_image_annotator.jl b/src/abstract_image_annotator.jl index add1293..aaacd69 100644 --- a/src/abstract_image_annotator.jl +++ b/src/abstract_image_annotator.jl @@ -2,4 +2,4 @@ abstract type AbstractImageAnnotator{L, A <: AbstractImageAnnotation{L}} end abstract type AbstractObjectAnnotator{L, T, A <: AbstractObjectAnnotation{L, T}} <: AbstractImageAnnotator{L, A} end -annotate(image, annotator::AbstractImageAnnotator) = error("No implementation for $(typeof(annotator))") +annotate(image::AbstractArray{<:Colorant,2}, annotator::AbstractImageAnnotator) = error("No implementation for $(typeof(annotator))") diff --git a/src/static_image_annotator.jl b/src/static_image_annotator.jl index 067ef42..f2b3985 100644 --- a/src/static_image_annotator.jl +++ b/src/static_image_annotator.jl @@ -6,6 +6,6 @@ struct StaticObjectAnnotator{L, T <: Real, A <: AbstractObjectAnnotation{L, T}} annotations::Vector{A} end -function annotate(image, annotator::Union{StaticImageAnnotator, StaticObjectAnnotator}) +function annotate(image::AbstractArray{<:Colorant,2}, annotator::Union{StaticImageAnnotator, StaticObjectAnnotator}) return annotator.annotations end From de4c5c01c6403ce2d5463c9b983d9dd61bfb2d4b Mon Sep 17 00:00:00 2001 From: Jesper Stemann Andersen Date: Mon, 15 May 2023 16:26:51 +0200 Subject: [PATCH 2/2] WIP Added lazy image --- Project.toml | 1 + src/lazy_image.jl | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/lazy_image.jl diff --git a/Project.toml b/Project.toml index e7f6f1d..f55a65a 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.6.0" [deps] ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f" GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" +ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19" [compat] ColorTypes = "0.11.0" diff --git a/src/lazy_image.jl b/src/lazy_image.jl new file mode 100644 index 0000000..a90cd66 --- /dev/null +++ b/src/lazy_image.jl @@ -0,0 +1,23 @@ +abstract type AbstractLazyImage{TPixel <: Colorant} end + +struct LazyImageIOImage{TPixel} <: AbstractLazyImage{TPixel} + path::Union{String, Nothing} + image::Union{Array{TPixel, 2}, Nothing} +end + +LazyImageIOImage{TPixel}(path::String) = LazyImageIOImage{TPixel}(path, nothing) + +# Instance properties + +Base.propertynames(::LazyImageIOImage) = fieldnames(LazyImageIOImage) + +function Base.getproperty(image::LazyImageIOImage, name::Symbol) + if name == :image + if image.image === nothing + image.image = load(image.path) + end + return image.image + else + return getfield(image, name) + end +end