Create Anaglyph (GIMP Plugin)
anaglyph_algorithm.Anaglyph Class Reference

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

Public Member Functions

def __init__ (self, f1=1.0, f2=1.0)
 Creates an anaglyph algorithm. More...
 
def shiftx (self, img, d)
 Helper function to shift an image with a given disparity value. More...
 
def shiftx_ext (self, img, d)
 Helper function to shift an image with a given disparity map. More...
 
def update (self, layer_data, d)
 Update the image using a single depth value. More...
 
def update_ext (self, layer_data, d)
 Update the image using a depth map. More...
 
def get_result (self, swap_lr)
 Combines the result collected so far (left and right image) as anaglyph. More...
 

Public Attributes

 f1
 
 f2
 
 imsum
 
 left
 
 right
 
 aleft
 
 aright
 

Detailed Description

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

Definition at line 34 of file anaglyph_algorithm.py.

Constructor & Destructor Documentation

def anaglyph_algorithm.Anaglyph.__init__ (   self,
  f1 = 1.0,
  f2 = 1.0 
)

Creates an anaglyph algorithm.

Parameters
f1the darkening factor for the left image (1.0 = no modification)
f2the darkening factor for the left image (1.0 = no modification)

Definition at line 36 of file anaglyph_algorithm.py.

36  def __init__(self, f1=1.0, f2=1.0):
37  """! Creates an anaglyph algorithm.
38  @param f1 the darkening factor for the left image (1.0 = no modification)
39  @param f2 the darkening factor for the left image (1.0 = no modification)
40  """
41  self.f1=f1
42  self.f2=f2
43  self.imsum = None
44  self.left = None
45  self.right = None
46  self.aleft = None
47  self.aright = None
48 
def __init__(self, f1=1.0, f2=1.0)
Creates an anaglyph algorithm.

Member Function Documentation

def anaglyph_algorithm.Anaglyph.get_result (   self,
  swap_lr 
)

Combines the result collected so far (left and right image) as anaglyph.

Parameters
swap_lrif true the left and right image are swapped.
Returns
a numpy array representing the result image with 4 (RGBA) channels.

Definition at line 122 of file anaglyph_algorithm.py.

122  def get_result(self,swap_lr):
123  """! Combines the result collected so far (left and right image) as anaglyph.
124  @param swap_lr if true the left and right image are swapped.
125  @return a numpy array representing the result image with 4 (RGBA) channels.
126  """
127  a = numpy.zeros((self.left.shape[0],self.left.shape[1],4))
128  if swap_lr:
129  r = self.left
130  l = self.right
131  else:
132  l = self.left
133  r = self.right
134  a[:,:,0] = l*self.f1 + (1-self.f1)/2
135  a[:,:,1] = r*self.f2 + (1-self.f2)/2
136  a[:,:,2] = r*self.f2 + (1-self.f2)/2
137  a[:,:,3] = numpy.maximum(self.aleft,self.aright)
138  return a
def anaglyph_algorithm.Anaglyph.shiftx (   self,
  img,
  d 
)

Helper function to shift an image with a given disparity value.

Definition at line 49 of file anaglyph_algorithm.py.

49  def shiftx(self,img,d):
50  """! Helper function to shift an image with a given disparity value. """
51  res = numpy.roll(img,d,axis=1)
52  if (d>0):
53  res[:,:d]=0
54  elif (d<0):
55  res[:,d:]=0
56  return res
57 
def shiftx(self, img, d)
Helper function to shift an image with a given disparity value.
def anaglyph_algorithm.Anaglyph.shiftx_ext (   self,
  img,
  d 
)

Helper function to shift an image with a given disparity map.

Definition at line 58 of file anaglyph_algorithm.py.

58  def shiftx_ext(self,img,d):
59  """! Helper function to shift an image with a given disparity map. """
60  w = d.shape[1]
61  h = d.shape[0]
62  x,y = numpy.meshgrid(numpy.arange(w),numpy.arange(h))
63  x = x-d
64  res,m = interp2(x,y,img);
65  return res*m
66 
67 
def shiftx_ext(self, img, d)
Helper function to shift an image with a given disparity map.
def interp2(X, Y, Z)
interpolates Z at locations X,Y output of function is of shape(X)==shape(Y)
def anaglyph_algorithm.Anaglyph.update (   self,
  layer_data,
  d 
)

