The two following labs deal with Poisson image editing, which can be used for image stitching, fusion, cloning, smoothing, context highlighting, color to gray conversion, and other applications.

The theory behind the labs can be found in the lectures:

Start by downloading the template of the assignment.

Use `test_FS.m`

and `test_HDR.m`

to check your solution.

**1a:** Implement a function that for a given image computes its gradients (** calc_grad.m**) -

- Use convolution with simple 1D finite differences kernels [1 -1] in X and Y direction.
- Make sure the gradients at image boundaries are set to zero.

**1b:** Implement a function that computes a mask preferring gradients with greater magnitude (** get_mask.m**): -

- In each pixel compare magnitudes of gradients in the first and in the second image. When the first image has greater magnitude store 0 in the mask otherwise store 255.

**1c:** Implement a function that merges two images according to a given mask (** merge_image.m**): -

- In each pixel if the mask has value 0 the output color is taken from the pixel of the first image otherwise the pixel color in the second image is used.

**1d:** Implement a function that merges two input gradient fields according to a given mask (** merge_grad.m**): -

- In each pixel if the mask has value 0 the output gradient vector is taken from the first image otherwise the gradient computed in the second image is used.

**1e:** Implement a function that computes divergence of a given gradient field (** calc_div.m**): -

- During the computation try to avoid a situation where the output divergence is shifted by one pixel.

**2:** Implement a function that solves Poisson equation by discretizing it into a system of linear equations which is solved iteratively using Gauss-Seidel method (** solve_GS.m**) -

- Perform all computations implicitly without the need to build the linear system explicitly.
- Provide good initialization, set sufficient number iterations, and resolve boundary conditions.
- Use nested for cycles (x and y coordinate and color channel) and 3D addressing I(x,y,c) to enable parallel processing.

**3:** Implement a function that solves Poisson equation by deconvolution in the frequency domain (** solve_FT.m**) -

- Compute frequency domain version of the discreet Laplace operator [0 1 0; 1 -4 1; 0 1 0].
- Use Wiener filtration to avoid division by zero during deconvolution.

**4a:** Implement a function that matches a brightness level of an input image to match a brightness level of a reference image (** match_colors.m**): -

- For each color channel (within a masked region) compute a global shift vector by averaging pixel differences between the input image and the reference image.
- For each color channel in the entire input image shift all pixel values so that (within a masked region) the brightness level is comparable to the brightness level of the reference image.

**4b:** Implement a function that normalizes color channels of an input image (** normalize_colors.m**) -

- Compute minimum and maximum value of each color channel.
- Shift and scale pixel values in the entire input image so that each color channel fits into an interval of <0,1>.

**5a:** Run `test_FS.m`

to check your solution on Face Swap application:

- Load images
`mona_lisa.png`

,`ginevra_benci.png`

, and a mask`mona_mask.png`

. - Compute their gradients using
`calc_grad.m`

. - Merge the gradients using
`merge_grad.m`

and compute the divergence using`calc_div.m`

. - Merge the images directly in the intensity domain using
`merge_image.m`

to see the discrepancy. - Solve Poisson equation using Gauss-Seidel
`solve_GS.m`

and Fourier transform`solve_FT.m`

. - Match colors of the Fourier transform solution using
`match_colors.m`

.

Compare your results to the reference:

**5b:** Run `test_HDR.m`

to check your solution on HDR Image Fusion application:

- Load images
`car_low.png`

and`car_high.png`

. - Compute their gradients using
`calc_grad.m`

. - Compute gradient merging mask using
`get_mask.m`

. - Merge the gradients using
`merge_grad.m`

and compute the divergence using`calc_div.m`

. - Solve Poisson equation using Fourier transform
`solve_FT.m`

. - Normalize colors of the Fourier transform solution using
`normalize_colors.m`

.

Compare your results to the reference:

When you are done, upload the complete zip archive containing your implemented files to BRUTE:

`calc_div.m`

`calc_grad.m`

`get_mask.m`

`match_colors.m`

`merge_grad.m`

`merge_image.m`

`normalize_colors.m`

`solve_FT.m`

`solve_GS.m`

Keep the files in the root of the zip archive (zip directly the files, NOT a folder containing the files). The evaluation system searches for the files just in the root of zip archive.

The points will be assigned manually by TA after the deadline.

courses/b4m33dzo/labs/5_poisson.txt · Last modified: 2023/04/11 11:02 by sykorad