On Wed, May 30, 2012 at 12:29 AM, Alexander Mikhailov <avm...@yahoo.com> wrote:
> I'm playing with some image processing, and not sure how to do
> a rather basic thing.
>
> It actually even applicable to 1D arrays. Suppose we have a
> picture, a 2D array of floating point brightness values in the
> range from 0 to 1. Suppose we want to superimpose another
> array on top of that, with some function for how to merge
> brightness from two sources in the same place. For 1D, an
> example could be "merge i. 5 with 2 * i. 4 where the second
> array is shifted 3 values from the beginning of the first one
> and merging values are averaged". I.e.
>
> 0 1 2 3 4 "merge with shift 3 and averaging" 0 2 4 6
> ->
> 0 1 2 1.5 3 4 6

Here you are combining a five element list with a four element list
and producing a seven element list.  If this were image manipulation,
you would be combining layers of different sizes and getting a new
layer which was a different size from either of the original sizes.  I
have never seen any image manipulation application which works like
this.

So the first step, I think, would be to specify more precisely what it
is you want to accomplish.

If you just want (average color with transparency) you would need to
define a transparent color.  The easiest way to implement transparency
is to use 0 for transparent, and use an offset when representing other
colors so that they are all positive values.  In other words if your
color range was 0-255, you could add 1 to non-transparent colors (and
then subtract 1 when you want to extract their values).

If you use this approach, here's averaging two layers, with transparency:

   (layer1 + layer 2) % layer1 +&* layer2
or
   layer1 (+ % +&*) layer2

Or, here's averaging a list of n layers (with transparency):

   (+/ % +/@:*) layers

> This could be useful for image manipulations, in 2D case.
>
> What would be a good way to do that? For example, merge i. 5 5
> with 3 * i. 3 4 shifting the second array 4 _1 from the first
> and, say, averaging values on the same places?
>
> Am I missing some known J patterns?

I need to understand what you mean by "merge" before I can comment on that.

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

Reply via email to