开发者

image interpolation

开发者 https://www.devze.com 2023-01-28 08:16 出处:网络
hi in my project i want to give some number of still images in those images i should take shuffling images as input but the out put will cme like sequential images it can compare the nearest neighbor

hi in my project i want to give some number of still images in those images i should take shuffling images as input but the out put will cme like sequential images it can compare the nearest neighbor by using interpolation methods how can i implement that plz tell me .i have some code tell me how it 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)
    {
      Mess开发者_JAVA百科ageBox.Show(this, "Incorrect values are entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}


Start with nearest neighbor interpolation -- it's the simplest. Basically, the approach works like this:

  • Allocate memory for your new image (unless it's already been done for you, obviously)
  • Iterate over all the pixels of your new image. You can do this in any way you want, but the most common way is called a "scanline traversal" or "raster scan" -- you read across columns first, and when you get to the last column, you move down a row and go back to the first column.
    • At each pixel position (row, col), work out the corresponding position (row_o, col_o) in the old image. For example, if the old image is half the size, then row_o = row/2 and col_o = col/2. Note that since all the pixel positions are integers, there will be some rounding involved. With nearest neighbor interpolation, it's a necessary evil and you can't avoid it.
    • Grab the pixel value at position (row_o, col_o) in the old image
    • Assign this value to the new image at position (row, col)

Once you get that out of the way, the other approaches should make more sense.

Scanline traversal:

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

What it looks like:

image interpolation

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号