Jump to content

Image convolution: Difference between revisions

J: reworked - more neutral padding, more concise kernel_filter
(J: reworked - more neutral padding, more concise kernel_filter)
Line 612:
<lang J>NB. pad the first n dimensions of an array with zeros
NB. (increasing all dimensions by 1 less than the kernel size)
pad=: adverb define
adj1'a b'=:. (<.,.>.) 0.5 0.5 p. $m%2
a"_`(<:@],0:)`(#1:)}~&# # b"_`(<:@],0:)`(#1:)}~&(1{$) #"1 ]
adj2=: m-1
(-@(adj2 + ]) {. (adj1 + ]) {. [) (#m) {. $
)
 
kernel_filter=: adverb define
[: (1,/"(-#:$m) ($m) +/@ .*&(,/^:(_1+#$m))@:*&m,;._3 m ($m)pad
)</lang>
 
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.