Skip to content

Commit f7193c7

Browse files
committed
updated documentation with more results for alphamat module
1 parent b65b3cc commit f7193c7

File tree

9 files changed

+48
-20
lines changed

9 files changed

+48
-20
lines changed

modules/alphamat/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ endif()
66
ocv_define_module(alphamat
77
opencv_core
88
opencv_imgproc
9+
WRAP python
910
)

modules/alphamat/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ This project was part of the Google Summer of Code 2019.
77
***
88
Alphamatting is the problem of extracting the foreground from an image. Given the input of an image and its corresponding trimap, we try to extract the foreground from the background.
99

10-
This project is implementation of "[[Designing Effective Inter-Pixel Information Flow for Natural Image Matting](http://people.inf.ethz.ch/aksoyy/ifm/)]" by Yağız Aksoy, Tunç Ozan Aydın and Marc Pollefeys[1]. It required implementation of parts of other papers [2,3,4].
10+
This project is implementation of "[Designing Effective Inter-Pixel Information Flow for Natural Image Matting](https://www.researchgate.net/publication/318489370_Designing_Effective_Inter-Pixel_Information_Flow_for_Natural_Image_Matting)" by Yağız Aksoy, Tunç Ozan Aydın and Marc Pollefeys[1]. It required implementation of parts of other papers [2,3,4].
1111

1212

1313
## References
1414

15-
[1] Yagiz Aksoy, Tunc Ozan Aydin, Marc Pollefeys, "[Designing Effective Inter-Pixel Information Flow for Natural Image Matting](http://people.inf.ethz.ch/aksoyy/ifm/)", CVPR, 2017.
15+
[1] Yagiz Aksoy, Tunc Ozan Aydin, Marc Pollefeys, "[Designing Effective Inter-Pixel Information Flow for Natural Image Matting](https://www.researchgate.net/publication/318489370_Designing_Effective_Inter-Pixel_Information_Flow_for_Natural_Image_Matting)", CVPR, 2017.
1616

1717
[2] Roweis, Sam T., and Lawrence K. Saul. "[Nonlinear dimensionality reduction by locally linear embedding](https://science.sciencemag.org/content/290/5500/2323)" Science 290.5500 (2000): 2323-2326.
1818

modules/alphamat/include/opencv2/alphamat.hpp

+14-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@
99

1010
/**
1111
* @defgroup alphamat Alpha Matting
12-
* This module is dedicated to compute alpha matting of images, given the input image and an input trimap.
13-
* The samples directory includes easy examples of how to use the module.
12+
* Alpha matting is used to extract a foreground object with soft boundaries from a background image.
13+
*
14+
* This module is dedicated to computing alpha matte of objects in images from a given input image and a greyscale trimap image that contains information about the foreground, background and unknown pixels. The unknown pixels are assumed to be a combination of foreground and background pixels. The algorithm uses a combination of multiple carefully defined pixels affinities to estimate the opacity of the foreground pixels in the unkown region.
15+
*
16+
* The implementation is based on "Designing Effective Inter-Pixel Information Flow for Natural Image Matting" by Yağız Aksoy, Tunç Ozan Aydın and Marc Pollefeys, CVPR 2017.
17+
*
18+
* This module was developed by Muskaan Kularia and Sunita Nayak as a project
19+
* for Google Summer of Code 2019 (GSoC 19).
20+
*
1421
*/
1522

