-
Notifications
You must be signed in to change notification settings - Fork 19
the wraparound behavior of using N0f8 seems unwanted? #63
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
Comments
That is expected behaviour. If you want to have more flexibility use floating point number. They can also use numbers outside the color domain julia> c = RGB{N0f8}(0.1, 0.2, 0.3)
RGB{N0f8}(0.102,0.2,0.298)
julia> c - c - c
RGB{N0f8}(0.902,0.804,0.706)
julia> c2 = RGB{Float32}(0.1, 0.2, 0.3)
RGB{Float32}(0.1f0,0.2f0,0.3f0)
julia> c2 - c2 - c2
RGB{Float32}(-0.1f0,-0.2f0,-0.3f0) |
Concerning truncation.
Either way, the right place to propose/discuss a change to that behaviour is https://github.com/JuliaMath/FixedPointNumbers.jl |
@johnnychen94 if you're used to Matlab then you probably expect saturating arithmetic. https://docs.julialang.org/en/stable/manual/faq/index.html#Why-does-Julia-use-native-machine-integer-arithmetic?-1 |
Wouldn't be crazy to define a FixedPoint overflow-checking type, however; it would be quite handy for debugging purposes. |
@Evizero Many thanks. I create this issue here because the default loading behavior is kind of annoying, and I'm not sure if this is an image-processing specific problem or not. I mean, I personally prefer using |
First, slightly simpler is Second, in the Matlab world many images are loaded in Third, rather than converting whole images you could use temporary variables that make arithmetic safe. Fourth and most importantly, we could change this, but the naive approach has a dreadful cost. Let me explain. The main reason to use
We've gone with the last of these, which I view as the least-bad of all options. IMO, the middle one is the worst of them all. It has several problems, but the most serious is that we would evolve a class of bugs that only strike users of large images, and therefore are not easily discoverable by a test suite. This is the "dreadful cost" to which I was referring above. Now, despite these considerations i wonder if we should harness your experience (and you are not alone) and see what we can do to improve the situation. I see two interesting ways forward:
Either of these will, of course, be slower than if you convert the image itself. So they might be best as a check to see whether the JuliaImages algorithms are sufficiently careful. Is anyone interested in either of these? I can look at setting up the raw numerics of this if folks offer to help fix any JuliaImages bugs that this discovers 😄. |
Thanks for your thoroughly explanation on the design! It's basically the trade-off between engineering efficiency and experimental flexibility. For my own purpose, I just want to make sure my idea and code work as expected without caring the potential overflow things, in which case I'm very likely to conclude that my idea doesn't work at all, which is a disaster for me. One need to do thing correctly at first and then consider doing it better, so I do be willing to guarantee the numerical correctness in my experiments even its cost is low speed and high memory usage. At present, function foo_(imgs::Array{Gray{T},N}) where {T,N} # N be 2 or 3
# everything here explicitly goes with T
# so it would be easy to test if `Float32` type works well
end
function foo(imgs::Array{Gray{Normed{T,N},3}}) where {T,N}
# do some warm-up test
idx = 1:size(imgs,3)
idx = idx[rand(idx)]
if foo(imgs[idx]) ≈ Gray{Normed{T,N}}.(foo_(Gray{Float32}.(imgs[idx])))
# things goes very pleasing
foo_(imgs)
else
@warn "Fall back to Float32 version"
imgs .|> Gray{Float32} |> foo_ .|> Gray{Normed{T,N}}
end
end I'm new with Julia and not familiar with engineering at present, I don't know how to implement your ideas in details, so I just explain what I want as a package user. I do like the idea of introducing And I might also "want" a macro like this, which I think makes debugging even more easier (I don't even know if this is possible): function foo()
# function definitions
end
@safe foo() # for debug usage
@fast foo() # make it fast These |
Uh oh!
There was an error while loading. Please reload this page.
For example, we have a new denoising algorithm
imgdenoise_new(img)
and want to compare the performance. A subtraction is often used to get the difference.For example, I want to get the img noise, which should be very small...
Since
FixedPointNumbers
use the same wraparound behavior for overflow as Julia does, theimg_diff
andimg_noise
are not actually what we want; some minor differences will become very large. Indeed, truncation behavior seems reasonable for image processing tasks.The text was updated successfully, but these errors were encountered: