-
Notifications
You must be signed in to change notification settings - Fork 141
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
Getting standard deviation of img (std) #187
Comments
It's not a silly question at all. This should work, but I agree it doesn't. Since you're just starting (welcome!), let me show you how I figured out where the problem is. Unfortunately, I am not immediately sure what to do about it, but I've opened an issue in julia proper (see the reference link above). julia> using Images, TestImages
julia> img = testimage("mandril")
RGB Image with:
data: 512x512 Array{RGB{UfixedBase{Uint8,8}},2}
properties:
IMcs: sRGB
spatialorder: x y
pixelspacing: 1 1
julia> @which mean(img)
mean(A::AbstractArray{T,N}) at statistics.jl:17
julia> @which std(img)
std(A::AbstractArray{T,N}) at statistics.jl:204
julia> edit("statistics.jl", 204) # note that this calls to var, unsurprisingly
julia> @which var(img)
var{T}(A::AbstractArray{T,N}) at statistics.jl:162 # same file, so just navigate to line 162 in your editor
julia> @which varm(img, mean(img))
ERROR: no method found for the specified argument types
in which at interactiveutil.jl:201
# So we've found the problem. What methods does varm have?
julia> methods(varm)
# 4 methods for generic function "varm":
varm(v::Range{T},m::Number) at statistics.jl:180
varm{T}(A::AbstractArray{T,N},m::Number) at statistics.jl:141
varm{T}(A::AbstractArray{T,N},m::AbstractArray{T,N},region) at statistics.jl:157
varm(iterable,m::Number) at statistics.jl:175 So the problem is that The solution is to remove the typing in However, this fix will presumably only be available if you're running a development version of julia; for most users, we recommend sticking with 0.3. My guess is that import Base: std, var
function std{T<:ColorType}(img::AbstractArray{T})
...
end Unlike perhaps some other languages you may be familiar with, simple loops suffice to implement high-performance versions of such functions. I'll wait to hear back from you about whether you want to try tackling those as a good starter project in Julia, or whether you want me to handle it. |
Tim, Thanks for the very thorough response. Especially the debugging demo - On Sun, Sep 21, 2014 at 3:05 AM, Tim Holy notifications@github.com wrote:
Loops get vectorized?
I'll take a look. I'm very much a newbie at this point. But I think julia Do you hangout on the #julia IRC channel and if so what times? (in case I Phil
|
Julia distinguishes functions from methods. Here's a trivial example: f(x::Integer) = x+1
f(x::FloatingPoint) = x+2
If you want to extend a function defined in another module, you have to import it, and then you can add new methods. We'd just need a method that works for
Vectorization has two meanings. In Matlab, vectorized means "I take a large collection of objects and repetitively do the same thing to each element, doing the looping in a fast language like C." Julia is a fast language (as fast as C), so there's no need for vectorization in this sense. For example, compare julia> a = rand(10^7);
julia> b = sin(a);
julia> @time b = sin(a);
elapsed time: 0.23192822 seconds (80000128 bytes allocated)
julia> function mysin(a)
b = similar(a)
for i = 1:length(a)
b[i] = sin(a[i])
end
b
end
mysin (generic function with 1 method)
julia> mysin(a);
julia> @time mysin(a);
elapsed time: 0.184923681 seconds (80000128 bytes allocated)
# Matlab
>> a = rand(10^7,1);
>> tic; b = sin(a); toc
Elapsed time is 0.184815 seconds. So you can basically write any function you want in Julia and not worry about whether you can vectorize it. This is incredibly freeing. The other meaning of vectorization refers to SIMD operations on the CPU.
In that case, I encourage you to try implementing a version of
I don't IRC, sorry. But I'm happy to continue the discussion thread here. |
On Sun, Sep 21, 2014 at 1:26 PM, Tim Holy notifications@github.com wrote:
I was referring to the 2nd meaning having to do with SIMD. As I understand
|
That article I linked to explains more, but basically, yes. For some reason LLVM 3.3 is reluctant to vectorize Float64s, but Float32s and integers vectorize quite nicely, and I think LLVM 3.6 (currently under development, but my understanding is that Julia will move to in the not too distant future) seems to vectorize Float64s. So it's already quite good, and will continue to improve. |
On Sun, Sep 21, 2014 at 1:26 PM, Tim Holy notifications@github.com wrote:
(later I could implement something that would be more general in Images Phil |
Actually, when I do: data(img) I see that it's: 512x512 Array{RGB{UfixedBase{Uint8,8}},2}: Each entry looks like: RGB{Ufixed8}(0.643,0.588,0.278) So RGB looks like a triple of floats, so I would think that I could Does that seem like a reasonable approach for now? Phil On Sun, Sep 21, 2014 at 8:43 PM, Phil Tomson philtomson@gmail.com wrote:
|
Hi Phil, if you need to separate the planes, the Cheers, Kevin |
Tim, Tangential question related to Images: Can you extract jpegs from an MPEG Phil On Sun, Sep 21, 2014 at 11:25 PM, Kevin Squire notifications@github.com
|
Yes, see @kmsquire's lovely VideoIO package: https://github.com/kmsquire/VideoIO.jl |
I'm a newbie to both julia and the Images package so perhaps this is a silly question:
I notice that I can get the mean of an img, via:
(in fact, in IJulia this displays that mean color)
But getting a standard deviation using std(img) gives:
while loading In[66], in expression starting on line 1
in var at statistics.jl:162
I also tried: std(data(img))
...but got the same result.
The text was updated successfully, but these errors were encountered: