private void GenerateCrop(GeneratorElementConfig config) { Console.WriteLine("from: " + config.InputFileName() + "\nto: " + config.OutputFileName() + "\nmethod: " + config.MethodName); var image = Image.FromFile(config.InputFilePath); Image res = SeamCarving.CropImage(image, config.ToWidth, config.ToHeight); res.Save(config.OutputFilePath(), getImageFormat(config.FileExtension())); }
private void BW_DoWork(object sender, DoWorkEventArgs e) { SeamCarving.TempMatrix = ImageMatrix; BackgroundWorker worker = sender as BackgroundWorker; stopWatch.Start(); dispatcherTimer.Start(); resizedImage = SeamCarving.Resize(ImageMatrix, newHeight, newWidth, worker); ImageMatrix = resizedImage; stopWatch.Stop(); }
static void Main(string[] args) { var show_help = false; var inputPath = ""; var outputPath = ""; var heightRate = 0.5; var widthRate = 0.5; var p = new OptionSet() { { "i|input=", "specific the input image.", v => { inputPath = v; } }, { "o|output=", "specific the output image.", v => { outputPath = v; } }, { "height", "specific the decreasing rate of height.\n" + "(0.0~1.0, default: 0.5)", (double v) => { heightRate = v; } }, { "width", "specific the decreasing rate of width.\n" + "(0.0~1.0, default: 0.5)", (double v) => { widthRate = v; } }, { "h|?|help", "show help message.", v => { show_help = v != null; } }, }; List <string> extra; try { extra = p.Parse(args); if (show_help) { ShowHelp(p); return; } var bm = new Bitmap(inputPath, true); var sc = new SeamCarving(bm, Convert.ToInt32(bm.Height * heightRate), Convert.ToInt32(bm.Width * widthRate)); var bo = sc.Carve(); bo.Save(outputPath); } catch (Exception e) { Console.Write("SeamCarving: "); Console.WriteLine(e.Message); Console.WriteLine("Try 'SeamCarving --help' for more information."); return; } // var bm = new Bitmap(@"/Users/xrc/Repository/AlgorithmHW/SeamCarving/example3.jpg",true); // var sc = new SeamCarving(bm,bm.Height/2,bm.Width/2); // var bo = sc.Carve(); // bo.Save(@"/Users/xrc/Repository/AlgorithmHW/SeamCarving/er3.jpg"); }
static void Main(string[] args) { var seamCarving = new SeamCarving(); using (var imageBitmap = new Bitmap(@"..\..\..\..\images\t001.png")) using (var removeBitmap = new Bitmap(@"..\..\..\..\images\m001.png")) { var result = seamCarving.Remove(imageBitmap, removeBitmap); result .SaveTo("..\\..\\..\\out2.png", ImageFormat.Png) .ShowFile(); } }
private void GenerateSeamCarving(GeneratorElementConfig config) { Console.WriteLine("from: " + config.InputFileName() + "\nto: " + config.OutputFileName() + "\nmethod: " + config.MethodName); var image = Image.FromFile(config.InputFilePath); SeamCarving.LoadImage(new Bitmap(image)); EnergyFunctionBase energyFunction = GetEnergyFunction(config.MethodName); if (config.ChangeWidth) { SeamCarving.ResizeWidth(energyFunction, image.Size.Width - config.ToWidth); } else { SeamCarving.ResizeHeight(energyFunction, image.Size.Height - config.ToHeight); } Image res = SeamCarving.ToImage(); res.Save(config.OutputFilePath(), getImageFormat(config.FileExtension())); }
public void Carve() { this.undoRedo.PushToUndoStack((Bitmap)this.model.Image.Clone()); this.undoRedo.ClearRedoStack(); new Thread(() => { for (int i = 0; i < this.filterParam; i++) { SeamCarving s = new SeamCarving(this.model.Image); s.Prepare(); this.model.Image = s.GetCarvedBitmap(); this.view.Image = this.model.Image; this.view.RedrawImageOnlyInvoker(); } this.view.RedrawInvoker(); }).Start(); }
//MOZNA DODAC WARTOSC SREDNIA ENERGII W OBRAZIE I POKAZAC ZE Z USUWANIE SEAMOW SIE PODNOSI private void LoadButton_Click(object sender, EventArgs e) { var result = OpenFileDialog.ShowDialog(); if (result != DialogResult.OK) { return; } if (_imageForm != null) { _imageForm.Close(); } _imageForm = new ImageForm(this); var image = Image.FromFile(OpenFileDialog.FileName); _imageFileName = OpenFileDialog.SafeFileName; _imageForm.imageBox.Image = image; _imageForm.imageBox.Width = image.Width; _imageForm.imageBox.Height = image.Height; _imageForm.Show(); ImageHeightNumeric.Value = image.Height; ImageWidthNumeric.Value = image.Width; EnableImageControls(); //for testing //MemoryStream ms = new MemoryStream(); //image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); SeamCarving.LoadImage(new Bitmap(image)); double avgEnergy; Bitmap bmp; SeamCarving.FindImageEnergy(GetEnergyAlgorithm(), out avgEnergy, out bmp); AverageEnergyLabel.Text = avgEnergy.ToString("F2"); //_imageForm.imageBox.Image = bmp; }
private void SetHeightButton_Click(object sender, EventArgs e) { var heightDiff = _imageForm.imageBox.Height - ImageHeightNumeric.Value; var energyFunction = GetEnergyAlgorithm(); SeamCarving.ResizeHeight(energyFunction, heightDiff); var newBitmap = SeamCarving.ToImage(); Bitmap bmp; double avgEnergy; SeamCarving.FindImageEnergy(energyFunction, out avgEnergy, out bmp); AverageEnergyLabel.Text = avgEnergy.ToString("F2"); _imageForm.imageBox.Image = newBitmap; _imageForm.imageBox.Width = newBitmap.Width; _imageForm.imageBox.Height = newBitmap.Height; ImageHeightNumeric.Value = newBitmap.Height; ImageWidthNumeric.Value = newBitmap.Width; ProgressBar.Value = 100; }
public void GenerateEnergyMaps() { CreateOutputDirectory(); string[] files = GetFiles(); foreach (var f in files) { Image image = Image.FromFile(f); double energy; Bitmap bmp; string filename = Path.GetFileNameWithoutExtension(f); string fileExtension = Path.GetExtension(f); foreach (var ef in enerfyFunctions) { SeamCarving.LoadImage(new Bitmap(image)); SeamCarving.FindImageEnergy(GetEnergyFunction(ef), out energy, out bmp); bmp.Save(outputDirectory + "\\" + filename + "_" + ef + "_energyMap" + fileExtension); //int [,] m = SeamCarving.ResizeWidth(GetEnergyFunction(ef),50); //SeamCarving.LoadImage(bmp); //Image im2 = SeamCarving.ToImage(m); //im2.Save(outputDirectory + "\\" + filename + "_" + ef + "_test" + fileExtension); } } }