public void ComputeCentroids( IImageRaster <IRasterType, int> image_labeling, IImageRaster <IRasterType, DomainType> image_data, IList <int[]> cluster_spatial_centroids, IList <DomainType> cluster_feature_centroids) { //Use the cluster raster for spacing the clusters in the image IList <IList <DomainType> > clusters = new List <IList <DomainType> >(); int dimension_count = image_labeling.Raster.DimensionCount; int element_count = image_labeling.Raster.ElementCount; int [] element_coordinates = new int[dimension_count]; //clear clusters // TODO make paralel for (int cluster_index = 0; cluster_index < cluster_spatial_centroids.Count; cluster_index++) { clusters.Add(new List <DomainType>()); for (int dimension_index = 0; dimension_index < image_labeling.Raster.DimensionCount; dimension_index++) { cluster_spatial_centroids[cluster_index][dimension_index] = 0; } } // Aggregate cluster. // TODO make paralel for (int element_index = 0; element_index < element_count; element_index++) { int cluster_index = image_labeling.GetElementValue(element_index); image_data.Raster.GetElementCoordinatesRBA(element_index, element_coordinates); clusters[cluster_index].Add(image_data.GetElementValue(element_index)); ToolsMathCollectionInteger.AddFill(cluster_spatial_centroids[cluster_index], element_coordinates, cluster_spatial_centroids[cluster_index]); } // Compute new cluster centers. // TODO make paralel for (int cluster_index = 0; cluster_index < clusters.Count; cluster_index++) { if (clusters[cluster_index].Count != 0) { for (int dimension_index = 0; dimension_index < image_labeling.Raster.DimensionCount; dimension_index++) { cluster_spatial_centroids[cluster_index][dimension_index] /= clusters[cluster_index].Count; } cluster_feature_centroids[cluster_index] = d_centroid_feature_calculator.Compute(clusters[cluster_index]); } else { // reduce cluster count cluster_feature_centroids.RemoveAt(cluster_index); cluster_spatial_centroids.RemoveAt(cluster_index); clusters.RemoveAt(cluster_index); cluster_index--; } } }
public ASLIC( int iteration_count, int [] cluster_dimensions, IFunctionDistance <DomainType, float> distance_features, IFunction <IList <DomainType>, DomainType> centroid_calculator, float feature_weight) { this.d_iteration_count = iteration_count; this.d_cluster_dimensions = cluster_dimensions; this.d_cluster_dimensions_double = ToolsMathCollectionInteger.Multiply(d_cluster_dimensions, 2); this.d_distance_features = distance_features; this.d_centroid_feature_calculator = centroid_calculator; this.feature_weight = feature_weight; }
private void InitMembers(double [] factors) { Debug.Assert(factors.Length == 4); argb_integer_weigths = new int[4]; argb_integer_temp = new int[4]; //reduced so it will not go out of uint32 range double sum = ToolsMathCollection.Sum(factors); double multiplier = (int.MaxValue) / (sum * 255); for (int index = 0; index < factors.Length; index++) { argb_integer_weigths[index] = (ushort)Math.Floor(factors[index] * multiplier); } argb_integer_divisor = ToolsMathCollectionInteger.Sum(argb_integer_weigths); }
public Polynomial <DomainType> Subtract(Polynomial <DomainType> other) { Debug.Assert(algebra.Equals(other.algebra)); DomainType[] coeffecients = new DomainType[Math.Max(this.coeffecients.Length, other.coeffecients.Length)]; for (int index = 0; index < coeffecients.Length; index++) { if (index < this.coeffecients.Length) { coeffecients[index] = this.coeffecients[index]; } else { coeffecients[index] = algebra.AddIdentity; } } for (int index = 0; index < other.coeffecients.Length; index++) { coeffecients[index] = algebra.Subtract(coeffecients[index], other.coeffecients[index]); } return(new Polynomial <DomainType>(algebra, ToolsMathCollectionInteger.CropValuesEnd(coeffecients, algebra.AddIdentity))); }
protected ARasterInteger( int [] size) { this.size = size; ElementCount = ToolsMathCollectionInteger.product(this.size); }