Ask Computer Engineering Expert

E27: Computer Vision Spring 2016 - PROJECT 2

PROJECT - LAPLACIAN PYRAMIDS AND IMAGE BLENDING

OVERVIEW

In this project, you will investigate two applications: Laplacian pyramid blending and hybrid images. You can use the former to make smooth transitions between arbitrary images, such as the fish sandwich depicted in Figure 1. The latter can be used to generate interesting optical illusions as seen in Figure 4.

1685_Figure.png

LAPLACIAN PYRAMID BLENDING

1. First, generate a Laplacian pyramid.

A Laplacian pyramid (see section 3.5.3 of the Szeliski textbook) encodes an image as a succession of progressively smaller Laplacian images, built atop a base layer consisting of a blurred and reduced copy of the original image. Given an input image I, we can construct a Laplacian pyramid P = (L0, L1, L2, . . . ,LN) of depth N + 1 according to the following rules:

  • Define G0 to be the input image itself, so G0 = I.
  • Given Gi, obtain Gi+1 by convolving Gi with a small Gaussian, and then discarding the odd-numbered rows and columns of the image, to obtain a half-sized result.
  • Given Gi+1, produce Gi+1 by enlarging Gi+1 to be the same size as Gi while smoothing the result.
  • For any i < N, define Li = Gi - Gi+1
  • Finally, let LN = GN

588_Figure1.png

When constructing the Laplacian pyramid, please keep the following tips in mind:

  • Creating Gi+1 from Gi may be accomplished via the cv2.pyrDown function.
  • Creating Gi+1 from Gi+1 may be accomplished via the cv2.pyrUp function. You will almost certainly want to supply the dstsize parameter so that Gi+1 and Gi have the same shape.
  • Be careful not to directly subtract two numpy.uint8 images - the result will certainly overflow. Instead, convert images to numpy.float32 datatype before subtracting.
  • When displaying floating-point images via cv2.imshow, OpenCV expects the intensities to vary between 0.0 and 1.0. Therefore, a reasonable method to display a floating-point Laplacian image (e.g. for debugging purposes) might be something like:

cv2.imshow(window, 0.5 + 0.5*(L / numpy.abs(L).max()))

Write a function pyr_build(img) which takes an 8-bit per channel RGB or grayscale image as input, and which outputs a list lp of Laplacian images (stored in numpy.float32 format) corresponding to the image's Laplacian pyramid. Your code should produce results similar to Figure 2.

2. Reconstruct an image from a Laplacian pyramid

Surprisingly, no information is lost when converting from an original image to the corresponding Laplacian pyramid. You can reconstruct the original image from the Laplacian pyramid (L0, L1, . . . , LN) by following these steps:

  • Let RN = LN
  • Given Ri, let Ri-1 = RI + Li-1, where RI is an enlarged and smoothed version of Ri with the same dimensions as Li-1.
  • When you reach R0, the result should be virtually indistinguishable from the original image.

Keep in mind these practical implementation matters:

  • You can use the cv2.pyrUp function to create RI from Ri. Be careful to specify destination size as you did when building the pyramid.
  • You will want to assemble R as a numpy.float32 array, but convert to numpy.uint8 immediately prior to displaying. If you have any problems with overflow, you can use the numpy.clip function to restrict R to the range [0, 255] before type-converting.

Write a function pyr_reconstruct(lp) that reconstructs the original image from a Laplacian pyramid, and test it to verify that it works before proceeding to the next section.

3. Combine two Laplacian pyramids.

Given two original images imgA and imgB, it is possible to combine their corresponding Laplacian pyramids lpA and lpB in such a way that low-frequency features (such as solid color areas) are blended over a large distance, while high-frequency features (such as fine lines, ripples or edges) are blended over much shorter distences.

One good way to combine images is with a continuously-varying mask, sometimes called an alpha mask. Let alpha be a 2D floating-point array with pixel intensities in the range [0.0, 1.0], and assume that it has the same height and width as two images A and B. Then you can use this alpha_blend function to combine the images:

def alpha_blend(A, B, alpha):

A = A.astype(alpha.dtype)

B = B.astype(alpha.dtype)

