public Set Load() { Set set = null; Bitmap bmp = (Bitmap)Bitmap.FromFile(SourceFilePath); //Ya tengo los atributos Attributes attributes = new Attributes(new List<Attribute>(new Attribute[] { new Attribute("PixelsCount", null), new Attribute("R_Ave", null), new Attribute("G_Ave", null), new Attribute("B_Ave", null), new Attribute("R_error", null), new Attribute("G_error", null), new Attribute("B_error", null), new Attribute("X_GravCenter", null), new Attribute("Y_GravCenter", null), new Attribute("Radius", null), new Attribute("Perimeter", null) })); //Ya tengo el nombre string relationName = Path.GetFileNameWithoutExtension(SourceFilePath); //Faltan los elementos...para esto tengo q cargar el archivo q contiene la informacion de los superpixels. string directoryName = Path.GetDirectoryName(SourceFilePath); string superPixelPath = directoryName + "//SP_supPix" + relationName + ".mat.txt"; int[,] sp = LoadSupPixMatrix(superPixelPath); Dictionary<int, List<Pixel>> spDic = GetSPDictionary(bmp, sp); SuperPixelGraph graph = new SuperPixelGraph(sp, spDic.Count); //Ya tengo los elementos List<Element> elements = GetElements(spDic, graph); set = new Set(relationName, elements, attributes); set.Image = bmp; set.FolderName = directoryName; set.SPGraph = graph; set.SuperPixelMatrix = sp; set.Segmentations = LoadSegmentations(SourceFilePath, sp, elements.Count); set.KValue = this.kvalue; set.GroundTruths = LoadGTs(SourceFilePath); //PRUEBAAAA...BORRAR //int[] l0 = new int[set.Segmentations[0].Labels.Length]; //int[] l1 = new int[set.Segmentations[0].Labels.Length]; //for (int i = 0; i < l0.Length; i++) // l0[i] = i; //Segmentation seg0 = new Segmentation(l0); //Segmentation seg1 = new Segmentation(l1); //set.Segmentations.Add(seg0); //set.Segmentations.Add(seg1); /// return set; }
//Devuelve la lista de superpixels como elementos a partir del diccionario de los superpixels private List<Element> GetElements(Dictionary<int, List<Pixel>> spDic, SuperPixelGraph graph) { //cp--cantidad de pixels, r--R, g--G, b--B (RGB values), cgx--coordenada x del centro de gravedad, cgy--coordenada y del centro de gravedad, ra--radio, definido como la distancia del pixel mas alejado al centro de gravedad. List<Element> elements = new List<Element>(); foreach (int spID in spDic.Keys) { List<object> realvalues = new List<object>(); int cp = 0, r = 0, g = 0, b = 0, cgx = 0, cgy = 0, ra = 0; for (int j = 0; j < spDic[spID].Count; j++) { cp++; r += spDic[spID][j].R; g += spDic[spID][j].G; b += spDic[spID][j].B; cgx += spDic[spID][j].j; cgy += spDic[spID][j].i; } r /= spDic[spID].Count; g /= spDic[spID].Count; b /= spDic[spID].Count; cgx /= spDic[spID].Count; cgy /= spDic[spID].Count; int aux=0, auxI=0, auxJ = 0; double r_error = 0, g_error = 0, b_error = 0; int perim =0; for (int j = 0; j < spDic[spID].Count; j++) { auxI = spDic[spID][j].i; auxJ = spDic[spID][j].j; aux = (int)Math.Sqrt(((auxI - cgy) * (auxI - cgy)) + ((auxJ - cgx) * (auxJ - cgx))); if (aux > ra) ra = aux; r_error += Math.Abs(spDic[spID][j].R - r); g_error += Math.Abs(spDic[spID][j].G - g); b_error += Math.Abs(spDic[spID][j].B - b); } r_error /= spDic[spID].Count; g_error /= spDic[spID].Count; b_error /= spDic[spID].Count; perim = graph.PerimList[spID]; realvalues.Add(cp); realvalues.Add(r); realvalues.Add(g); realvalues.Add(b); realvalues.Add(r_error); realvalues.Add(g_error); realvalues.Add(b_error); realvalues.Add(cgx); realvalues.Add(cgy); realvalues.Add(ra); realvalues.Add(perim); Element e = new Element(realvalues); e.Name = "SP-" + spID; e.Index = spID; elements.Add(e); } return elements; }