public void SetElementValue(int element_index, RangeType value) { int[] coordinates_x_y = Raster.GetElementCoordinates(element_index); int element_index_inner = wrapped_image.Raster.GetElementIndex(coordinates_x_y[0], coordinates_x_y[1], index_2, index_3); wrapped_image.SetElementValue(element_index_inner, value); }
public void AssignElements( IImageRaster <IRasterType, int> image_labeling, IImageRaster <IRasterType, float> image_distance, IImageRaster <IRasterType, DomainType> image_data, IList <int[]> cluster_spatial_centroids, IList <DomainType> cluster_feature_centroids, int[] neigbourhood_element_indexes) { int dimension_count = image_labeling.Raster.DimensionCount; int[] element_coordinates = new int[dimension_count]; for (int element_index = 0; element_index < image_distance.Raster.ElementCount; element_index++) { image_distance.SetElementValue(element_index, Single.MaxValue); } //for each cluster // TODO make paralel (Beware race conditoin in setting labeling and distance RB ordering might help or make it image driven) for (int index_cluster = 0; index_cluster < cluster_spatial_centroids.Count; index_cluster++) { DomainType centroid = cluster_feature_centroids[index_cluster]; int[] coordinates_cluster = cluster_spatial_centroids[index_cluster]; //for each pixel in a region around the cluster neigbourhood image_data.Raster.GetNeigbourhoodElementIndexesRBA(coordinates_cluster, this.d_cluster_dimensions, neigbourhood_element_indexes); for (int element_index_index = 0; element_index_index < neigbourhood_element_indexes.Length; element_index_index++) { int index_element = neigbourhood_element_indexes[element_index_index]; if (index_element != -1) { image_data.Raster.GetElementCoordinatesRBA(index_element, element_coordinates); //Compute the distance D between the element and the cluster. float distance = 0; for (int dimension_index = 0; dimension_index < dimension_count; dimension_index++) { float dimension_distance = ((float)Math.Abs(coordinates_cluster[dimension_index] - element_coordinates[dimension_index])) / this.d_cluster_dimensions[dimension_index]; distance += dimension_distance * dimension_distance; } distance += d_distance_features.Compute(centroid, image_data.GetElementValue(index_element)) * this.feature_weight; //Compute if it is less than the current distance update cluster membership if (distance < image_distance.GetElementValue(index_element)) { image_labeling.SetElementValue(index_element, index_cluster); image_distance.SetElementValue(index_element, distance); } } } } }
public static void SetOverlay <RasterType, DomainType> ( IImageRaster <RasterType, DomainType> destination, IImageRaster <RasterType, bool> overlay_mask, DomainType overlay_value) where RasterType : IRasterInteger { if (!destination.Raster.Equals(overlay_mask.Raster)) { throw new Exception("Raster mismatch"); } Parallel.For(0, overlay_mask.Raster.ElementCount, element_index => { if (overlay_mask.GetElementValue(element_index)) { destination.SetElementValue(element_index, overlay_value); } }); }
public void ImproveLabeling( IImageRaster <RasterType, int> initial_labeling, IImageRaster <RasterType, int> new_labeling, IList <IImageRaster <RasterType, FeatureType> > feature_images) { int element_count = initial_labeling.Raster.ElementCount; int neighborhood_size = 0; int [] element_coordinates = new int [initial_labeling.Raster.DimensionCount]; int [] element_neighborhood_indexes = new int [this.neighborhood_element_count]; int [] state_vector = new int [this.neighborhood_element_count]; FeatureType [] feature_neighborhood_values = new FeatureType [neighborhood_size]; FeatureType [] feature_vector = new FeatureType [neighborhood_size]; for (int element_index = 0; element_index < element_count; element_index++) { initial_labeling.Raster.GetNeigbourhoodElementIndexesRBA(element_coordinates, this.neighborhood_size, element_neighborhood_indexes); // initial_labeling.GetElementValuesFill(element_neighborhood_indexes, this.background_label, state_vector); for (int feature_image_index = 0; feature_image_index < feature_image_count; feature_image_index++) { //feature_images[feature_image_index].GetElementValuesFill(element_neighborhood_indexes, this.background_feature, feature_neighborhood_values); Array.Copy(feature_neighborhood_values, 0, feature_vector, this.neighborhood_element_count * feature_image_index, this.neighborhood_element_count); } float best_likelyhood = Single.MinValue; for (int label_index = 0; label_index < this.label_count; label_index++) { float likelyhood = label_likelyhood_models[label_index].Compute(state_vector) * feature_likelyhood_models[label_index].Compute(feature_vector); if (best_likelyhood < likelyhood) { best_likelyhood = likelyhood; new_labeling.SetElementValue(label_index, label_index); } } } }
public static void GetShellRBA <RasterType>(IImageRaster <RasterType, bool> source, ITopologyElement topology, IImageRaster <RasterType, bool> target, bool border_is_shell) where RasterType : IRasterInteger { int[] element_neigbour_array = new int[topology.MaximumConnectivity]; for (int element_index = 0; element_index < source.Raster.ElementCount; element_index++) { if (source.GetElementValue(element_index)) { bool is_shell = false; topology.ElementNeighboursRBA(element_index, element_neigbour_array); foreach (int other_element_index in element_neigbour_array) { if (other_element_index != -1) { if (!source.GetElementValue(other_element_index)) { is_shell = true; } } else { if (border_is_shell) { is_shell = true; } } } if (is_shell) { target.SetElementValue(element_index, true); } } } }