Image processing (Zoom out algorithm)

Default featured post

In the last post, zoom in algorithm was discussed and simple example of it was also given. This post is about zoom out algorithm. Basically, zoom out algorithm task is opposite of zoom in, means that instead of increasing the size of the image (make the image bigger) which shows more details of the picture, it decreases the size and as a result details of the picture will be shown less in comparison with the original size of the picture.

In short the zoom out algorithm can be described as follow,

  1. Make an empty image file with the half size of the original image. For instance, if the current size of the picture is 400x400, the new image size should be 200x200.
  2. Read each pixel of the image file which is located in x and y, then write the pixel in x/2 and y/2 place
  3. Repeat step 2 for all pixel

As it is clear zoom out algorithm does the task exactly opposite of the zoom in algorithm. Firstly, the size of the destination image is half of the original picture and then four neighbors pixels will be read and instead just one pixel will be written in the file.

The sample code of the zoom out algorithm is like below,

private void zoomOut(PictureBox picImp) {
  y = new System.Drawing.Bitmap((x.Width) / 2, (x.Height) / 2);
  //temppic =  (System.Drawing.Bitmap) PictureBox1.Image;
  for (int i = 0; i <= x.Width - 3; i++) {
    for (int j = 0; j <= x.Height - 3; j++) {
      z = x.GetPixel(i, j);
      y.SetPixel(i / 2, j / 2, z);
    }

  }
  Message.setMessage(PicSave.savechange(picImp, y), "ZoomOut");
}

As mentioned before in earlier post most of the image processing share some characteristics and one is reading all pixels of the picture with using two loops (i,j).

In the next post I will discuss about negative algorithm.