2010-12-03 67 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