I think Oleg posted something like this some time ago,
but I can't find it:
   kernel=:2 :'(m,:$n) (n +/@,@:* ]);._3 ]'

This is a conjunction whose left argument is the stride
(sampling interval, in x and y directions) and whose
right argument is weights used to merge adjacent pixels.

Anyways, here's a plausible use:
   k2=: 2 2 kernel ((% +/@,)1 4 1,4 9 4,:1 4 1)"2
   extendborders=: ({.,{:,~])@({."1,.{:"1,.~])
   halfdim=: <.@:k2&.|:&.(256 256 256&#:)@extendborders

   viewrgb img2=: halfdim img

This assumes that pixels are being represented as rgb integers --
three byte values packed together in an integer.

Anyways, you can tweak this algorithm in a variety of directions,
if you have need of that.  For example, to get 1/10th the size,
change the left argument of kernel (in the definition of k2) to 10.
(And you can get rid of extendborders if you're not fussy).

(You can get viewrgb from:  require'viewmat')

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to