Skip to content

Commit

Permalink
some tweaks. making mean(A) work on any array.
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 10, 2012
1 parent dc37c60 commit ee55e00
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
10 changes: 4 additions & 6 deletions examples/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,9 @@ sadn{T}(A::Array{T}, B::Array{T}) = sad(A, B)/numel(A)

# normalized cross correlation
function ncc{T}(A::Array{T}, B::Array{T})
Am = A[:]-mean(A[:])
Bm = B[:]-mean(B[:])
res = ((Am/norm(Am))'*(Bm/norm(Bm)))
return res
Am = (A-mean(A))[:]
Bm = (B-mean(B))[:]
return dot(Am,Bm)/(norm(Am)*norm(Bm))
end

function imfilter{T}(img::Matrix{T}, filter::Matrix{T}, border::String, value)
Expand Down Expand Up @@ -368,8 +367,7 @@ function imthresh{T}(img::Array{T,2}, threshold::Float)
end

function imgaussiannoise{T}(img::Array{T}, variance::Number, mean::Number)
tmp = img + sqrt(variance)*randn(size(img)) + mean
return tmp
return img + sqrt(variance)*randn(size(img)) + mean
end

imgaussiannoise{T}(img::Array{T}, variance::Number) = imgaussiannoise(img, variance, 0)
Expand Down
2 changes: 1 addition & 1 deletion jl/statistics.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mean(v::AbstractVector) = sum(v) / length(v)
mean(v::AbstractArray) = sum(v) / numel(v)
mean(v::AbstractArray, dim::Int) = sum(v,dim) / size(v,dim)

function std(v::AbstractVector)
Expand Down

0 comments on commit ee55e00

Please sign in to comment.