1623
namespace cv { namespace alphamat {
1724
//! @addtogroup alphamat
1825
//! @{
1926

2027
/**
21-
* The implementation is based on Designing Effective Inter-Pixel Information Flow for Natural Image Matting by Yağız Aksoy, Tunç Ozan Aydın and Marc Pollefeys, CVPR 2019.
28+
* @brief Compute alpha matte of an object in an image
29+
* @param image Input RGB image
30+
* @param tmap Input greyscale trimap image
31+
* @param result Output alpha matte image
2232
*
23-
* This module has been originally developed by Muskaan Kularia and Sunita Nayak as a project
24-
* for Google Summer of Code 2019 (GSoC 19).
33+
* The function infoFlow performs alpha matting on a RGB image using a greyscale trimap image, and outputs a greyscale alpha matte image. The output alpha matte can be used to softly extract the foreground object from a background image. Examples can be found in the samples directory.
2534
*
2635
*/
2736
CV_EXPORTS_W void infoFlow(InputArray image, InputArray tmap, OutputArray result);

modules/alphamat/samples/information_flow_matting.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
// It is subject to the license terms in the LICENSE file found in the top-level directory
33
// of this distribution and at http://opencv.org/license.html.
44

5+
// Include relevant headers
56
#include <iostream>
67
#include "opencv2/highgui.hpp"
78
#include <opencv2/core.hpp>
89
#include <opencv2/imgproc.hpp>
910
#include <opencv2/alphamat.hpp>
1011

12+
// Set namespaces
1113
using namespace std;
1214
using namespace cv;
1315
using namespace cv::alphamat;
1416

17+
// Set the usage parameter names
1518
const char* keys =
1619
"{img || input image name}"
1720
"{tri || input trimap image name}"
@@ -30,10 +33,12 @@ int main(int argc, char* argv[])
3033
return 0;
3134
}
3235

36+
// Read the paths to the input image, input trimap and the location of the output image.
3337
string img_path = parser.get<std::string>("img");
3438
string trimap_path = parser.get<std::string>("tri");
3539
string result_path = parser.get<std::string>("out");
3640

41+
// Make sure the user inputs paths to the input image and trimap
3742
if (!parser.check()
3843
|| img_path.empty() || trimap_path.empty())
3944
{
@@ -44,13 +49,15 @@ int main(int argc, char* argv[])
4449

4550
Mat image, tmap;
4651

47-
image = imread(img_path, IMREAD_COLOR); // Read the input image file
52+
// Read the input image
53+
image = imread(img_path, IMREAD_COLOR);
4854
if (image.empty())
4955
{
5056
printf("Cannot read image file: '%s'\n", img_path.c_str());
5157
return 1;
5258
}
5359

60+
// Read the trimap
5461
tmap = imread(trimap_path, IMREAD_GRAYSCALE);
5562
if (tmap.empty())
5663
{
@@ -59,16 +66,19 @@ int main(int argc, char* argv[])
5966
}
6067

6168
Mat result;
69+
// Perform information flow alpha matting
6270
infoFlow(image, tmap, result);
6371

6472
if (result_path.empty())
6573
{
74+
// Show the alpha matte if a result filepath is not provided.
6675
namedWindow("result alpha matte", WINDOW_NORMAL);
6776
imshow("result alpha matte", result);
6877
waitKey(0);
6978
}
7079
else
7180
{
81+
// Save the alphamatte
7282
imwrite(result_path, result);
7383
printf("Result saved: '%s'\n", result_path.c_str());
7484
}
Binary file not shown.
Loading

modules/alphamat/tutorials/alphamat_tutorial.markdown

+20-12
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ This project was part of Google Summer of Code 2019.
77

88
*Mentor:* Sunita Nayak
99

10-
Alphamatting is the problem of extracting the foreground from an image. The extracted foreground can be used for further operations like changing the background in an image.
10+
Alphamatting is the problem of extracting the foreground with soft boundaries from a background image. The extracted foreground can be used for further operations like changing the background in an image.
1111

1212
Given an input image and its corresponding trimap, we try to extract the foreground from the background. Following is an example:
1313

14-
Input Image: ![](samples/input_images/plant.jpg)
15-
Input Trimap: ![](samples/trimaps/plant.png)
16-
Output alpha Matte: ![](samples/output_mattes/plant_result.jpg)
14+
Input Image: ![](../samples/input_images/plant.jpg)
15+
Input image should be preferably a RGB image.
16+
Input Trimap: ![](../samples/trimaps/plant.png)
17+
The trimap image is a greyscale image that contains information about the foreground(white pixels), background(black pixels) and unknown(grey) pixels.
18+
Output alpha Matte: ![](../samples/output_mattes/plant_result.png)
19+
The computed alpha matte is saved as a greyscale image where the pixel values indicate the opacity of the extracted foreground object. These opacity values can be used to blend the foreground object into a diffferent backgound, as shown below:
20+
![](./images/plant_new_backgrounds.jpg)
1721

18-
This project is implementation of @cite aksoy2017designing . It required implementation of parts of other papers [2,3,4].
22+
Following are some more results.
23+
![](./images/matting_results.jpg)
24+
25+
The first column is input RGB image, the second column is input trimap, third column is the extracted alpha matte and the last two columns show the foreground object blended on new backgrounds.
26+
27+
This project is implementation of @cite aksoy2017designing . It also required implementation of parts of other papers [2,3,4].
1928

2029
# Building
2130

@@ -33,21 +42,20 @@ Please refer to OpenCV building tutorials for further details, if needed.
3342

3443
The built target can be tested as follows:
3544
```
36-
example_alphamat_information_flow_matting -img=<path to input image file> -tri=<path to the corresponding trimap> -out=<path to save output matte file>
45+
<path to your opencv build directory>/bin/example_alphamat_information_flow_matting -img=<path to input image file> -tri=<path to the corresponding trimap> -out=<path to save output matte file>
3746
```
3847
# Source Code of the sample
3948

4049
@includelineno alphamat/samples/information_flow_matting.cpp
4150

42-
4351
# References
4452

45-
[1] Yagiz Aksoy, Tunc Ozan Aydin, Marc Pollefeys, "[Designing Effective Inter-Pixel Information Flow for Natural Image Matting](http://people.inf.ethz.ch/aksoyy/ifm/)", CVPR, 2017.
53+
[1] Yagiz Aksoy, Tunc Ozan Aydin, Marc Pollefeys, [Designing Effective Inter-Pixel Information Flow for Natural Image Matting](https://www.researchgate.net/publication/318489370_Designing_Effective_Inter-Pixel_Information_Flow_for_Natural_Image_Matting), CVPR, 2017.
4654

47-
[2] Roweis, Sam T., and Lawrence K. Saul. "[Nonlinear dimensionality reduction by locally linear embedding](https://science.sciencemag.org/content/290/5500/2323)" Science 290.5500 (2000): 2323-2326.
55+
[2] Roweis, Sam T., and Lawrence K. Saul. [Nonlinear dimensionality reduction by locally linear embedding](https://science.sciencemag.org/content/290/5500/2323), Science 290.5500 (2000): 2323-2326.
4856

49-
[3] Anat Levin, Dani Lischinski, Yair Weiss, "[A Closed Form Solution to Natural Image Matting](https://www.researchgate.net/publication/5764820_A_Closed-Form_Solution_to_Natural_Image_Matting)", IEEE TPAMI, 2008.
57+
[3] Anat Levin, Dani Lischinski, Yair Weiss, [A Closed Form Solution to Natural Image Matting](https://www.researchgate.net/publication/5764820_A_Closed-Form_Solution_to_Natural_Image_Matting), IEEE TPAMI, 2008.
5058

51-
[4] Qifeng Chen, Dingzeyu Li, Chi-Keung Tang, "[KNN Matting](http://dingzeyu.li/files/knn-matting-tpami.pdf)", IEEE TPAMI, 2013.
59+
[4] Qifeng Chen, Dingzeyu Li, Chi-Keung Tang, [KNN Matting](http://dingzeyu.li/files/knn-matting-tpami.pdf), IEEE TPAMI, 2013.
5260

53-
[5] Yagiz Aksoy, "[Affinity Based Matting Toolbox](https://github.com/yaksoy/AffinityBasedMattingToolbox)".
61+
[5] Yagiz Aksoy, [Affinity Based Matting Toolbox](https://github.com/yaksoy/AffinityBasedMattingToolbox).
263 KB
Loading
Loading

0 commit comments

Comments
 (0)