Merhaba arkdaşlar bu uygulamada resimlere transformların yani matematiksel dönüşümlerin nasıl uygulanacağını anlatmaya çalıştım. C# 'in Lambda ifadelerini kullanarak resimlere istediğimiz dönüşümleri uygulamaktayız. İstersek kendi dönüşümlerinizi de bu method sayesinde uygulayabilirsiniz.
using (Image img = m_originalImage.Convert().Convert(b => (float)Math.Sin(b * b / 255D)))
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
partial class MainForm : Form | |
{ | |
private Image<Bgr, Byte> m_originalImage; | |
private static void fillSizeInfo(Label label, Mat m) | |
{ | |
label.Text = m.Height + "x" + m.Width; | |
} | |
public MainForm() | |
{ | |
InitializeComponent(); | |
} | |
private void m_buttonOK_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
OpenFileDialog dlg = new OpenFileDialog(); | |
if (dlg.ShowDialog() != DialogResult.OK) | |
return; | |
m_originalImage = new Image<bgr, byte>(dlg.FileName); | |
m_pictureBoxOriginalImage.Image = m_originalImage.ToBitmap(); | |
fillSizeInfo(m_labelOriginalSize, m_originalImage.Mat); | |
} | |
catch (Exception ex) { | |
MessageBox.Show(ex.GetType().Name + " " + ex.Message); | |
} | |
} | |
private void m_buttonSineTransform_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
if (m_originalImage == null) | |
{ | |
MessageBox.Show("You must choose an image"); | |
return; | |
} | |
using (Image<gray, float> img = m_originalImage.Convert<gray, byte>().Convert<float>(b => (float)Math.Sin(b * b / 255D))) | |
//OpenCV kullanmış oluyoruz (Herhangi bir matematiksel algoritmalar uygulanabilir.) | |
{ | |
m_pictureBoxResult.Image = img.ToBitmap(); | |
fillSizeInfo(m_labelResultSize, img.Mat); | |
} | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.GetType().Name + " " + ex.Message); | |
} | |
} | |
} |