# if A and B are RGB images, we must pad

# out alpha to be the right shape

if len(A.shape) == 3:

alpha = numpy.expand_dims(alpha, 2)

return A + alpha*(B-A)

At each level of the Laplacian pyramid, resize the original alpha mask (which had the same dimensions as imgA and imgB) to the size of each of the Laplacian images using cv2.resize with interpolation mode cv2.INTER_AREA. Then, use the resized alpha mask to blend the pair of Laplacian images at that level. The result is shown in Figure 3.

Your task is to photograph (or obtain) a pair of images to blend together, and write a program to generate an alpha mask and perform Laplacian pyramid blending between the two images. One reasonable way of generating an alpha mask with OpenCV is to draw a geometric shape (i.e. using cv2.ellipse) and the smooth the resulting image using cv2.GaussianBlur. Your program should use the pyr_build and pyr_reconstruct functions you have already written.

362_Figure2.png

In addition to submitting your program and the Laplacian-pyramid-blended output, you should also submit the "traditional" result of directly alpha-blending the two input images, without the pyramid. Hopefully, the pyramid result looks much more convincing than the traditional result.

HYBRID IMAGE

Moving on from Laplacian pyramids, a related concept is the hybrid image illusion, as shown in Figure 4. A hybrid image I can be created from two images A and B according to the formula

I = kA · lopass(A, σA) + kB · hipass(B, σB)

Here, the lopass(X, σ) function implements a low-pass filter on the image X by blurring it with a Gaussian kernel with standard deviation σ, and hipass implements a high-pass filter according to

hipass(X, σ) = X - lopass(X, σ)

Typically σA > σB, and setting both kA and kB to 1 is a reasonable place to start.

Your task here is to obtain a pair of images A and B, and write a program to merge them into a hybrid image. As with the Laplacian pyramid code, you will probably want to work in numpy.float32 as an intermediate format, and be careful about overflow when converting from floating-point back to numpy.uint8 format. Please submit source code, source images, and output hybrid image.

WRITEUP

Please create a 2-4 PDF writeup addressing the following questions:

  • Who did what for this project?
  • How did you obtain and align your images for each of the two tasks? Did you use any thirdparty software (e.g. Paintbrush, Photoshop), or write a program to help prepare the images or mask?
  • What depth did you choose to build your Laplacian pyramid to, and why?
  • Why does Laplacian pyramid blending blend low-frequency content over a larger distance than high-frequency content? See if you can illustrate this with some carefully chosen input image examples.
  • How did you arrive at good values for the constants σA, σB, kA, and kB for the hybrid image generation? Describe the process.
  • If you display your hybrid image at full size on your computer screen, how close do you need to be in order to primarly see image B? How far away do you need to get before you only see features from image A? Are these distances fairly consistent between you, your lab partner, and any unsuspecting friends you show your image to?
  • What does the Laplacian pyramid of your hybrid image look like?

Please include your source images/masks, and program outputs as figures, along with whatever other images you think will be useful/informative.

EVALUATION CRITERIA

Your project will be evaluated by the following criteria (percentages are approximate):

a. source code, raw data, and output - Turn in the full source code for your project, including any additional files needed to run it. You should also submit the program outputs as image files. I expect your code to be neatly indented and reasonably commented. Please expect to spend plenty of time photographing/obtaining and aligning suitable input images for both main tasks above - it is critical to have reasonably well aligned inputs, especially for the second task!

b. Laplacian pyramid results - The results of your Laplacian pyramid blending should be free of sharp seams, and be clearly superior to traditional alpha blending.

c. hybrid image results  - Your image should clearly transition from image A to image B as the viewer approaches from far away.

d. going further - Go above and beyond the tasks outlined above. Examples might include writing a helper program to align input images and/or generate masks; adapting either one of the above techniques to work on video (live or pre-recorded); visualizing intermediate computations/results of the above tasks; researching and discussing other uses of pyramid representations in computer vision, etc. Feel free to ask if you want to run any ideas by me!

e. written report - Your PDF report should address all of the questions mentioned above, and contain the relevant images as figures.

1449_Figure3.png

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M91845173

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As