====== Poisson Image Editing ====== 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. {{:courses:b4m33dzo:labs:05_poisson_image_cloning.jpg?400|}} The theory behind the labs can be found in the lectures: * [[https://dcgi.fel.cvut.cz/home/sykorad/dzo/slides/dzo-l06.pdf|L6 - Image Editing]] Start by downloading the [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/dzo2022_05_poisson_student.zip|template]] of the assignment. Use ''poisson.m'' to check your solution. ===== Computing image gradients, their merge, and divergence ===== **1a:** Implement a function that for a given image computes its gradients (**''calc_grad.m''**) - **0.5 points** * Use convolution with simple 1D finite differences kernels 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''**) - **0.5 points** * 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''**) - **0.5 points** * 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''**) - **0.5 points** * 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''**) - **0.5 points** * During the computation try to avoid a situation where the output divergence is shifted by one pixel. Compare your results to the reference: * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_mona_Gx.jpg|Image gradients in X direction]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_mona_Gy.jpg|Image gradients in Y direction]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_car_mask.jpg|Gradinent selection mask]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_intensity.jpg|Cloned image using intensity domain]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_Gx.jpg|Merged gradients in X direction]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_Gy.jpg|Merged gradients in Y direction]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_divG.jpg|Divergence of merged gradients]] ===== Solving Poisson equation iteratively using Gauss-Seidel method ===== **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''**) - **2.5 points** * Try to perform all computations implicitly without the need to build the linear system explicitly. * Try to provide good initialization, set sufficient number iterations, and resolve boundary conditions. * Try to reduce the number of equations to pixels for which the value is not known (use the given mask and/or bounding box). Compare your results to the reference: * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_gradient_gs.jpg|Cloned image using gradient domain (Gauss-Seidel)]] ===== Solving Poisson equation directly using Fourier transform ===== **3:** Implement a function that solves Poisson equation by deconvolution in the frequency domain (**''solve_FT.m''**) - **4 points** * Compute frequency domain version of the discreet Laplace operator. * Use Wiener filtration to avoid division by zero during deconvolution. * Try to normalize the output to have similar colors and contrast as the original images. Compare your results to the reference: * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_gradient_ft.jpg|Cloned image using gradient domain (Fourier transform)]] ===== Testing the resulting implementation ===== **4a:** Do image cloning using images and mask in the data folder (''mona_lisa.png'', ''ginevra_benci.png'', ''mona_mask.png'') - **0.5 points** * Merge the images ''mona_lisa.png'' and ''ginevra_benci.png'' using ''merge_image.m'' function to see the discrepancy. * Compute gradients of images ''mona_lisa.png'' and ''ginevra_benci.png'' using ''calc_grad.m''. * Merge the gradients using ''merge_grad.m'' and compute the divergence using ''calc_div.m''. * Solve Poisson equation using ''solve_GS.m'' and ''solve_FT.m''. * Compare output quality and processing speed. **4b:** Do image fusion to simulate HDR photo using images in the data folder (''car_low.png'' and ''car_high.png'') - **0.5 points** * Compute gradients for images ''car_low.png'' and ''car_high.png'' using ''calc_grad.m''. * Compute 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 ''solve_FT.m''. Compare your results to the reference: * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_intensity.jpg|Cloned image using intensity domain]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_gradient_gs.jpg|Cloned image using gradient domain (Gauss-Seidel)]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_cloned_gradient_ft.jpg|Cloned image using gradient domain (Fourier transform)]] * [[https://cw.fel.cvut.cz/wiki/_media/courses/b4m33dzo/labs/05_poisson_merged_gradient_ft.jpg|Merged image using gradient domain (Fourier transform)]] When you are done, upload the complete zip archive containing your implemented files to BRUTE: * ''calc_grad.m'' * ''get_mask.m'' * ''merge_image.m'' * ''merge_grad.m'' * ''calc_div.m'' * ''solve_GS.m'' * ''solve_FT.m'' * ''poisson.m'' as well as your final output images generated in tasks 4a and 4b. 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.