public Problem(string path) { string[] files = Directory.GetFiles(path); string nameSeg = ""; foreach (string str in files) { nameSeg = Path.GetFileName(str); if (nameSeg.StartsWith("Seg_") || nameSeg.StartsWith("seg_") || nameSeg.StartsWith("SEG_")) { segsImg.Add((Bitmap)Bitmap.FromFile(str)); } else { Image = (Bitmap)Bitmap.FromFile(str); } } this.SuperPixelMatrix = new int[Image.Height, Image.Width]; this.Segmentations = new List <Segmentation>(); CreateSuperPixelMatrix(); Dictionary <int, List <Pixel> > spDic = GetSPDictionary(Image, SuperPixelMatrix); SPGraph = new SuperPixelGraph(SuperPixelMatrix, spDic.Count); //poner aqui el resto de las cosas q estan en el load. }
public Segmentation GetNeighbor(SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) { newLabels[i] = Labels[i]; } Random r = new Random(); //posicion del objeto q voy a cambiar de region int pos = r.Next(0, Labels.Length - 1); //le meti el -1..analizar //numero de la nueva region a seleccionar entre las posibles segun el grafo de la imagen int reg = r.Next(0, spg.AdjList[pos].Count - 1); //le meti el -1..analizar //este es el superpixel con el q me voy a pegar en el mismo cluster. int sp = spg.AdjList[pos][reg]; //Esta es la etiqueta del cluster al q voy a ser asignado. int newL = Labels[sp]; //Si la nueva posicion es la misma, cojo esta posibilidad para poner el elemento en un nuevo cluster donde esta el solo. if (newLabels[pos] == newL) { newLabels[pos] = this.maxLabel + 1; } else { newLabels[pos] = newL; } Segmentation result = new Segmentation(newLabels); return(result); }
//Devuelve una nueva segmentacion que se forma al unir "clusCount" pares de clusters en la segmentacion actual. public Segmentation Join(int clusCount, SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) { newLabels[i] = Labels[i]; } Random r = new Random(); for (int i = 0; i < clusCount; i++) { int pos = r.Next(0, Labels.Length); int reg = r.Next(0, spg.AdjList[pos].Count); int sp = spg.AdjList[pos][reg]; int newL = newLabels[sp]; int value = newLabels[pos]; for (int j = 0; j < newLabels.Length; j++) { if (newLabels[j] == value) { newLabels[j] = newL; } } } Segmentation result = new Segmentation(newLabels); return(result); }
//Aqui estoy asumiendo q ya la segmentacion inicial tiene k clusters, con k el valor q quiero q tengan todas. public Segmentation GetNeighborKFIJO(SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) { newLabels[i] = Labels[i]; } Random r = new Random(); //posicion del objeto q voy a cambiar de region int pos = 0; do { pos = r.Next(0, Labels.Length); }while (this.Clusters[Labels[pos]].Count <= 1); //numero de la nueva region a seleccionar entre las posibles segun el grafo de la imagen int reg = r.Next(0, spg.AdjList[pos].Count); //este es el superpixel con el q me voy a pegar en el mismo cluster. int sp = spg.AdjList[pos][reg]; //Esta es la etiqueta del cluster al q voy a ser asignado. int newL = Labels[sp]; //Tiene el problema de q si es la misma etiqueta...estoy generando la misma segmentacion de nuevo!! newLabels[pos] = newL; Segmentation result = new Segmentation(newLabels); return(result); }
//Devuelve una nueva segmentacion que se forma al separar "clusCount" clusters (en dos nuevos clusters) en la segmentacion actual. public Segmentation Split(int clusCount, SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) { newLabels[i] = Labels[i]; } Random r = new Random(); int last = this.maxLabel; for (int i = 0; i < clusCount; i++) { int pos = r.Next(0, Labels.Length); newLabels[pos] = last + 1; last++; } Segmentation result = new Segmentation(newLabels); return(result); }
public Problem(string path) { string[] files = Directory.GetFiles(path); string nameSeg = ""; foreach (string str in files) { nameSeg = Path.GetFileName(str); if (nameSeg.StartsWith("Seg_") || nameSeg.StartsWith("seg_") || nameSeg.StartsWith("SEG_")) segsImg.Add((Bitmap)Bitmap.FromFile(str)); else Image = (Bitmap)Bitmap.FromFile(str); } this.SuperPixelMatrix = new int[Image.Height, Image.Width]; this.Segmentations = new List<Segmentation>(); CreateSuperPixelMatrix(); Dictionary<int, List<Pixel>> spDic = GetSPDictionary(Image, SuperPixelMatrix); SPGraph = new SuperPixelGraph(SuperPixelMatrix, spDic.Count); //poner aqui el resto de las cosas q estan en el load. }
//Devuelve una nueva segmentacion que se forma al separar "clusCount" clusters (en dos nuevos clusters) en la segmentacion actual. public Segmentation Split(int clusCount, SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) newLabels[i] = Labels[i]; Random r = new Random(); int last = this.maxLabel; for (int i = 0; i < clusCount; i++) { int pos = r.Next(0, Labels.Length); newLabels[pos] = last + 1; last++; } Segmentation result = new Segmentation(newLabels); return result; }
//Devuelve una nueva segmentacion que se forma al unir "clusCount" pares de clusters en la segmentacion actual. public Segmentation Join(int clusCount, SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) newLabels[i] = Labels[i]; Random r = new Random(); for (int i = 0; i < clusCount; i++) { int pos = r.Next(0, Labels.Length); int reg = r.Next(0, spg.AdjList[pos].Count); int sp = spg.AdjList[pos][reg]; int newL = newLabels[sp]; int value = newLabels[pos]; for (int j = 0; j < newLabels.Length; j++) { if (newLabels[j] == value) newLabels[j] = newL; } } Segmentation result = new Segmentation(newLabels); return result; }
//Aqui estoy asumiendo q ya la segmentacion inicial tiene k clusters, con k el valor q quiero q tengan todas. public Segmentation GetNeighborKFIJO(SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) newLabels[i] = Labels[i]; Random r = new Random(); //posicion del objeto q voy a cambiar de region int pos = 0; do { pos = r.Next(0, Labels.Length); } while (this.Clusters[Labels[pos]].Count <= 1); //numero de la nueva region a seleccionar entre las posibles segun el grafo de la imagen int reg = r.Next(0, spg.AdjList[pos].Count); //este es el superpixel con el q me voy a pegar en el mismo cluster. int sp = spg.AdjList[pos][reg]; //Esta es la etiqueta del cluster al q voy a ser asignado. int newL = Labels[sp]; //Tiene el problema de q si es la misma etiqueta...estoy generando la misma segmentacion de nuevo!! newLabels[pos] = newL; Segmentation result = new Segmentation(newLabels); return result; }
public Segmentation GetNeighbor(SuperPixelGraph spg) { int[] newLabels = new int[Labels.Length]; for (int i = 0; i < Labels.Length; i++) newLabels[i] = Labels[i]; Random r = new Random(); //posicion del objeto q voy a cambiar de region int pos = r.Next(0, Labels.Length-1); //le meti el -1..analizar //numero de la nueva region a seleccionar entre las posibles segun el grafo de la imagen int reg = r.Next(0, spg.AdjList[pos].Count - 1); //le meti el -1..analizar //este es el superpixel con el q me voy a pegar en el mismo cluster. int sp = spg.AdjList[pos][reg]; //Esta es la etiqueta del cluster al q voy a ser asignado. int newL = Labels[sp]; //Si la nueva posicion es la misma, cojo esta posibilidad para poner el elemento en un nuevo cluster donde esta el solo. if (newLabels[pos] == newL) newLabels[pos] = this.maxLabel + 1; else newLabels[pos] = newL; Segmentation result = new Segmentation(newLabels); return result; }