Merhaba arkadaşlar...
UYGULAMA 2: Flip
UYGULAMA 3: Transpose
Transpose : Matematikte özellikle de doğrusal cebirde (linear algebra) bir matrisin satır ve sütünlarının yer değiştirmesi anlamını taşır. Görüntülerde bir matris ifade ettiği için matematikteki transpozu resimlere uygulayabiliriz. Satırlar sütün, sütunlar satır olacağından resmin boyutu değişecektir.
Bu yazımda herhangi bir resmi istediğimiz bir açıda nasıl döndürebiliriz bunu anlatacağım. Aşağıdaki uygulamada daha iyi gözlem yapabilmek adına Trackbar kontrolü ile açıyı değiştirip resmin anlık nasıl döndüğünü göstermekteyim.
UYGULAMA 1: Rotate
UYGULAMA 1: Rotate
This file contains hidden or 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
public partial class MainForm : Form | |
{ | |
private Image<Gray, Byte> m_originalImage; | |
private static void fillSizeInfo(Label label, Mat m) | |
{ | |
label.Text = m.Width + "x" + m.Height; | |
} | |
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<Gray, 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 trackBar1_Scroll(object sender, EventArgs e) | |
{ | |
try | |
{ | |
var img = m_originalImage.Rotate(trackBar1.Value, new Gray(255)); | |
m_pictureBoxResult.Image = img.ToBitmap(); | |
m_labelResultSize.Text = img.Width + "x" + img.Height; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
label1.Text = trackBar1.Value.ToString() + " " + "derece"; | |
} | |
} |
UYGULAMA 2: Flip
This file contains hidden or 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
public partial class MainForm : Form | |
{ | |
private Image<Gray, Byte> m_originalImage; | |
private static void fillSizeInfo(Label label, Mat m) | |
{ | |
label.Text = m.Width + "x" + m.Height; | |
} | |
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<gray 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 MainForm_Load(object sender, EventArgs e) | |
{ | |
try | |
{ | |
Enum.GetValues(typeof(FlipType)).Cast<fliptype>().ToList().ForEach(ft => m_comboBoxFlipTypes.Items.Add(ft)); | |
m_comboBoxFlipTypes.SelectedIndex = 0; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
} | |
private void m_buttonResult_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
var img = m_originalImage.Flip((FlipType)m_comboBoxFlipTypes.SelectedItem); | |
m_pictureBoxResult.Image = img.ToBitmap(); | |
m_labelResultSize.Text = img.Width + "x" + img.Height; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
} | |
} |
UYGULAMA 3: Transpose
Transpose : Matematikte özellikle de doğrusal cebirde (linear algebra) bir matrisin satır ve sütünlarının yer değiştirmesi anlamını taşır. Görüntülerde bir matris ifade ettiği için matematikteki transpozu resimlere uygulayabiliriz. Satırlar sütün, sütunlar satır olacağından resmin boyutu değişecektir.
This file contains hidden or 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
public partial class MainForm : Form | |
{ | |
private Image<Gray, byte> m_originalImage; | |
private static void fillSizeInfo(Label label, Mat m) | |
{ | |
label.Text = m.Width + "x" + m.Height; | |
} | |
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<Gray, 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_buttonResult_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
Mat m = new Mat(); | |
CvInvoke.Transpose(m_originalImage, m); | |
var img = new Image<Gray, byte>(m.Bitmap); | |
m_pictureBoxResult.Image = img.ToBitmap(); | |
m_labelResultSize.Text = img.Width + "x" + img.Height; | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message); | |
} | |
} | |
} |