Time for action – cloning the seagull

In this example, we will demonstrate how we can perform image blending without actually preprocessing the two input images. Let's start:

  1. As always, our first step is to import the two images in MATLAB. As already mentioned, we will use the two images that do not need preprocessing, named seagull1.jpg and seagull2.jpg:
    >> A = imread('seagull1.jpg'),
    >> B = imread('seagull2.jpg'),
  2. Now that we have loaded our images, we can display them next to each other, to see if they fit our purpose:
    >> figure,imshowpair(A,B,'montage');
    Time for action – cloning the seagull
  3. It is apparent that the images are quite suitable for our purposes. They have almost identical backgrounds and the seagull is at a different part of the image in each picture. So, we can give it a go, by asking MATLAB to blend the two images:
    >> imshowpair(A,B,'blend');
    Time for action – cloning the seagull
  4. Let's now say that we want to achieve a more psychedelic result, with pseudo colored elements. Well, I have good news for you! MATLAB provides this without requiring any complex preprocessing steps. All you have to do, is to omit the 'blend' input and let MATLAB use the default choice ('falsecolor'), which is to show the two images overlaid in different color bands:
    >> imshowpair(A,B);
    Time for action – cloning the seagull
  5. If we prefer to alter the predefined colors used in the previous step, we can also alter them. This is done via the 'ColorChannel' input. This input can assign the default ('green-magenta') choice, the 'red-cyan' choice, or any arbitrary choice that can be generated using a [R G B] vector. Let's try the 'red-cyan' choice:
    >> imshowpair(A,B,'ColorChannel','red-cyan'),
    Time for action – cloning the seagull
  6. Now that we have a rough idea of what we are doing, let's save our last result into a new image, which we will call 'RedCyanSeagulls.jpg':
    >> C = imfuse(A,B,'ColorChannel','red-cyan'),
    >> imwrite(C,'RedCyanSeagulls.jpg'),

What just happened?

With this example, you have started to get a grasp on some of the powers of MATLAB that are really easy to use. The only thing that we really did was to pick two pictures with the same size, very similar backgrounds, and non-overlapping (or to be more precise, minimally overlapping) objects in them and blend them using several ready-made choices of the function pair imshowpair-imfuse. Once we were happy with the result, we saved it in a new JPEG file using imwrite.

Note

Note that the predefined 'green-magenta' and 'red-cyan' choices for the color channels can also be accomplished using the [R G B] triplets. The first one is [2 1 2], meaning that red and blue (magenta) were used for the second image and green was used for the first image. The second one is [1 2 2], meaning that green and blue (cyan) were used for the second image, while red was used for the first image. It's time for you to try out some of this now, so that you create a work of art with four different versions of the seagull composite picture.

Have a go hero – playing Warhol with your pictures

In this exercise, you should try to create four different false-color composite versions of the seagull pictures. Try whichever combinations of [R G B] that you wish and then concatenate the four images in order to make a large 2x2 grid that contains all of them.

Using the functions imread, imfuse, flipdim, and cat, you should be able to make a picture that looks like the following screenshot:

Have a go hero – playing Warhol with your pictures

This was not exactly difficult, right? Of course, your choices in tweaking the result are almost unlimited, since only your imagination can dictate what choices you would like to make in designing a work of art. You are free to try other choices of inputs, as well as applying various filters on your results to see what happens.

In this exercise, you created a quite interesting visual result using just two plain images. Playing with the falsecolor method setting and different mixtures of the three color channels, led to four different variations of the blended image. Flipping two of the images along the vertical axis led to a more symmetrical outcome. You could experiment with other kinds of transformations, such as rotation, to further customize your resulting image.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset