2 from gimpfu_numpy_converter
import *
6 This class is responsible to compute the depth of a layer. This can be a single depth value or a depth map. 8 def __init__(self, gimp_image, mindisp, maxdisp):
11 @param gimp_image the gimp image to be processed 12 @param min_disp the minimum disparity to be processed (relative to image width) 13 @param max_disp the maximum disparity to be processed (relative to image width) 21 for layer
in reversed(gimp_image.layers):
27 self.normallayers.insert(0,layer)
31 assert(data.max()>data.min())
32 data = (data-data.min())/(data.max()-data.min())*1.0
33 mi = float(m.group(2))
34 ma = float(m.group(3))
36 self.
depthmaps[m.group(1)] = mi+data*(ma-mi)
42 Determines if a layer is a depth map. 43 @param gimp_layer the layer to be investigated. 44 @return the matcher containing (name, mindepth, maxdepth) or None (logically maps to a boolean) 46 pat = re.compile(
r'depthmap\s+(\w+)\s+(-?[\d\.]+)\s+to\s+(-?[\d\.]+)')
47 m=pat.match(gimp_layer.name)
52 @param gimp_layer the layer to be investigated. 53 @return if this layer has a depth map (or a single depth for the whole layer) 58 """! Determines if a layer has (uses) a depth map as relative map (relative depth values between the neighboring layers) 59 @param gimp_layer the layer to be investigated. 60 @return the matcher containing the map name or None (logically maps to a boolean) 62 pat = re.compile(
r'reldepthmap\s*=\s*(\w+)')
63 m=pat.match(gimp_layer.name)
67 """! Determines if a layer has (uses) a depth map as fixed map fixed depth values) 68 @param gimp_layer the layer to be investigated. 69 @return the matcher containing the map name or None (logically maps to a boolean) 71 pat = re.compile(
r'fixdepthmap\s*=\s*(\w+)')
72 m=pat.match(gimp_layer.name)
76 """! Determines if a used depth is specified for the layer 77 @param gimp_layer the layer to be investigated. 78 @return the matcher containing the map depth (logically maps to a boolean) 81 if (n.startswith(
"background")):
83 pat = re.compile(
r'depth=(-?[\d\.]+)')
88 """! Determines the depth value or the map of depth values of a layer 89 @param gimp_layer the layer to be investigated. 90 @retrun the depth value (as absolute disparity in pixels) either as single value or as array of values. 92 idx = self.gimp_image.layers.index(gimp_layer)
96 d = float(idx)/float(self.
n-1)
101 print(
"relative map detected: "+gimp_layer.name)
102 d0 = d-float(1.0/(self.
n-1))
103 d1 = d+float(1.0/(self.
n-1))
104 assert(mrel.group(1)
in self.depthmaps.keys())
108 print(
"fixed map detected: "+gimp_layer.name)
109 assert(mfix.group(1)
in self.depthmaps.keys())
112 return numpy.floor(0.5+d*self.gimp_image.width/100.0)
116 d = float(m.group(1))
119 idx = self.normallayers.index(gimp_layer)
121 d = float(idx)/float(self.
n-1)
127 return int(0.5+d*self.gimp_image.width/100.0)
def has_map(self, gimp_layer)
def __init__(self, gimp_image, mindisp, maxdisp)
Creates a DepthAlgo.
def has_reldepthmap(self, gimp_layer)
Determines if a layer has (uses) a depth map as relative map (relative depth values between the neigh...
def has_fixdepthmap(self, gimp_layer)
Determines if a layer has (uses) a depth map as fixed map fixed depth values)
This class is responsible to compute the depth of a layer.
def has_depth(self, gimp_layer)
Determines if a used depth is specified for the layer.
def layer2array(layer, dtype=None)
converts a layer to an array.
def get_disparity(self, gimp_layer)
Determines the depth value or the map of depth values of a layer.
def is_depth_map(self, gimp_layer)
Determines if a layer is a depth map.