public static int[,] FindImageEnergy(EnergyFunctionBase energyFunction, out double avgEnergy, out Bitmap bmp) { energyFunction.ComputeEnergy(Width, Height, Pixels); bmp = ToImage(energyFunction.Energy); avgEnergy = energyFunction.AvgEnergy; return(energyFunction.Energy); }
public static void ResizeHeight(EnergyFunctionBase energyFunction, decimal heightDiff) { int[,] m; double avgEnergy; Bitmap bmp; Progress(0); if (heightDiff < 0) { var seamList = new List <int[]>(); Bitmap original = SeamCarving.ToImage(); m = SeamCarving.FindImageEnergy(energyFunction, out avgEnergy, out bmp); for (int i = 0; i < -heightDiff; i++) { Progress((int)((i * 100) / -heightDiff)); var seam = SeamCarving.FindSeamHorizontal(m); seamList.Add(seam); m = SeamCarving.RemoveHorizontalSeam(seam, m); m = SeamCarving.UpdateImageEnergyHorizontalSeam(energyFunction, m, seam, out avgEnergy, out bmp); } SeamCarving.LoadImage(new Bitmap(original)); m = SeamCarving.FindImageEnergy(energyFunction, out avgEnergy, out bmp); for (int i = 0; i < seamList.Count; i++) { var seam = seamList[i]; m = SeamCarving.AddHorizontalSeam(seam, m); for (int j = 1; j < seamList.Count; j++) { for (int k = 0; k < seam.Length; k++) { if (seam[k] <= seamList[j][k]) { seamList[j][k]++; } } } } } else { m = SeamCarving.FindImageEnergy(energyFunction, out avgEnergy, out bmp); for (int i = 0; i < heightDiff; i++) { Progress((int)((i * 100) / heightDiff)); var seam = SeamCarving.FindSeamHorizontal(m); m = SeamCarving.RemoveHorizontalSeam(seam, m); m = SeamCarving.UpdateImageEnergyHorizontalSeam(energyFunction, m, seam, out avgEnergy, out bmp); } } Progress(100); }
public static int[,] UpdateImageEnergyHorizontalSeam(EnergyFunctionBase energyFunction, int[,] m, int[] seam, out double avgEnergy, out Bitmap bmp) { energyFunction.Energy = m; energyFunction.UpdateEnergyHorizontalSeam(Width, Height, Pixels, seam); bmp = ToImage(energyFunction.Energy); avgEnergy = energyFunction.AvgEnergy; return(energyFunction.Energy); }