public PgmImg ReduceColors(PgmImg pgm) { var temp = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) { for (int j = 0; j < pgm.Height; j++) { temp[i, j] = Reduce(pgm[i, j], pgm.ReduceTo); } } /* * // outra forma - mais lenta * var newColorArray = new int[pgm.ReduceTo]; * for (int i = 0; i < pgm.ReduceTo ; i++) * newColorArray[i] = i * (255 / (pgm.ReduceTo-1)); * * for (int i = 0; i < matrix.GetLength(0); i++) * for (int j = 0; j < matrix.GetLength(1); j++) * temp[i, j] = (byte)Closest((int)matrix[i, j], newColorArray); */ return(temp); }
public PgmImg Expansion(PgmImg img) { var ret = img.Clone(); var EstruturanteNormal = CriaMatrizEstruturante(img); // espelha estrutura var Estruturante = (double[, ])EstruturanteNormal.Clone(); var n = img.ReduceTo; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { Estruturante[i, j] = EstruturanteNormal[n - i - 1, n - j - 1]; } } for (int i = 0; i < img.Width; i++) { for (int j = 0; j < img.Height; j++) { windowMorpho(1, img, ret, Estruturante, i, j); } } return(ret); }
public PgmImg Equalize(PgmImg pgm) { var Acumulativo = pgm.CumulativePallete(); var min = Acumulativo.Min(); var max = Acumulativo[255]; var ret = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) { for (int j = 0; j < pgm.Height; j++) { ret[i, j] = (byte)( ( (double) (Acumulativo[pgm[i, j]] - min) / (max - min) ) * 255); } } return(ret); }
public PgmImg Erosion(PgmImg img) { var ret = img.Clone(); var Estruturante = CriaMatrizEstruturante(img); for (int i = 0; i < img.Width; i++) for (int j = 0; j < img.Height; j++) windowMorpho(0, img, ret, Estruturante, i, j); return ret; }
public PgmImg MirrorY(PgmImg pgm) { var temp = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) { for (int j = 0; j < pgm.Height; j++) { temp[i, j] = pgm[i, pgm.Height - 1 - j]; } } return(temp); }
public PgmImg Erosion(PgmImg img) { var ret = img.Clone(); var Estruturante = CriaMatrizEstruturante(img); for (int i = 0; i < img.Width; i++) { for (int j = 0; j < img.Height; j++) { windowMorpho(0, img, ret, Estruturante, i, j); } } return(ret); }
public PgmImg Expansion(PgmImg img) { var ret = img.Clone(); var EstruturanteNormal = CriaMatrizEstruturante(img); // espelha estrutura var Estruturante = (double[,])EstruturanteNormal.Clone(); var n = img.ReduceTo; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) Estruturante[i, j] = EstruturanteNormal[n-i-1,n-j-1]; for (int i = 0; i < img.Width; i++) for (int j = 0; j < img.Height; j++) windowMorpho(1, img, ret, Estruturante, i, j); return ret; }
public PgmImg Equalize(PgmImg pgm) { var Acumulativo = pgm.CumulativePallete(); var min = Acumulativo.Min(); var max = Acumulativo[255]; var ret = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) for (int j = 0; j < pgm.Height; j++) ret[i, j] = (byte) ( ( (double) (Acumulativo[pgm[i, j]] - min) / (max - min) ) *255); return ret; }
public PgmImg FloydSteinberg(PgmImg pgm) { var temp = pgm.Clone(); var width = temp.Width - 1; var height = temp.Height - 1; for (int i = 0; i < temp.Width; i++) { for (int j = 0; j < temp.Height; j++) { var original = temp[i, j]; temp[i, j] = Reduce(temp[i, j], pgm.ReduceTo); var error = (double)original - (double)temp[i, j]; if (j < height) { temp[i, j + 1] = Normalize(temp[i + 0, j + 1] + error * MagicNumbers.Right); } if (i < width) { temp[i + 1, j] = Normalize(temp[i + 1, j + 0] + error * MagicNumbers.Down); } if (j < height && i < width) { temp[i + 1, j + 1] = Normalize(temp[i + 1, j + 1] + error * MagicNumbers.DownRight); } if (j > 0 && i < width) { temp[i + 1, j - 1] = Normalize(temp[i + 1, j - 1] + error * MagicNumbers.DownLeft); } } } return(temp); }
private void addHistory() { Redo = new Stack <PgmImg>(); Undo.Push(bitmap.Clone()); }
public PgmImg FloydSteinberg(PgmImg pgm) { var temp = pgm.Clone(); var width = temp.Width-1; var height = temp.Height-1; for (int i = 0; i < temp.Width; i++) for (int j = 0; j < temp.Height; j++) { var original = temp[i, j]; temp[i, j] = Reduce(temp[i, j], pgm.ReduceTo); var error = (double)original - (double)temp[i, j]; if (j < height) temp[i, j + 1] = Normalize(temp[i + 0, j + 1] + error * MagicNumbers.Right); if (i < width) temp[i + 1, j ] = Normalize(temp[i + 1, j + 0] + error * MagicNumbers.Down); if (j < height && i < width) temp[i + 1, j + 1] = Normalize(temp[i + 1, j + 1] + error * MagicNumbers.DownRight); if (j > 0 && i < width) temp[i + 1, j - 1] = Normalize(temp[i + 1, j - 1] + error * MagicNumbers.DownLeft); } return temp; }
public PgmImg ReduceColors(PgmImg pgm) { var temp = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) for (int j = 0; j < pgm.Height; j++) temp[i, j] = Reduce(pgm[i, j], pgm.ReduceTo); /* // outra forma - mais lenta var newColorArray = new int[pgm.ReduceTo]; for (int i = 0; i < pgm.ReduceTo ; i++) newColorArray[i] = i * (255 / (pgm.ReduceTo-1)); for (int i = 0; i < matrix.GetLength(0); i++) for (int j = 0; j < matrix.GetLength(1); j++) temp[i, j] = (byte)Closest((int)matrix[i, j], newColorArray); */ return temp; }
public PgmImg MirrorY(PgmImg pgm) { var temp = pgm.Clone(); for (int i = 0; i < pgm.Width; i++) for (int j = 0; j < pgm.Height; j++) temp[i, j] = pgm[i, pgm.Height - 1 - j]; return temp; }