{"action":"created","comment":{"url":"https://api.github.com/repos/timholy/Images.jl/pulls/comments/45566012","id":45566012,"diff_hunk":"@@ -1473,6 +1473,171 @@ extr(order::Ordering, x::Color, y::Color) = extr(order, convert(RGB, x), convert\n extr(order::Ordering, x::Color, y::Color, z::Color) = extr(order, convert(RGB, x), convert(RGB, y), convert(RGB, z))\n \n \n+\n+# Min max filter\n+\n+type Wedge\n+    buffer::AbstractArray\n+    size::Int\n+    n::Int\n+    first::Int\n+    last::Int\n+    mxn::Int\n+end\n+\n+\n+for N = 2:4\n+    @eval begin\n+    function extrema_filter{T <: Number}(A::Array{T, $N}, window::Array{Int, 1})\n+\n+        maxval_temp = copy(A); minval_temp = copy(A)\n+\n+        for dim = 1:$N\n+\n+            # For all but the last dimension\n+            @nloops $(N-1) i maxval_temp begin\n+\n+                # Create index for full array (fa) length\n+                @nexprs $(N)   j->(fa_{j} = 1:size(maxval_temp)[j])\n+                @nexprs $(N-1) j->(fa_{j} = i_j)\n+\n+                # Create index for short array (sa) length\n+                @nexprs $(N)   j->(sa_{j} = 1:size(maxval_temp)[j] - window[dim] + 1)\n+                @nexprs $(N-1) j->(sa_{j} = i_j)\n+\n+                # Filter the last dimension\n+                (@nref $N minval_temp sa) = min_filter(vec( @nref $N minval_temp fa), window[dim])\n+                (@nref $N maxval_temp sa) = max_filter(vec( @nref $N maxval_temp fa), window[dim])\n+\n+            end\n+\n+            # Circular shift the dimensions\n+            maxval_temp = permutedims(maxval_temp, mod([1:$N], $N)+1)\n+            minval_temp = permutedims(minval_temp, mod([1:$N], $N)+1)\n+\n+        end\n+\n+        # The dimensions to extract\n+        @nexprs $N j->(a_{j} = 1:size(A, j)-window[j]+1)\n+\n+        # Extract set dimensions\n+        maxval_out = @nref $N maxval_temp a\n+        minval_out = @nref $N minval_temp a\n+\n+        return minval_out, maxval_out\n+    end\n+    end\n+end\n+\n+\n+function extrema_filter{T <: Number}(a::AbstractArray{T}, window::Int)\n+\n+    n = length(a)\n+\n+    # Initialise the output variables\n+    # This is the running minimum and maximum over the specified window length\n+    minval = zeros(T, 1, n-window+1)\n+    maxval = zeros(T, 1, n-window+1)\n+\n+    # Initialise the internal wedges\n+    # U[1], L[1] are the location of the global maximum and minimum\n+    # U[2], L[2] are the maximum and minimum over (U1, inf)\n+    L = Wedge(zeros(Int,1,window+1), window+1, 0, 1, 0, 0)          # Min\n+    U = Wedge(zeros(Int,1,window+1), window+1, 0, 1, 0, 0)\n+\n+    for i = 2:n\n+        if i > window\n+            if ~wedgeisempty(U)\n+                maxval[i-window] = a[getfirst(U)]\n+            else\n+                maxval[i-window] = a[i-1]\n+            end\n+            if ~wedgeisempty(L)\n+                minval[i-window] = a[getfirst(L)]\n+            else\n+                minval[i-window] = a[i-1]\n+            end\n+        end # window\n+\n+        if a[i] > a[i-1]\n+            L = pushback(L, i-1)\n+            if i==window+getfirst(L); L=popfront(L); end\n+            while ~wedgeisempty(U)\n+                if a[i] <= a[getlast(U)]\n+                    if i == window+getfirst(U); U = popfront(U); end\n+                    break\n+                end\n+                U = popback(U)\n+            end\n+\n+        else\n+\n+            U = pushback(U, i-1)\n+            if i==window+getfirst(U); U=popfront(U); end\n+\n+            while ~wedgeisempty(L)\n+                if a[i] >= a[getlast(L)]\n+                    if i == window+getfirst(L); L = popfront(L); end\n+                    break\n+                end\n+                L = popback(L)\n+            end\n+\n+        end  # a>a-1\n+\n+    end # for i\n+\n+    i = n+1\n+    if ~wedgeisempty(U)\n+        maxval[i-window] = a[getfirst(U)]\n+    else\n+        maxval[i-window] = a[i-1]\n+    end\n+\n+    if ~wedgeisempty(L)\n+        minval[i-window] = a[getfirst(L)]\n+    else\n+        minval[i-window] = a[i-1]\n+    end\n+\n+    return minval, maxval\n+end\n+\n+function wedgeisempty(X::Wedge)\n+    X.n <= 0\n+end\n+\n+function pushback(X::Wedge, v)","path":"src/algorithms.jl","position":138,"original_position":138,"commit_id":"38f3d82733bf7660c2493413cd536c4d70db6645","original_commit_id":"38f3d82733bf7660c2493413cd536c4d70db6645","user":{"login":"codles","id":748691,"avatar_url":"https://avatars.githubusercontent.com/u/748691?v=3","gravatar_id":"","url":"https://api.github.com/users/codles","html_url":"https://github.com/codles","followers_url":"https://api.github.com/users/codles/followers","following_url":"https://api.github.com/users/codles/following{/other_user}","gists_url":"https://api.github.com/users/codles/gists{/gist_id}","starred_url":"https://api.github.com/users/codles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codles/subscriptions","organizations_url":"https://api.github.com/users/codles/orgs","repos_url":"https://api.github.com/users/codles/repos","events_url":"https://api.github.com/users/codles/events{/privacy}","received_events_url":"https://api.github.com/users/codles/received_events","type":"User","site_admin":false},"body":"Noted, thanks","created_at":"2015-11-22T22:46:03Z","updated_at":"2015-11-22T22:46:03Z","html_url":"https://github.com/timholy/Images.jl/pull/413#discussion_r45566012","pull_request_url":"https://api.github.com/repos/timholy/Images.jl/pulls/413","_links":{"self":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/comments/45566012"},"html":{"href":"https://github.com/timholy/Images.jl/pull/413#discussion_r45566012"},"pull_request":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/413"}}},"pull_request":{"url":"https://api.github.com/repos/timholy/Images.jl/pulls/413","id":51472951,"html_url":"https://github.com/timholy/Images.jl/pull/413","diff_url":"https://github.com/timholy/Images.jl/pull/413.diff","patch_url":"https://github.com/timholy/Images.jl/pull/413.patch","issue_url":"https://api.github.com/repos/timholy/Images.jl/issues/413","number":413,"state":"open","locked":false,"title":"Add extrema_filter","user":{"login":"codles","id":748691,"avatar_url":"https://avatars.githubusercontent.com/u/748691?v=3","gravatar_id":"","url":"https://api.github.com/users/codles","html_url":"https://github.com/codles","followers_url":"https://api.github.com/users/codles/followers","following_url":"https://api.github.com/users/codles/following{/other_user}","gists_url":"https://api.github.com/users/codles/gists{/gist_id}","starred_url":"https://api.github.com/users/codles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codles/subscriptions","organizations_url":"https://api.github.com/users/codles/orgs","repos_url":"https://api.github.com/users/codles/repos","events_url":"https://api.github.com/users/codles/events{/privacy}","received_events_url":"https://api.github.com/users/codles/received_events","type":"User","site_admin":false},"body":"Added function and tests for 2d and 4d case","created_at":"2015-11-22T19:57:14Z","updated_at":"2015-11-22T22:46:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dd2580f4b277293ee47131baae72107eb17b656e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/timholy/Images.jl/pulls/413/commits","review_comments_url":"https://api.github.com/repos/timholy/Images.jl/pulls/413/comments","review_comment_url":"https://api.github.com/repos/timholy/Images.jl/pulls/comments{/number}","comments_url":"https://api.github.com/repos/timholy/Images.jl/issues/413/comments","statuses_url":"https://api.github.com/repos/timholy/Images.jl/statuses/38f3d82733bf7660c2493413cd536c4d70db6645","head":{"label":"codles:master","ref":"master","sha":"38f3d82733bf7660c2493413cd536c4d70db6645","user":{"login":"codles","id":748691,"avatar_url":"https://avatars.githubusercontent.com/u/748691?v=3","gravatar_id":"","url":"https://api.github.com/users/codles","html_url":"https://github.com/codles","followers_url":"https://api.github.com/users/codles/followers","following_url":"https://api.github.com/users/codles/following{/other_user}","gists_url":"https://api.github.com/users/codles/gists{/gist_id}","starred_url":"https://api.github.com/users/codles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codles/subscriptions","organizations_url":"https://api.github.com/users/codles/orgs","repos_url":"https://api.github.com/users/codles/repos","events_url":"https://api.github.com/users/codles/events{/privacy}","received_events_url":"https://api.github.com/users/codles/received_events","type":"User","site_admin":false},"repo":{"id":46674091,"name":"Images.jl","full_name":"codles/Images.jl","owner":{"login":"codles","id":748691,"avatar_url":"https://avatars.githubusercontent.com/u/748691?v=3","gravatar_id":"","url":"https://api.github.com/users/codles","html_url":"https://github.com/codles","followers_url":"https://api.github.com/users/codles/followers","following_url":"https://api.github.com/users/codles/following{/other_user}","gists_url":"https://api.github.com/users/codles/gists{/gist_id}","starred_url":"https://api.github.com/users/codles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codles/subscriptions","organizations_url":"https://api.github.com/users/codles/orgs","repos_url":"https://api.github.com/users/codles/repos","events_url":"https://api.github.com/users/codles/events{/privacy}","received_events_url":"https://api.github.com/users/codles/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/codles/Images.jl","description":"An image library for Julia","fork":true,"url":"https://api.github.com/repos/codles/Images.jl","forks_url":"https://api.github.com/repos/codles/Images.jl/forks","keys_url":"https://api.github.com/repos/codles/Images.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codles/Images.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codles/Images.jl/teams","hooks_url":"https://api.github.com/repos/codles/Images.jl/hooks","issue_events_url":"https://api.github.com/repos/codles/Images.jl/issues/events{/number}","events_url":"https://api.github.com/repos/codles/Images.jl/events","assignees_url":"https://api.github.com/repos/codles/Images.jl/assignees{/user}","branches_url":"https://api.github.com/repos/codles/Images.jl/branches{/branch}","tags_url":"https://api.github.com/repos/codles/Images.jl/tags","blobs_url":"https://api.github.com/repos/codles/Images.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codles/Images.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codles/Images.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/codles/Images.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codles/Images.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/codles/Images.jl/languages","stargazers_url":"https://api.github.com/repos/codles/Images.jl/stargazers","contributors_url":"https://api.github.com/repos/codles/Images.jl/contributors","subscribers_url":"https://api.github.com/repos/codles/Images.jl/subscribers","subscription_url":"https://api.github.com/repos/codles/Images.jl/subscription","commits_url":"https://api.github.com/repos/codles/Images.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/codles/Images.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/codles/Images.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/codles/Images.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/codles/Images.jl/contents/{+path}","compare_url":"https://api.github.com/repos/codles/Images.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codles/Images.jl/merges","archive_url":"https://api.github.com/repos/codles/Images.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codles/Images.jl/downloads","issues_url":"https://api.github.com/repos/codles/Images.jl/issues{/number}","pulls_url":"https://api.github.com/repos/codles/Images.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/codles/Images.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/codles/Images.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codles/Images.jl/labels{/name}","releases_url":"https://api.github.com/repos/codles/Images.jl/releases{/id}","created_at":"2015-11-22T18:38:02Z","updated_at":"2015-11-22T18:38:03Z","pushed_at":"2015-11-22T20:07:08Z","git_url":"git://github.com/codles/Images.jl.git","ssh_url":"git@github.com:codles/Images.jl.git","clone_url":"https://github.com/codles/Images.jl.git","svn_url":"https://github.com/codles/Images.jl","homepage":null,"size":2253,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"timholy:master","ref":"master","sha":"b0f056e8b068142db0103a1c74da6cf864f75935","user":{"login":"timholy","id":1525481,"avatar_url":"https://avatars.githubusercontent.com/u/1525481?v=3","gravatar_id":"","url":"https://api.github.com/users/timholy","html_url":"https://github.com/timholy","followers_url":"https://api.github.com/users/timholy/followers","following_url":"https://api.github.com/users/timholy/following{/other_user}","gists_url":"https://api.github.com/users/timholy/gists{/gist_id}","starred_url":"https://api.github.com/users/timholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timholy/subscriptions","organizations_url":"https://api.github.com/users/timholy/orgs","repos_url":"https://api.github.com/users/timholy/repos","events_url":"https://api.github.com/users/timholy/events{/privacy}","received_events_url":"https://api.github.com/users/timholy/received_events","type":"User","site_admin":false},"repo":{"id":7018954,"name":"Images.jl","full_name":"timholy/Images.jl","owner":{"login":"timholy","id":1525481,"avatar_url":"https://avatars.githubusercontent.com/u/1525481?v=3","gravatar_id":"","url":"https://api.github.com/users/timholy","html_url":"https://github.com/timholy","followers_url":"https://api.github.com/users/timholy/followers","following_url":"https://api.github.com/users/timholy/following{/other_user}","gists_url":"https://api.github.com/users/timholy/gists{/gist_id}","starred_url":"https://api.github.com/users/timholy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timholy/subscriptions","organizations_url":"https://api.github.com/users/timholy/orgs","repos_url":"https://api.github.com/users/timholy/repos","events_url":"https://api.github.com/users/timholy/events{/privacy}","received_events_url":"https://api.github.com/users/timholy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timholy/Images.jl","description":"An image library for Julia","fork":false,"url":"https://api.github.com/repos/timholy/Images.jl","forks_url":"https://api.github.com/repos/timholy/Images.jl/forks","keys_url":"https://api.github.com/repos/timholy/Images.jl/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timholy/Images.jl/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timholy/Images.jl/teams","hooks_url":"https://api.github.com/repos/timholy/Images.jl/hooks","issue_events_url":"https://api.github.com/repos/timholy/Images.jl/issues/events{/number}","events_url":"https://api.github.com/repos/timholy/Images.jl/events","assignees_url":"https://api.github.com/repos/timholy/Images.jl/assignees{/user}","branches_url":"https://api.github.com/repos/timholy/Images.jl/branches{/branch}","tags_url":"https://api.github.com/repos/timholy/Images.jl/tags","blobs_url":"https://api.github.com/repos/timholy/Images.jl/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timholy/Images.jl/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timholy/Images.jl/git/refs{/sha}","trees_url":"https://api.github.com/repos/timholy/Images.jl/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timholy/Images.jl/statuses/{sha}","languages_url":"https://api.github.com/repos/timholy/Images.jl/languages","stargazers_url":"https://api.github.com/repos/timholy/Images.jl/stargazers","contributors_url":"https://api.github.com/repos/timholy/Images.jl/contributors","subscribers_url":"https://api.github.com/repos/timholy/Images.jl/subscribers","subscription_url":"https://api.github.com/repos/timholy/Images.jl/subscription","commits_url":"https://api.github.com/repos/timholy/Images.jl/commits{/sha}","git_commits_url":"https://api.github.com/repos/timholy/Images.jl/git/commits{/sha}","comments_url":"https://api.github.com/repos/timholy/Images.jl/comments{/number}","issue_comment_url":"https://api.github.com/repos/timholy/Images.jl/issues/comments{/number}","contents_url":"https://api.github.com/repos/timholy/Images.jl/contents/{+path}","compare_url":"https://api.github.com/repos/timholy/Images.jl/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timholy/Images.jl/merges","archive_url":"https://api.github.com/repos/timholy/Images.jl/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timholy/Images.jl/downloads","issues_url":"https://api.github.com/repos/timholy/Images.jl/issues{/number}","pulls_url":"https://api.github.com/repos/timholy/Images.jl/pulls{/number}","milestones_url":"https://api.github.com/repos/timholy/Images.jl/milestones{/number}","notifications_url":"https://api.github.com/repos/timholy/Images.jl/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timholy/Images.jl/labels{/name}","releases_url":"https://api.github.com/repos/timholy/Images.jl/releases{/id}","created_at":"2012-12-05T14:43:16Z","updated_at":"2015-11-20T14:15:36Z","pushed_at":"2015-11-22T20:07:08Z","git_url":"git://github.com/timholy/Images.jl.git","ssh_url":"git@github.com:timholy/Images.jl.git","clone_url":"https://github.com/timholy/Images.jl.git","svn_url":"https://github.com/timholy/Images.jl","homepage":null,"size":2288,"stargazers_count":89,"watchers_count":89,"language":"HTML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":72,"mirror_url":null,"open_issues_count":48,"forks":72,"open_issues":48,"watchers":89,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/413"},"html":{"href":"https://github.com/timholy/Images.jl/pull/413"},"issue":{"href":"https://api.github.com/repos/timholy/Images.jl/issues/413"},"comments":{"href":"https://api.github.com/repos/timholy/Images.jl/issues/413/comments"},"review_comments":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/413/comments"},"review_comment":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/timholy/Images.jl/pulls/413/commits"},"statuses":{"href":"https://api.github.com/repos/timholy/Images.jl/statuses/38f3d82733bf7660c2493413cd536c4d70db6645"}}}}