2010-12-03 71 views
0

嗨在我的項目中,我想給這些圖像中的一些靜止圖像,我應該把洗牌圖像作爲輸入,但輸出會cme像連續圖像,它可以通過使用插值方法比較最近的鄰居我怎麼能實施那些PLZ告訴我。我有一些代碼告訴我它是如何wrks。圖像插值

public InterpolationMethod method = InterpolationMethod.Bilinear; 
    public int newWidth = 0; 
    public int newHeight = 0; 
    try { 
     this.newWidth = Math.Max(1, Math.Min(5000, int.Parse(widthBox.Text))); 
     this.newHeight = Math.Max(1, Math.Min(5000, int.Parse(heightBox.Text))); 
     this.method = (methodCombo.SelectedIndex == 0) 
     ? InterpolationMethod.NearestNeighbor 
     : (methodCombo.SelectedIndex == 1) 
      ? InterpolationMethod.Bilinear 
      : InterpolationMethod.Bicubic; 
     this.DialogResult = DialogResult.OK; 
     this.Close(); 
    } 
    catch (Exception) 
    { 
     MessageBox.Show(this, "Incorrect values are entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
    } 
} 

回答

0

從最近鄰插值開始 - 這是最簡單的。基本上,該方法是這樣的:

  • 分配內存爲新圖像(除非它已經完成了你,很明顯)
  • 遍歷您的新圖像的所有像素。你可以以任何你想要的方式來做到這一點,但最常見的方式被稱爲「掃描線遍歷」或「光柵掃描」 - 你首先讀取列,當你到達最後一列時,向下移動一行,回到第一列。
    • 在每個像素位置(row, col),計算舊圖像中對應的位置(row_o, col_o)。例如,如果舊圖像的大小是一半,則row_o = row/2col_o = col/2。請注意,由於所有像素位置都是整數,因此會有一些舍入。使用最近鄰插值,這是一個必要的罪惡,你無法避免它。
    • 搶在舊圖像
    • (row_o, col_o)位置的像素值在位置(row, col)

分配該值將新形象一旦你說出來的方式,其他的方法應更有意義

掃描線穿越:

for (i=0; i < image.height; ++i) 
for (j=0; j < image.width; ++j) 
{ 
    // Do stuff here 
} 

它看起來像:

alt text