Update the image using a single depth value.

Parameters
layer_datathe layer to be added (as numpy array)
dthe disparity of the layer

Definition at line 68 of file anaglyph_algorithm.py.

68  def update(self, layer_data, d):
69  """! Update the image using a single depth value
70  @param layer_data the layer to be added (as numpy array)
71  @param d the disparity of the layer
72  """
73  h = layer_data.shape[0]
74  w = layer_data.shape[1]
75  if layer_data.shape[2]==1:
76  tmp = numpy.ones((h,w,2))*255.0
77  tmp[:,:,1]=numpy.reshape(layer_data,(h,w))
78  layer_data=tmp
79  if self.left==None:
80  self.left = numpy.zeros((h,w))
81  self.right = numpy.zeros((h,w))
82  self.aleft = numpy.zeros((h,w))
83  self.aright = numpy.zeros((h,w))
84  else:
85  assert(self.left.shape == (h,w), "shape must not change")
86 
87  imleft = self.shiftx(layer_data[:,:,0],-d)
88  imright = self.shiftx(layer_data[:,:,0],+d)
89  alphaleft = self.shiftx(layer_data[:,:,1],-d)
90  alpharight = self.shiftx(layer_data[:,:,1],+d)
91 
92  self.left = (self.left *(255-alphaleft )+imleft *alphaleft )/255
93  self.right = (self.right*(255-alpharight)+imright*alpharight)/255
94  self.aleft = numpy.maximum(alphaleft, self.aleft)
95  self.aright = numpy.maximum(alpharight, self.aright)
96 
def shiftx(self, img, d)
Helper function to shift an image with a given disparity value.
def update(self, layer_data, d)
Update the image using a single depth value.
def anaglyph_algorithm.Anaglyph.update_ext (   self,
  layer_data,
  d 
)

Update the image using a depth map.

Parameters
layer_datathe layer to be added (as numpy array)
dthe disparity map of the layer

Definition at line 97 of file anaglyph_algorithm.py.

97  def update_ext(self, layer_data, d):
98  """! Update the image using a depth map
99  @param layer_data the layer to be added (as numpy array)
100  @param d the disparity map of the layer
101  """
102  h = layer_data.shape[0]
103  w = layer_data.shape[1]
104  if self.left==None:
105  self.left = numpy.zeros((h,w))
106  self.right = numpy.zeros((h,w))
107  self.aleft = numpy.zeros((h,w))
108  self.aright = numpy.zeros((h,w))
109  else:
110  assert(self.left.shape == (h,w), "shape must not change")
111 
112  imleft = self.shiftx_ext(layer_data[:,:,0],-d)
113  imright = self.shiftx_ext(layer_data[:,:,0],+d)
114  alphaleft = self.shiftx_ext(layer_data[:,:,1],-d)
115  alpharight = self.shiftx_ext(layer_data[:,:,1],+d)
116 
117  self.left = (self.left *(255-alphaleft )+imleft *alphaleft )/255
118  self.right = (self.right*(255-alpharight)+imright*alpharight)/255
119  self.aleft = numpy.maximum(alphaleft, self.aleft)
120  self.aright = numpy.maximum(alpharight, self.aright)
121 
def shiftx_ext(self, img, d)
Helper function to shift an image with a given disparity map.
def update_ext(self, layer_data, d)
Update the image using a depth map.

Member Data Documentation

anaglyph_algorithm.Anaglyph.aleft

Definition at line 46 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.aright

Definition at line 47 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.f1

Definition at line 41 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.f2

Definition at line 42 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.imsum

Definition at line 43 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.left

Definition at line 44 of file anaglyph_algorithm.py.

anaglyph_algorithm.Anaglyph.right

Definition at line 45 of file anaglyph_algorithm.py.


The documentation for this class was generated from the following file: