Skip to content

Commit f0e3632

Browse files
committed
addressed issues raised in the PR
1 parent 1a7ed31 commit f0e3632

21 files changed

+98
-58
lines changed

modules/alphamat/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ if(NOT HAVE_EIGEN)
55
ocv_module_disable(alphamat)
66
endif()
77

8-
cmake_minimum_required (VERSION 3.0)
9-
project (myproject)
10-
set (CMAKE_CXX_STANDARD 11)
11-
128
ocv_define_module(alphamat opencv_core
139
opencv_imgproc
1410
)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
By downloading, copying, installing or using the software you agree to this
3+
license. If you do not agree to this license, do not download, install,
4+
copy or use the software.
5+
License Agreement
6+
For Open Source Computer Vision Library
7+
(3-clause BSD License)
8+
Copyright (C) 2013, OpenCV Foundation, all rights reserved.
9+
Third party copyrights are property of their respective owners.
10+
11+
Redistribution and use in source and binary forms, with or without modification,
12+
are permitted provided that the following conditions are met:
13+
14+
* Redistributions of source code must retain the above copyright notice,
15+
this list of conditions and the following disclaimer.
16+
17+
* Redistributions in binary form must reproduce the above copyright notice,
18+
this list of conditions and the following disclaimer in the documentation
19+
and/or other materials provided with the distribution.
20+
21+
* Neither the names of the copyright holders nor the names of the contributors
22+
may be used to endorse or promote products derived from this software
23+
without specific prior written permission.
24+
25+
This software is provided by the copyright holders and contributors "as is" and
26+
any express or implied warranties, including, but not limited to, the implied
27+
warranties of merchantability and fitness for a particular purpose are
28+
disclaimed. In no event shall copyright holders or contributors be liable for
29+
any direct, indirect, incidental, special, exemplary, or consequential damages
30+
(including, but not limited to, procurement of substitute goods or services;
31+
loss of use, data, or profits; or business interruption) however caused
32+
and on any theory of liability, whether in contract, strict liability,
33+
or tort (including negligence or otherwise) arising in any way out of
34+
the use of this software, even if advised of the possibility of such damage.
35+
*/
36+
37+
/** Information Flow algorithm implementaton for alphamatting */
38+
39+
#ifndef _OPENCV_ALPHAMAT_HPP_
40+
#define _OPENCV_ALPHAMAT_HPP_
41+
42+
/**
43+
* @defgroup alphamat Alpha Matting
44+
* This module is dedicated to compute alpha matting of images, given the input image and an input trimap.
45+
* The samples directory includes easy examples of how to use the module.
46+
*
47+
* 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.
48+
*
49+
* This module has been originally developed by Muskaan Kularia and Sunita Nayak as a project
50+
* for Google Summer of Code 2019 (GSoC 19).
51+
*
52+
*/
53+
54+
namespace cv{ namespace alphamat{
55+
56+
CV_EXPORTS_W void infoFlow(Mat& image, Mat& tmap, Mat& result);
57+
58+
}}
59+
#endif

modules/alphamat/include/opencv2/infoflow.hpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

modules/alphamat/samples/information_flow_matting.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
#include <iostream>
66
#include "opencv2/highgui.hpp"
7-
#include <opencv2/core/base.hpp>
8-
#include <opencv2/core/utility.hpp>
7+
#include <opencv2/core.hpp>
98
#include <opencv2/imgproc.hpp>
10-
#include <opencv2/infoflow.hpp>
9+
#include <opencv2/alphamat.hpp>
1110

1211
using namespace std;
1312
using namespace cv;
@@ -28,7 +27,7 @@ int main(int argc, char *argv[])
2827

2928
if (show_help)
3029
{
31-
printf("\nThis sample demonstrates Information Flow alpha matting\n"
30+
printf("\nThis sample demonstrates Information Flow Alpha Matting\n"
3231
"Call:\n"
3332
" %s -img=<string> -tri=<string> [-out=<string>]\n\n", argv[0]);
3433
return 0;
@@ -75,7 +74,6 @@ int main(int argc, char *argv[])
7574
imwrite(result_path, result);
7675
}
7776

78-
imshow("Result Matte", result);
7977
return 0;
8078

8179
}
-842 KB
Binary file not shown.
Loading
-677 KB
Binary file not shown.
Binary file not shown.
Loading
-3.66 KB
Binary file not shown.
32.7 KB
Loading
-6.12 KB
Binary file not shown.

modules/alphamat/src/nanoflann.hpp renamed to modules/alphamat/src/3rdparty/nanoflann.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include <vector>
6060

6161
/** Library version: 0xMmP (M=Major,m=minor,P=patch) */
62-
#define NANOFLANN_VERSION 0x130
62+
#define NANOFLANN_VERSION 0x132
6363

