Create Anaglyph (GIMP Plugin)
create_anaglyph_plugin Namespace Reference

Functions

def run (timg, tdrawable, mindisp, maxdisp, f1, f2, swap_lr)
 Plugin main function. More...
 

Function Documentation

def create_anaglyph_plugin.run (   timg,
  tdrawable,
  mindisp,
  maxdisp,
  f1,
  f2,
  swap_lr 
)

Plugin main function.

Combines layers to form an anaglyph.

Definition at line 8 of file create_anaglyph_plugin.py.

8 def run(timg, tdrawable, mindisp, maxdisp,f1,f2,swap_lr):
9  """! Plugin main function. Combines layers to form an anaglyph."""
10  # init algo
11  anaglyph = Anaglyph(f1,f2)
12  depthalgo = DepthAlgo(timg, mindisp, maxdisp)
13 
14  n=1
15  nmax=len(timg.layers)
16  for layer in reversed(timg.layers):
17  print layer.name
18  if not depthalgo.is_depth_map(layer):
19  # convert layer data to numpy array
20  mf = layer2array(layer, dtype=numpy.float)
21 
22  # determine depth
23  d = depthalgo.get_disparity(layer)
24 
25  # update algo and progress bar
26  if (depthalgo.has_map(layer)):
27  print("%s --> special"%(layer.name))
28  anaglyph.update_ext(mf,d)
29  else:
30  print("%s --> %f"%(layer.name,d))
31  anaglyph.update(mf,d)
32 
33  pdb.gimp_progress_update(float(n)/float(nmax))
34  n=n+1
35 
36  # create new output image
37  new_image = pdb.gimp_image_new(timg.width, timg.height, RGB);
38  new_layer = pdb.gimp_layer_new(new_image, timg.width, timg.height, RGB, "main", 100.0, NORMAL_MODE)
39  pdb.gimp_layer_add_alpha(new_layer)
40  new_image.add_layer(new_layer)
41 
42  # convert algorithm output array (numpy) to gimp data
43  copy_array_into_layer(anaglyph.get_result(swap_lr), new_layer)
44 
45  # display new image
46  display = pdb.gimp_display_new(new_image)
47 
48 print("registering create_anaglyph plugin.")
49 register(
50  "create_anaglyph",
51  """Create an anaglyph from layers (generates a new image)
52 Layers named depth=<float> specify a fixed depth from 0 (near) to 1(far). Values outside 0..1 are also possible.""", "", "", "", "",
53  "<Toolbox>/Xtns/Goto40/Create Anaglyph From Layers",
54  "GRAY*",
55  [
56  (PF_IMAGE, "image", "Input image", None),
57  (PF_DRAWABLE, "drawable", "Input drawable", None),
58  (PF_FLOAT, "mindisp", "min disparity, percent width (near)", 0.0),
59  (PF_FLOAT, "maxdisp", "max disparity, percent width (far)", 2.0),
60  (PF_FLOAT, "left_factor", "luminance correction left (0.0..1.0)", 1.0),
61  (PF_FLOAT, "right_factor", "luminance correction right (0.0..1.0)", 0.8),
62  (PF_BOOL, "swap_lr", "swap left/right", False),
63 #optional: (PF_OPTION, "mode", "conversion mode", 0, ["layers","encoded"]),
64  ],
65  [],
66  run
67  )
68 
69 main()
70 
71 
def copy_array_into_layer(data, layer)
copies an array into a layer.
This class is responsible to compute the depth of a layer.
This class represents an algorithm to compute two stereo images from gimp layers and to combine them ...
def run(timg, tdrawable, mindisp, maxdisp, f1, f2, swap_lr)
Plugin main function.
def layer2array(layer, dtype=None)
converts a layer to an array.