-
Notifications
You must be signed in to change notification settings - Fork 22
Bug/move std to cvs #125
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
Bug/move std to cvs #125
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import Base: abs, abs2, clamp, convert, copy, div, eps, isfinite, isinf, | |
import LinearAlgebra: norm | ||
import StatsBase: histrange, varm | ||
import SpecialFunctions: gamma, lgamma, lfact | ||
import Statistics: middle | ||
import Statistics: middle, var, std | ||
|
||
export nan | ||
|
||
|
@@ -207,6 +207,35 @@ for op in unaryOps | |
@eval ($op)(c::AbstractGray) = $op(gray(c)) | ||
end | ||
|
||
function var(A::AbstractArray{C}; kwargs...) where C<:AbstractGray | ||
imgc = channelview(A) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, But given that the best place I have in mind for cc: @timholy There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need the BTW, I do not fully understand why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, we don't necessarily need, but it would make trivial things less trivial. Another choice is to move these functions to
Generally, for non-gray image For example, PSNR treats RGB and other Color3 images differently. https://github.com/JuliaImages/ImageQualityIndexes.jl/blob/master/src/psnr.jl#L13-L21 From wikipedia
I agree that we may need one more method for It's a little inconsistent, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, if there are no clear rules about combining channels, ColorVectorSpace should only support a single-channel (grayscale) arrays. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically I agree with you. From the commit history I think deprecating it would be acceptable. But at least for now the best choice is to move it here and to add a deprecation warning. My suggestion is to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may think my comments are inconsistent, but I'm not negative in channel-wise variance itself. I just care about the problem of a lower-level package depending on higher-level packages. julia> using Statistics
julia> wbb = [[1.0,1.0,1.0], [0.0,0.0,0.0], [0.0,0.0,0.0]]
3-element Array{Array{Float64,1},1}:
[1.0, 1.0, 1.0]
[0.0, 0.0, 0.0]
[0.0, 0.0, 0.0]
julia> rgb = [[1.0,0.0,0.0], [0.0,1.0,0.0], [0.0,0.0,1.0]]
3-element Array{Array{Float64,1},1}:
[1.0, 0.0, 0.0]
[0.0, 1.0, 0.0]
[0.0, 0.0, 1.0]
julia> var(wbb)
3-element Array{Float64,1}:
0.33333333333333337
0.33333333333333337
0.33333333333333337
julia> var(rgb)
3-element Array{Float64,1}:
0.33333333333333337
0.33333333333333337
0.33333333333333337 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It makes sense. I had a feeling about that but didn't check that previously. Corrects me if I don't understand it right, let me try to state the roles of ImageCore, Colors and ColorVectorSpaces
Revisiting ColorVectorSpaces, I don't see any method on Array types. I now think I was wrong saying ColorVectorSpace is the most suitable place for For the array-level glue package, we only have For this PR, one thing for sure is that But...I now think it might be better to stay in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree for the most part of the roles. Similarly,
My comment above
means "2.". I don't think "pixel-level" or "array-level" is the essence of the problem. Therefore, I think that defining "default" (fallback)
The current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, I understand this is the motivation of this package. Still, I tried to avoid saying this when I described the roles because I thought it doesn't help to solve the current issue. For example, by saying this, any function in ImageDistances has their right to stay here, but introducing any of them would trigger such a discussion thread.
The pixel/array level difference is the only thing that I can speak of the low/high level abstraction. Since both packages don't strictly rely on each other, we can't say that one is more fundamental than the other. As I said, not using channelview would make trivial things less trivial, it's not very replicable. If we can't use Thus, I prefer to create an ImageBase package to fit these kinds of needs for array-level operations. Indeed, if there's no objection about that, I can do it myself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The difference from Statistics is that Distance is not a stdlib. I do not object to creating a new package to reduce the size of the package. (I think ImageCore and ImageBase can be confusing, though.)
ColorVectorSpace defines the color arithmetic. Perhaps the "pixel-level" you said might mean that, but the arithmetic should be independent of the shape of arrays. In short, the problem with
What you said is correct, but no channel splitter is needed to calculate channel-wise mapreduce(color->mapc(abs2, color - mean_color), +, A) Handling the keyword arguments (especially |
||
base_colorant_type(C)(var(imgc; kwargs...)) | ||
end | ||
|
||
function var(A::AbstractArray{C,N}; kwargs...) where {C<:Colorant,N} | ||
imgc = channelview(A) | ||
colons = ntuple(d->Colon(), Val(N)) | ||
inds1 = axes(imgc, 1) | ||
val1 = var(view(imgc, first(inds1), colons...); kwargs...) | ||
vals = similar(imgc, typeof(val1), inds1) | ||
vals[1] = val1 | ||
for i in first(inds1)+1:last(inds1) | ||
vals[i] = var(view(imgc, i, colons...); kwargs...) | ||
end | ||
base_colorant_type(C)(vals...) | ||
end | ||
|
||
""" | ||
y = complement(x) | ||
|
||
Take the complement `1-x` of `x`. If `x` is a color with an alpha channel, | ||
the alpha channel is left untouched. Don't forget to add a dot when `x` is | ||
an array: `complement.(x)` | ||
""" | ||
complement(x::Union{Number,Colorant}) = oneunit(x)-x | ||
complement(x::TransparentColor) = typeof(x)(complement(color(x)), alpha(x)) | ||
|
||
std(A::AbstractArray{C}; kwargs...) where {C<:Colorant} = mapc(sqrt, var(A; kwargs...)) | ||
middle(c::AbstractGray) = arith_colorant_type(c)(middle(gray(c))) | ||
middle(x::C, y::C) where {C<:AbstractGray} = arith_colorant_type(C)(middle(gray(x), gray(y))) | ||
|
||
|
@@ -343,4 +372,5 @@ _precompile_() | |
@deprecate (*)(A::AbstractArray{T}, b::TransparentGray) where {T<:Number} A.*b | ||
@deprecate (*)(b::TransparentGray, A::AbstractArray{T}) where {T<:Number} A.*b | ||
|
||
@deprecate complement(x::AbstractArray) complement.(x) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,13 @@ end | |
@test Gray24(0.8)*0.5 === Gray(0.4) | ||
@test Gray24(0.8)/2 === Gray(0.5f0*N0f8(0.8)) | ||
@test Gray24(0.8)/2.0 === Gray(0.4) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The failed Could you also add some tests for |
||
# Complement | ||
@test complement(Gray(0.5)) == Gray(0.5) | ||
@test complement(Gray(0.2)) == Gray(0.8) | ||
@test all(complement.(img) .== 1 .- img) | ||
# deprecated (#690) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the link is invalid now, needs update to JuliaImages/Images.jl#690 |
||
@test all(complement.(img) .== 1 .- img) | ||
end | ||
|
||
@testset "Comparisons with Gray" begin | ||
|
@@ -276,6 +283,14 @@ end | |
@test RGB24(1,0,0)/2.0 === RGB(0.5,0,0) | ||
end | ||
|
||
@testset "Complement" begin | ||
@test complement.([Gray(0.2)]) == [Gray(0.8)] | ||
@test complement.([Gray{N0f8}(0.2)]) == [Gray{N0f8}(0.8)] | ||
@test complement.([RGB(0,0.3,1)]) == [RGB(1,0.7,0)] | ||
@test complement.([RGBA(0,0.3,1,0.7)]) == [RGBA(1.0,0.7,0.0,0.7)] | ||
@test complement.([RGBA{N0f8}(0,0.6,1,0.7)]) == [RGBA{N0f8}(1.0,0.4,0.0,0.7)] | ||
end | ||
|
||
@testset "Arithemtic with RGBA" begin | ||
cf = RGBA{Float32}(0.1,0.2,0.3,0.4) | ||
@test @inferred(zero(cf)) === RGBA{Float32}(0,0,0,0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
complement
needs to be exported so that users don't need to writeColorVectorSpaces.complement
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that be as simple as
export complement
in that case?