Coverage for navipy/processing/pcode.py : 56%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" place code derived from scene """
"""Return the average along the elevation of a scene
:param scene: the scenery at a given location (a 4d numpy array) :returns: the skyline [1,azimuth,channel,1] :rtype: np.ndarray
"""
"""Return the michelson constrast
.. math::
\\frac{I_\\text{max}-I_\\text{min}}{I_\\text{max}+I_\\text{min}}
with :math:`I_\\text{max}` and :math:`I_\\text{min}` representing the \ highest and lowest luminance in an image region around each pixel.
:param scene: an image based scene :param size: the size of the region to calculate the maximum \ and minimum of the local image intensity :returns: the michelson-contrast :rtype: np.ndarray
""" raise TypeError('scene should be image based\ to compute the michelson constrast') size=size, mode='wrap') size=size, mode='wrap')
"""Return the michelson contrast wheighted nearness
:param scene: an image based scene :param contrast_size: the size of the region to calculate the maximum \ and minimum of the local image intensity in the michelson-contrast. :param distance_channel: the index of the distance-channel.
""" raise TypeError('scene should be image based to\ compute the contrast weighted nearness')
"""Place code vectors
:param place_code: the place code at a given location (e.g. an ibs scene) :param viewing_directions: viewing direction of each pixel :returns: the place code vectors in cartesian coordinates :rtype: (np.ndarray)
""" # print("place code shape",place_code.shape) elif is_obpc(place_code): component_dim = __obpc_indeces__['component'] channel_dim = __obpc_indeces__['channel'] else: raise TypeError('place code should be either an ibpc or obpc')
raise Exception('dimensions of place code and viewing\ direction do not match') raise Exception('dimensions of place code and viewing\ direction do not match') raise TypeError('viewing_directions should be a numpy array') raise Exception('the last dimension ({}) of the place-code\ should be 1'.format(place_code.shape[component_dim])) raise ValueError(" Elevation must be radians in range [-pi;pi]") raise ValueError(" max difference in elevation must be < 2*pi") raise ValueError(" Azimuth must be radians in range [-2*pi;2*pi]") x, y, z = spherical_to_cartesian(elevation, azimuth, radius=1) unscaled_lv = np.zeros((viewing_directions.shape[0], viewing_directions.shape[1], 3)) unscaled_lv[..., __cartesian_indeces__['x']] = x unscaled_lv[..., __cartesian_indeces__['y']] = y unscaled_lv[..., __cartesian_indeces__['z']] = z scaled_lv = np.zeros_like(place_code) # (3,) -> (1,1,3) or (1,1,1,3) see numpy.tile scaled_lv = np.tile(scaled_lv, (unscaled_lv.shape[-1],)) for channel_index in range(0, scaled_lv.shape[channel_dim]): radius = np.tile(place_code[..., channel_index, 0] [..., np.newaxis], (scaled_lv.shape[-1],)) scaled_lv[..., channel_index, :] = unscaled_lv * radius return scaled_lv
"""Calculate the average scene vector
:param place_code: the place code at a given location (e.g. an ibs scene) :param viewing_directions: viewing direction of each pixel :returns: the average place-code vector :rtype: (np.ndarray)
""" raise Exception('dimensions of place code and viewing\ direction do not match') raise Exception('dimensions of place code and viewing\ direction do not match') if is_ibpc(place_code): return (scaled_lv.sum(axis=0).sum(axis=0))[np.newaxis, np.newaxis, ...] elif is_obpc(place_code): return (scaled_lv.sum(axis=0))[np.newaxis, ...] else: raise TypeError('place code is neither an ibpc nor obpc')
position_df, ref_pos, nb_snapshot, radius, blender_view): """Return set of views around and oriented towards memorized location :param mydb: Database environment :param position_df: dataframe with the positions of the grid :param ref_pos: df with x, y and z position of the reference snapshot :param nb_snapshot: number of wanted set of views (multiple of 2) :param radius: distance from memorized location to take snapshots :param blender_view: viewing axis camera id y=90, if x=0 :returns: list of reoriented image array, snaphots positions :rtypes: array of np.array, pd.DataFrame """
svp_all = pd.DataFrame(columns=['x', 'y', 'z', 'frame']) # angle of rotation ang_deg = 360 / nb_snapshot ang = np.deg2rad(ang_deg) # make the different view for i in range(0, nb_snapshot): x = ref_pos.x + radius * np.cos(ang * i) y = ref_pos.y + radius * np.sin(ang * i) z = ref_pos.z svp_frame = pd.Series(index=['frame', 'x', 'y', 'z']) distance_arr = pd.Series(index=position_df.index) for index, pos in position_df.dropna().iterrows(): distance = (pos.x - x)**2 distance += (pos.y - y)**2 distance += (pos.z - z)**2 distance_arr[index] = distance svp_frame.frame = int(distance_arr.dropna().argmin()) svp_frame.x = position_df.x[svp_frame.frame] svp_frame.y = position_df.y[svp_frame.frame] svp_frame.z = position_df.z[svp_frame.frame] svp_all.loc[i] = [svp_frame.x, svp_frame.y, svp_frame.z, int(svp_frame.frame)] reoriented_mem = [] rot = list()
for i, j in svp_all.iterrows(): ide = int(j.frame) image = mydb.scene(rowid=ide) alpha = np.floor(np.rad2deg(np.arctan2( (ref_pos.y - j.y), (ref_pos.x - j.x)))) alpha = alpha + blender_view # because y view on blender rot.append(alpha) alpha = int(alpha) svp_reorient = np.roll(image, alpha, 1) reoriented_mem.append(svp_reorient) return reoriented_mem, svp_all |