6464
// Avoid conflicting declaration of min/max macros in windows headers
6565
#if !defined(NOMINMAX) && \
@@ -469,7 +469,8 @@ struct SO2_Adaptor {
469469
/** Note: this assumes that input angles are already in the range [-pi,pi] */
470470
template <typename U, typename V>
471471
inline DistanceType accum_dist(const U a, const V b, const size_t) const {
472-
DistanceType result = DistanceType(), PI = pi_const<DistanceType>();
472+
DistanceType result = DistanceType();
473+
DistanceType PI = pi_const<DistanceType>();
473474
result = b - a;
474475
if (result > PI)
475476
result -= 2 * PI;

modules/alphamat/src/cm.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "cm.hpp"
1212

1313
namespace cv{
14-
namespace alphamat{
14+
namespace alphamat{
1515

1616
void generateFVectorCM(my_vector_of_vectors_t &samples, Mat &img)
1717
{
@@ -24,18 +24,17 @@ void generateFVectorCM(my_vector_of_vectors_t &samples, Mat &img)
2424

2525
int i, j;
2626

27-
for (i = 0; i < nRows; ++i)
28-
for (j = 0; j < nCols; ++j){
29-
samples[i*nCols+j].resize(dim);
30-
samples[i*nCols+j][0] = img.at<cv::Vec3b>(i, j)[0]/255.0;
31-
samples[i*nCols+j][1] = img.at<cv::Vec3b>(i, j)[1]/255.0;
32-
samples[i*nCols+j][2] = img.at<cv::Vec3b>(i, j)[2]/255.0;
33-
samples[i*nCols+j][3] = double(i)/nRows;
34-
samples[i*nCols+j][4] = double(j)/nCols;
35-
}
27+
for (i = 0; i < nRows; ++i)
28+
for (j = 0; j < nCols; ++j){
29+
samples[i*nCols+j].resize(dim);
30+
samples[i*nCols+j][0] = img.at<cv::Vec3b>(i, j)[0]/255.0;
31+
samples[i*nCols+j][1] = img.at<cv::Vec3b>(i, j)[1]/255.0;
32+
samples[i*nCols+j][2] = img.at<cv::Vec3b>(i, j)[2]/255.0;
33+
samples[i*nCols+j][3] = double(i)/nRows;
34+
samples[i*nCols+j][4] = double(j)/nCols;
35+
}
3636
}
3737

38-
3938
void kdtree_CM(Mat &img, my_vector_of_vectors_t& indm, my_vector_of_vectors_t& samples, std::unordered_set<int>& unk)
4039
{
4140
// Generate feature vectors for intra U:

modules/alphamat/src/infoflow.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
// of this distribution and at http://opencv.org/license.html.
44

55
#include "precomp.hpp"
6-
#include "opencv2/infoflow.hpp"
6+
#include "opencv2/alphamat.hpp"
77
#include <fstream>
8+
#include <Eigen/Sparse>
9+
10+
using namespace Eigen;
811

912
namespace cv{
1013
namespace alphamat{
1114

15+
void solve(SparseMatrix<double> Wcm,SparseMatrix<double> Wuu,SparseMatrix<double> Wl,SparseMatrix<double> Dcm,
16+
SparseMatrix<double> Duu,SparseMatrix<double> Dl, SparseMatrix<double> T, Mat& wf, Mat& alpha);
17+
1218
void solve(SparseMatrix<double> Wcm,SparseMatrix<double> Wuu,SparseMatrix<double> Wl,SparseMatrix<double> Dcm,
1319
SparseMatrix<double> Duu, SparseMatrix<double> Dl, SparseMatrix<double> T,
1420
Mat &wf, Mat &alpha){

modules/alphamat/src/precomp.hpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,26 @@
1010
#include <unordered_set>
1111
#include <set>
1212

13-
#include <opencv2/core/base.hpp>
14-
#include <opencv2/core/utility.hpp>
13+
#include <opencv2/core.hpp>
1514
#include <opencv2/imgproc.hpp>
1615

17-
#include "nanoflann.hpp"
18-
#include "KDTreeVectorOfVectorsAdaptor.h"
16+
#include "3rdparty/nanoflann.hpp"
17+
#include "3rdparty/KDTreeVectorOfVectorsAdaptor.h"
18+
19+
#ifdef HAVE_EIGEN
1920
#include <Eigen/Eigen>
2021
#include <opencv2/core/eigen.hpp>
22+
#include <Eigen/IterativeLinearSolvers>
23+
#endif
2124

2225
namespace cv{
23-
namespace alphamat{
24-
const int dim = 5; // dimension of feature vectors
25-
}
26+
namespace alphamat{
27+
const int dim = 5; // dimension of feature vectors
28+
}
2629
}
2730

2831
#include "intraU.hpp"
2932
#include "cm.hpp"
3033
#include "local_info.hpp"
31-
#include <Eigen/IterativeLinearSolvers>
3234

3335
#endif

modules/alphamat/tutorials/alphamat_tutorial.markdown

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ Alphamatting is the problem of extracting the foreground from an image. The extr
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: ![](images/net_input_image.jpg)
15-
Input Trimap: ![](images/net_trimap.jpg)
16-
Output alpha Matte: ![](images/net_result.jpg)
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)
1717

18-
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].
18+
This project is implementation of @cite aksoy2017designing . It required implementation of parts of other papers [2,3,4].
1919

2020
# Building
2121

2222
This module uses the Eigen package.
2323

24-
Build the sample code of the alphamat module using the following cmake command, followed by ```make``` command.
24+
Build the sample code of the alphamat module using the following cmake command, followed by `make` command.
2525
```
26-
cmake -DOPENCV_EXTRA_MODULES_PATH=<path to opencv_contrib modules> -Dopencv_alphamat=ON -DBUILD_EXAMPLES=ON ..
26+
cmake -DOPENCV_EXTRA_MODULES_PATH=<path to opencv_contrib modules> -DBUILD_EXAMPLES=ON ..
2727
2828
make
2929
```
Binary file not shown.
-60.5 KB
Binary file not shown.
-29.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)