Create Anaglyph (GIMP Plugin)
anaglyph_algorithm Namespace Reference

Classes

class  Anaglyph
 This class represents an algorithm to compute two stereo images from gimp layers and to combine them to an anaglyph. More...
 

Functions

def interp2 (X, Y, Z)
 interpolates Z at locations X,Y output of function is of shape(X)==shape(Y) More...
 

Function Documentation

def anaglyph_algorithm.interp2 (   X,
  Y,
  Z 
)

interpolates Z at locations X,Y output of function is of shape(X)==shape(Y)

Definition at line 5 of file anaglyph_algorithm.py.

5 def interp2(X,Y,Z):
6  """! interpolates Z at locations X,Y
7  output of function is of shape(X)==shape(Y)
8  """
9  from numpy import *
10  X1 = array(floor(X),dtype=int);
11  X2 = array(ceil(X),dtype=int);
12  Y1 = array(floor(Y),dtype=int);
13  Y2 = array(ceil(Y),dtype=int);
14 
15  M1 = logical_or(logical_or(Y1<0,Y1>=Z.shape[0]),logical_or(Y2<0,Y2>=Z.shape[0]))
16  M2 = logical_or(logical_or(X1<0,X1>=Z.shape[1]),logical_or(X2<0,X2>=Z.shape[1]))
17  M = logical_not(logical_or(M1,M2));
18 
19  X1[X1<0]=0;
20  X1[X1>=Z.shape[1]]=Z.shape[1]-1;
21  X2[X2<0]=0;
22  X2[X2>=Z.shape[1]]=Z.shape[1]-1;
23  XR = X-X1;
24  Y1[Y1<0]=0;
25  Y1[Y1>=Z.shape[0]]=Z.shape[0]-1;
26  Y2[Y2<0]=0;
27  Y2[Y2>=Z.shape[0]]=Z.shape[0]-1;
28  YR = Y-Y1;
29  ERG1 = Z[Y1,X1]+(Z[Y1,X2]-Z[Y1,X1])*XR;
30  ERG2 = Z[Y2,X1]+(Z[Y2,X2]-Z[Y2,X1])*XR;
31  ERG = ERG1+(ERG2-ERG1)*YR;
32  return ERG,M;
33 
def interp2(X, Y, Z)
interpolates Z at locations X,Y output of function is of shape(X)==shape(Y)