This is true for image scaling (zooming and changing the h/w ratio), but
also for image rotations and perspective transformations etc.? Or am I
missing your point? 

Bilinear (multilinear) interpolation itself is of course separable, but
that is probably not what you mean:

   (<1.1 2.2 3.3 4.4) ffrom y =. i.5 6 7 8 9
4712.4 4713.4 4714.4 4715.4 4716.4 4717.4 4718.4 4719.4 4720.4

   4.4 ffrom 3.3 ffrom 2.2 ffrom 1.1 ffrom y
4712.4 4713.4 4714.4 4715.4 4716.4 4717.4 4718.4 4719.4 4720.4

Besides, I wouldn't expect the second to be more efficient than the
first.
   
Ben


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Marshall
Lochbaum
Sent: woensdag 26 januari 2011 2:34
To: 'Programming forum'
Subject: Re: [Jprogramming] Floating from

The bilinear resampling is a separable problem. All you have to do is
resample along each axis in succession. So:

(0&|:)@:(ffrom~ f)^:(#@$)

with f giving you the correct set of indices for that axis (in your
example, (0.9*i.n)"_), will give you the correct answer quickly.

   6!:2 '(0&|:)@:(ffrom~ (0.9*i.n)"_)^:(#@$) i.n,n=.100'
0.0080147
   6!:2 '(0&|:)@:(ffrom~ (0.9*i.n)"_)^:(#@$) i.n,n=.200'
0.0207797

Marshall 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ben Gorte - LR
Sent: Monday, January 24, 2011 12:42 PM
To: Programming forum
Subject: Re: [Jprogramming] Floating from

If it is about speed (not beauty), then it seems yours is not very fast
when selecting a lot of elements at once, as in bilinear image
resampling.

The example:

   ((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.5
   0  0.9  1.8  2.7  3.6
 4.5  5.4  6.3  7.2  8.1
   9  9.9 10.8 11.7 12.6
13.5 14.4 15.3 16.2 17.1
  18 18.9 19.8 20.7 21.6

This is your fastest version:

   6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.100'
0.405595
   6!:2 '((<"1)0.9*,"0/~i.n)ffrom2 i.n,n=.200'
6.26634

About mine I may say:

 6!:2 '((<"1)0.9*,"0/~i.n) bgffrom i.n,n=.100'
0.27029
   6!:2 '((<"1)0.9*,"0/~i.n) bgffrom i.n,n=.200'
1.07775

(pure luck, I admit)

Ben



 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Marshall
Lochbaum
Sent: maandag 24 januari 2011 14:06
To: 'Programming forum'
Subject: Re: [Jprogramming] Floating from

If you want one that works exactly like the others, replace }. in the
code with |.  . This is a much more elegant way to do it, but it
requires moving the whole array around and more time and space (it is
about three times slower).

Marshall

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ben Gorte - LR
Sent: Monday, January 24, 2011 2:14 AM
To: Programming forum
Subject: Re: [Jprogramming] Floating from

Impressed again.
I suppose I should start using that one in my application,

However you were changing the specs.
Your previous one is the real ffrom.

Ben


-----Original Message-----
From: [email protected] on behalf of Marshall Lochbaum
Sent: Mon 1/24/2011 1:18 AM
To: 'Programming forum'
Subject: Re: [Jprogramming] Floating from
 
I have a better version!
This one, despite an ugly for loop, uses more J array power and
outperforms my previous attempt by an order of magnitude in time and
space.

   ffrom=:4 :0"0 _
x=.,>x
a=.(2"0 x) {. (<.x) }. y
mult=. (,.~-.) (-<.) x
for_m. mult do.
  a=. m +/@:* a
end.
a
)
   6!:2 '(<?20$0) ffrom i.20#2'
0.0627697
   7!:2 '(<?20$0) ffrom i.20#2'
75506048

Note that this one, because of its use of head, substitutes 0 for any
value that is out of range. It also doesn't work for negative indices.

Marshall

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

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

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

Reply via email to