private FakeImageObject GetRandomFromObjectList() { FakeImageObject result = new FakeImageObject(); if (hitClosesImagesList == null) { hitClosesImagesList = new int[objectList.Count]; } if (hitClosesImagesList.Where(x => x == 1).Count() == objectList.Count) { result.SetPropertiesFromImageObject(objectList.First()); return(result); } int imageIndex; do { imageIndex = random.Next(0, objectList.Count - 1); } while (hitClosesImagesList[imageIndex] != 0); hitClosesImagesList[imageIndex] = 1; result.SetPropertiesFromImageObject(objectList.ToArray()[imageIndex]); return(result); }
private FakeImageObject GetClosestObjectFromObjectList(FakeImageObject fakeImage) { FakeImageObject result = new FakeImageObject(); if (hitClosesImagesList == null) { hitClosesImagesList = new int[objectList.Count]; } ImageObject[] classes = objectList.ToArray(); double[] distances = new double[objectList.Count]; for (int i = 0; i < objectList.Count; i++) { distances[i] = Math.Abs(areaCoefficient * (classes[i].Area - fakeImage.Area)) + Math.Abs(densityCoefficient * (classes[i].Density - fakeImage.Density)) + Math.Abs(elongationCoefficient * (classes[i].Elongation - fakeImage.Elongation)) + Math.Abs(perimeterCoefficient * (classes[i].Perimeter - fakeImage.Perimeter)) + Math.Abs(massCenterCoefficient * Math.Sqrt( (classes[i].MassCenter.X - fakeImage.MassCenter.X) * (classes[i].MassCenter.X - fakeImage.MassCenter.X) + (classes[i].MassCenter.Y - fakeImage.MassCenter.Y) * (classes[i].MassCenter.Y - fakeImage.MassCenter.Y)) ); } int index = 0; double minRange = distances[0]; for (int i = 0; i < objectList.Count; i++) { if (hitClosesImagesList[i] == 0 && distances[i] <= minRange) { minRange = distances[i]; index = i; } } result.SetPropertiesFromImageObject(classes[index]); hitClosesImagesList[index] = 1; return(result); }
public void SetObjectsToGroups() { FakeImageObject[] mediansArray = new FakeImageObject[kMedians]; hitClosesImagesList = null; for (int i = 0; i < kMedians; i++) { mediansArray[i] = GetRandomFromObjectList(); } hitClosesImagesList = null; List <ImageObject>[] imageClasses = new List <ImageObject> [kMedians]; for (int i = 0; i < kMedians; i++) { imageClasses[i] = new List <ImageObject>(); } foreach (ImageObject imageObject in objectList) { imageClasses[GetClassIndex(mediansArray, imageObject)].Add(imageObject); } bool flag = true; while (flag) { flag = false; mediansArray = new FakeImageObject[kMedians]; hitClosesImagesList = null; for (int i = 0; i < kMedians; i++) { mediansArray[i] = GetClosestObjectFromObjectList(GetAverageFromImageList(imageClasses[i])); } hitClosesImagesList = null; List <ImageObject>[] tempImageClasses = new List <ImageObject> [kMedians]; for (int i = 0; i < kMedians; i++) { tempImageClasses[i] = new List <ImageObject>(); } foreach (List <ImageObject> objectList1 in imageClasses) { foreach (ImageObject imageObject in objectList1) { tempImageClasses[GetClassIndex(mediansArray, imageObject)].Add(imageObject); } } for (int i = 0; i < kMedians; i++) { if (tempImageClasses[i].Equals(imageClasses[i])) { flag = true; } } imageClasses = tempImageClasses; } foreach (List <ImageObject> imageObjectList in imageClasses) { foreach (ImageObject imageObject in imageObjectList) { foreach (Point point in imageObject.Points) { groupMap[point.X, point.Y] = Array.IndexOf(imageClasses, imageObjectList) + 2; } } } }
private FakeImageObject GetRandomFromObjectList() { FakeImageObject result = new FakeImageObject(); if (hitClosesImagesList == null) { hitClosesImagesList = new int[objectList.Count]; } if (hitClosesImagesList.Where(x => x == 1).Count() == objectList.Count) { result.SetPropertiesFromImageObject(objectList.First()); return result; } int imageIndex; do { imageIndex = random.Next(0, objectList.Count - 1); } while (hitClosesImagesList[imageIndex] != 0); hitClosesImagesList[imageIndex] = 1; result.SetPropertiesFromImageObject(objectList.ToArray()[imageIndex]); return result; }
private FakeImageObject GetClosestObjectFromObjectList(FakeImageObject fakeImage) { FakeImageObject result = new FakeImageObject(); if (hitClosesImagesList == null) { hitClosesImagesList = new int[objectList.Count]; } ImageObject[] classes = objectList.ToArray(); double[] distances = new double[objectList.Count]; for (int i = 0; i < objectList.Count; i++) { distances[i] = Math.Abs(areaCoefficient * (classes[i].Area - fakeImage.Area)) + Math.Abs(densityCoefficient * (classes[i].Density - fakeImage.Density)) + Math.Abs(elongationCoefficient * (classes[i].Elongation - fakeImage.Elongation)) + Math.Abs(perimeterCoefficient * (classes[i].Perimeter - fakeImage.Perimeter)) + Math.Abs(massCenterCoefficient * Math.Sqrt( (classes[i].MassCenter.X - fakeImage.MassCenter.X) * (classes[i].MassCenter.X - fakeImage.MassCenter.X) + (classes[i].MassCenter.Y - fakeImage.MassCenter.Y) * (classes[i].MassCenter.Y - fakeImage.MassCenter.Y)) ); } int index = 0; double minRange = distances[0]; for (int i = 0; i < objectList.Count; i++) { if (hitClosesImagesList[i] == 0 && distances[i] <= minRange) { minRange = distances[i]; index = i; } } result.SetPropertiesFromImageObject(classes[index]); hitClosesImagesList[index] = 1; return result; }
private int GetClassIndex(FakeImageObject[] classes, ImageObject imageObject) { double[] distances = new double[classes.Count()]; for (int i = 0; i < classes.Count(); i++) { distances[i] = Math.Abs(areaCoefficient * (classes[i].Area - imageObject.Area)) + Math.Abs(densityCoefficient * (classes[i].Density - imageObject.Density)) + Math.Abs(elongationCoefficient * (classes[i].Elongation - imageObject.Elongation)) + Math.Abs(perimeterCoefficient * (classes[i].Perimeter - imageObject.Perimeter)) + Math.Abs(massCenterCoefficient * Math.Sqrt( (classes[i].MassCenter.X - imageObject.MassCenter.X) * (classes[i].MassCenter.X - imageObject.MassCenter.X) + (classes[i].MassCenter.Y - imageObject.MassCenter.Y) * (classes[i].MassCenter.Y - imageObject.MassCenter.Y)) ); } return Array.IndexOf(distances, distances.Min()); }
public void SetObjectsToGroups() { FakeImageObject[] mediansArray = new FakeImageObject[kMedians]; hitClosesImagesList = null; for (int i = 0; i < kMedians; i++) { mediansArray[i] = GetRandomFromObjectList(); } hitClosesImagesList = null; List<ImageObject>[] imageClasses = new List<ImageObject>[kMedians]; for (int i = 0; i < kMedians; i++) { imageClasses[i] = new List<ImageObject>(); } foreach (ImageObject imageObject in objectList) { imageClasses[GetClassIndex(mediansArray, imageObject)].Add(imageObject); } bool flag = true; while (flag) { flag = false; mediansArray = new FakeImageObject[kMedians]; hitClosesImagesList = null; for (int i = 0; i < kMedians; i++) { mediansArray[i] = GetClosestObjectFromObjectList(GetAverageFromImageList(imageClasses[i])); } hitClosesImagesList = null; List<ImageObject>[] tempImageClasses = new List<ImageObject>[kMedians]; for (int i = 0; i < kMedians; i++) { tempImageClasses[i] = new List<ImageObject>(); } foreach (List<ImageObject> objectList1 in imageClasses) { foreach (ImageObject imageObject in objectList1) { tempImageClasses[GetClassIndex(mediansArray, imageObject)].Add(imageObject); } } for (int i = 0; i < kMedians; i++) { if (tempImageClasses[i].Equals(imageClasses[i])) { flag = true; } } imageClasses = tempImageClasses; } foreach (List<ImageObject> imageObjectList in imageClasses) { foreach (ImageObject imageObject in imageObjectList) { foreach (Point point in imageObject.Points) { groupMap[point.X, point.Y] = Array.IndexOf(imageClasses, imageObjectList) + 2; } } } }