raytools.mapper¶
Mapper¶
- class raytools.mapper.Mapper(dxyz=(0.0, 0.0, 1.0), sf=(1, 1), bbox=((0, 0), (1, 1)), aspect=None, name='mapper', origin=(0, 0, 0), jitterrate=1.0, uvz=0.0)[source]¶
Bases:
object
translate between world and normalized UV space. do not use directly, instead use an inheriting class.
- Parameters:
sf (tuple np.array, optional) – scale factor for each axis (array of length(2)
bbox (tuple np.array, optional) – bounding box for mapper shape (2, 2)
name (str, optional) – used for output file naming
- property aspect¶
- property dxyz¶
(float, float, float) central view direction
- property bbox¶
bounding box of view
- Type:
np.array of shape (2,2)
- idx2uv(idx, shape, jitter=True)[source]¶
- Parameters:
idx (flattened index)
shape – the shape to unravel into
jitter (bool, optional) – randomly offset coordinates within grid
- Returns:
uv – uv coordinates
- Return type:
np.array
- init_img(res=512, jitter=0.0, **kwargs)[source]¶
Initialize an image array with vectors and mask
- Parameters:
res (int, optional) – image array resolution
jitter (float, optional) – pixel jitter rate
kwargs – passed to self.header
- Returns:
img (np.array) – zero array of shape (res, res)
vecs (np.array) – direction vectors corresponding to each pixel (img.size, 3)
mask (np.array) – indices of flattened img that are in view
mask2 (np.array None) –
if ViewMapper has inverse, mask for opposite view, usage:
add_to_img(img, vecs[mask], mask) add_to_img(img[res:], vecs[res:][mask2], mask2
header (str)
AngularMixin¶
- class raytools.mapper.angularmixin.AngularMixin[source]¶
Bases:
object
includes overrides of transformation functions for angular type mapper classes. Inherit before raytools.mapper.Mapper eg:
NewMapper(AngularMixin, Mapper)
initialization of NewMapper must include declarations of:
self._viewangle = viewangle self._chordfactor = chordfactor self._ivm = ivm
- in_view(vec, indices=True, tol=0.0)[source]¶
generate mask for vec that are in the field of view (up to 180 degrees) if view aspect is 2, only tests against primary view direction
- init_img(res=512, pt=(0, 0, 0), features=1, viewproj='vta', indices=True, **kwargs)[source]¶
Initialize an image array with vectors and mask
- Parameters:
res (int, optional) – image array resolution
pt (tuple, optional) – view point for image header
features (int, optional) – when greater than 1 initialize img array with N output channels
viewproj (str, optional) –
output view projection chose from:
angular: '[Aa]*', 'vta', 'fish*' shirley chiu: '[Uu]*', 'square'
- Returns:
img (np.array) – zero array of shape (res*self.aspect, res)
vecs (np.array) – direction vectors corresponding to each pixel (img.size, 3)
mask (np.array) – indices of flattened img that are in view
mask2 (np.array None) – if features > 1, use mask 2 fro color images
header (str)
- property viewangle¶
view angle
- property ivm¶
viewmapper for opposite view direction (in case of 360 degree view
ViewMapper¶
- class raytools.mapper.ViewMapper(dxyz=(0.0, 1.0, 0.0), viewangle=360.0, name='view', origin=(0, 0, 0), jitterrate=0.5)[source]¶
Bases:
AngularMixin
,Mapper
translate between world direction vectors and normalized UV space for a given view angle. pixel projection yields equiangular projection
- Parameters:
dxyz (tuple, optional) – central view direction
viewangle (float, optional) – if < 180, the horizontal and vertical view angle, if greater, view becomes 360,180
- property aspect¶
- property dxyz¶
(float, float, float) central view direction
- idx2uv(idx, shape, jitter=True)[source]¶
- Parameters:
idx (flattened index)
shape – the shape to unravel into
jitter (bool, optional) – randomly offset coordinates within grid
- Returns:
uv – uv coordinates
- Return type:
np.array
- transform_to(imarray, other, nearest=False)[source]¶
take an image arrray with an assumed projection of self and transform it to other
- Parameters:
imarray (np.array) – 2-d or 3-d array with (features,x,y)
other (raytools.ViewMapper) – the destination view
nearest (bool) – disable linear interpolation and use nearest pixel sets the method= of scipy.interpolate.RegularGridInterpolator
- Return type:
np.array