def project_ground_to_image(self, coords, **kwargs): """ Transforms a 3D ECF point to pixel (row/column) coordinates. This is implemented in accordance with the SICD Image Projections Description Document. **Really Scene-To-Image projection.**" Parameters ---------- coords : numpy.ndarray|tuple|list ECF coordinate to map to scene coordinates, of size `N x 3`. kwargs The keyword arguments for the :func:`sarpy.geometry.point_projection.ground_to_image` method. Returns ------- Tuple[numpy.ndarray, float, int] * `image_points` - the determined image point array, of size `N x 2`. Following the SICD convention, he upper-left pixel is [0, 0]. * `delta_gpn` - residual ground plane displacement (m). * `iterations` - the number of iterations performed. See Also -------- sarpy.geometry.point_projection.ground_to_image """ if 'use_structure_coa' not in kwargs: kwargs['use_structure_coa'] = True return point_projection.ground_to_image(coords, self, **kwargs)
def get_sq_residue(perturb): da, dv, dr = get_params(perturb) img_proj, _, _ = ground_to_image(ecf_coords, struct, max_iterations=100, use_structure_coa=False, delta_arp=da, delta_varp=dv, range_bias=dr, adj_params_frame='ECF') diff = (img_proj - img_coords) return numpy.sum(diff * diff, axis=1)
def create_ortho( self, output_ny, output_nx, ): input_image_data = self.display_image display_image_nx = input_image_data.shape[1] display_image_ny = input_image_data.shape[0] image_points = np.zeros((display_image_nx * display_image_ny, 2)) canvas_coords_1d = np.zeros(2 * display_image_nx * display_image_ny) tmp_x_vals = np.arange(0, display_image_ny) tmp_y_vals = np.zeros(display_image_ny) for x in range(display_image_nx): start_index = display_image_ny * 2 * x + 1 end_index = start_index + display_image_ny * 2 canvas_coords_1d[start_index:end_index:2] = tmp_x_vals canvas_coords_1d[display_image_ny * x * 2::2][0:display_image_ny] = tmp_y_vals + x full_image_coords = self.canvas_coords_to_full_image_yx( canvas_coords_1d) image_points[:, 0] = full_image_coords[0::2] image_points[:, 1] = full_image_coords[1::2] sicd_meta = self.reader_object.sicd_meta ground_points_ecf = point_projection.image_to_ground( image_points, sicd_meta) ground_points_latlon = geocoords.ecf_to_geodetic(ground_points_ecf) world_y_coordinates = ground_points_latlon[:, 0] world_x_coordinates = ground_points_latlon[:, 1] x = np.ravel(world_x_coordinates) y = np.ravel(world_y_coordinates) z = np.ravel(np.transpose(input_image_data)) ground_x_grid, ground_y_grid = self._create_ground_grid( min(x), max(x), min(y), max(y), output_nx, output_ny) ortho_image = interp.griddata((x, y), z, (ground_x_grid, ground_y_grid), method='nearest') s = np.zeros((output_nx * output_ny, 3)) s[:, 0] = ground_y_grid.ravel() s[:, 1] = ground_x_grid.ravel() s[:, 2] = ground_points_latlon[0, 2] s_ecf = geocoords.geodetic_to_ecf(s) gridded_image_pixels = point_projection.ground_to_image( s_ecf, sicd_meta) full_image_coords_y = full_image_coords[0::2] full_image_coords_x = full_image_coords[1::2] mask = np.ones_like(gridded_image_pixels[0][:, 0]) indices_1 = np.where( gridded_image_pixels[0][:, 0] < min(full_image_coords_y)) indices_2 = np.where( gridded_image_pixels[0][:, 1] < min(full_image_coords_x)) indices_3 = np.where( gridded_image_pixels[0][:, 0] > max(full_image_coords_y)) indices_4 = np.where( gridded_image_pixels[0][:, 1] > max(full_image_coords_x)) mask[indices_1] = 0 mask[indices_2] = 0 mask[indices_3] = 0 mask[indices_4] = 0 mask_2d = np.reshape(mask, (output_ny, output_nx)) return ortho_image * mask_2d