pcbway




zoom image in matlab, matlab image zooming, bilinear interpolation in matlab, matlab bilinear interpolationHello friends, hope you all are fine and having fun with your lives. Today, I am going to share a simple tutorial on Image zooming with bilinear Interpolation in MATLAB. We have seen many software in which there’s an option of zooming an image. For example, if you have used paint or photoshop then you have seen that you can zoom your image quite easily by clicking a button. Today’s we are gonna do the same thing but in MATLAB and we will have a look at the code behind this feature.

Now, when we are zooming some image then in fact we are increasing the pixels of that image and in order to do that we have to fill those extra pixels with the color of their neighbor pixel. This thing is know as interpolation. There are many different techniques for interpolation and the one we are gonna use for this tutorial is known as Bilinear Interpolation. Bilinear interpolation is simple type of linear interpolation in which we simply apply interpolation formula on both the x and y axis. So, let’s have a brief overview of Bilinear Interpolation first and then we will move on to MATLAB implementation.

What is Bilinear Interpolation ?

  • As I explained earlier, Bilinear Interpolation is a simple interpolation technique in which we fill the gaps between pixels using the neighbor pixels.
  • For example, we have an unknown pixel in between four pixels, and let’s say the unknown pixel is f(x,y) and it is surrounded by four pixels which are:
    1. Q11 = (x1y1).
    2. Q12 = (x1y2).
    3. Q21 = (x2y1).
    4. Q22 = (x2y2).
  • All these four neighbor pixels are known , now by using Bilinear Interpolation we can find the values of this unknown pixel.
  • Now, first of all, we will move in the x direction only.
  • The formula used for Bilinear Interpolation for x factor is:

Image Zooming with Bilinear Interpolation in MATLAB

  • Now after calculating these x formulas, now we will move in y direction and the formulas are:

zoom image in matlab, matlab image zooming, bilinear interpolation in matlab, matlab bilinear interpolation

  • Now using these formulas we can quite easily find our unknown pixel f(x,y) using Bilinear interpolation. These formulas are taken from Wiki Page of Bilinear Interpolation and you can read more details about it there.
  • Now we have seen the Bilinear Interpolation so now let’s move and see How to do Image Zooming using this Bilinear interpolation in MATLAB.

Image Zooming with Bilinear Interpolation in MATLAB

  • You can download the complete code by clicking the below button but also read the post, as I have explained this code in this remaining post.

Download MATLAB Code for Image Zooming

  • In order to do image zooming with Bilinear Interpolation in MATLAB, first of all, what you need to do is to read an image file, which I have done using this simple formula:

  • So, in this above code, what we did is , we simply read the image file which I have named as TEP.jpg
  • After that I have converted this image file into int16 and then to uint8 and finally I get the size of this image file using size command.
  • After that I have applied a simple algorithm and have zoomed my image using below code:

  • Now in the above loop what we have done is we simply enhanced our image and named it as im1, I have used a variable fac, which is factor, its user defined like if you want to zoom image by 2 then factor will be 2.
  • Now we have enhanced our image, next thing we need to do is to apply the bilinear Interpolation on this complete image and we will get the result.
  • Here’s the complete code for Image Zooming with Bilinear Interpolation in MATLAB.

  • Now if you check in the Bilinear Interpolation code, we have applied the same equations which we have discussed in the above section.
  • The Image I have used for this code is as follows:

555 timer projects, 555 timer tutorials, 555 timer tutorial, 555 timer project, 555 timer circuits

  • Now in MATLAB window, I have given this command bilinear_zoom(2) , where fac = 2, so I am increasing my image by factor 2. So it will be zoomed by 2 times.
  • Its the image from my 555 Timer post but as I have posted it recently so this image was on my desktop thats why I used it. 😛
  • The result obtained is as follows:

zoom image in matlab, matlab image zooming, bilinear interpolation in matlab, matlab bilinear interpolation

  •  Now you can see the image has been zoomed and is now looking big and because of Bilinear Interpolation in MATLAB we haven’t lost the in between pixels.
  • Here’s a video for this tutorial, which will give you better idea of How to do Image Zooming with Bilinear Interpolation in MATLAB.

That’s all for today, I hope you have enjoyed this post. Will meet you guys in the next tutorials soon. Till then take care. 🙂

2 Comments

  1. what does this command do. How it is related with ur code if ((rem(i-1,fac)==0) && (rem(j-1,fac)==0) ?
    Why did you convert first to int16 and then to uint8?

Leave a Reply

Your email address will not be published. Required fields are marked *

Post comment