Skip to content

Commit 9ca4edb

Browse files
Implemented Radon transform.
1 parent 600905e commit 9ca4edb

File tree

8 files changed

+691
-9
lines changed

8 files changed

+691
-9
lines changed

modules/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ $ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -D BUILD_opencv_re
4646

4747
19. **opencv_xfeatures2d**: Extra 2D Features Framework containing experimental and non-free 2D feature algorithms.
4848

49-
20. **opencv_ximgproc**: Extended Image Processing: Structured Forests / Domain Transform Filter / Guided Filter / Adaptive Manifold Filter / Joint Bilateral Filter / Superpixels.
49+
20. **opencv_ximgproc**: Extended Image Processing: Structured Forests / Domain Transform Filter / Guided Filter / Adaptive Manifold Filter / Joint Bilateral Filter / Superpixels / Radon transform.
5050

5151
21. **opencv_xobjdetect**: Integral Channel Features Detector Framework.
5252

modules/ximgproc/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
Extended Image Processing
22
=========================
33

4-
1. Structured Forests
4+
1. Structured Forests
55
2. Domain Transform Filter
66
3. Guided Filter
77
4. Adaptive Manifold Filter
88
5. Joint Bilateral Filter
99
6. Superpixels
1010
7. Graph segmentation
1111
8. Selective search from segmentation
12+
9. Radon Transform

modules/ximgproc/doc/ximgproc.bib

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ @inproceedings{zhang2014100+
165165
pages={2830--2837},
166166
year={2014},
167167
organization={IEEE}
168+
169+
@phdthesis{7910dc8d5b654c90ac4bc94c67d06f01,
170+
title = "The Radon Transform - Theory and Implementation",
171+
author = "Toft, {Peter Aundal} and Sørensen, {John Aasted}",
172+
year = "1996",
173+
month = "11",
174+
publisher = "Technical University of Denmark (DTU)",
168175
}

modules/ximgproc/include/opencv2/ximgproc.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
* By downloading, copying, installing or using the software you agree to this license.
33
* If you do not agree to this license, do not download, install,
44
* copy or use the software.
5-
*
6-
*
5+
*
6+
*
77
* License Agreement
88
* For Open Source Computer Vision Library
99
* (3 - clause BSD License)
10-
*
10+
*
1111
* Redistribution and use in source and binary forms, with or without modification,
1212
* are permitted provided that the following conditions are met :
13-
*
13+
*
1414
* *Redistributions of source code must retain the above copyright notice,
1515
* this list of conditions and the following disclaimer.
16-
*
16+
*
1717
* * Redistributions in binary form must reproduce the above copyright notice,
1818
* this list of conditions and the following disclaimer in the documentation
1919
* and / or other materials provided with the distribution.
20-
*
20+
*
2121
* * Neither the names of the copyright holders nor the names of the contributors
2222
* may be used to endorse or promote products derived from this software
2323
* without specific prior written permission.
24-
*
24+
*
2525
* This software is provided by the copyright holders and contributors "as is" and
2626
* any express or implied warranties, including, but not limited to, the implied
2727
* warranties of merchantability and fitness for a particular purpose are disclaimed.
@@ -48,6 +48,7 @@
4848
#include "ximgproc/weighted_median_filter.hpp"
4949
#include "ximgproc/slic.hpp"
5050
#include "ximgproc/lsc.hpp"
51+
#include "ximgproc/radon_transform.hpp"
5152

5253
/** @defgroup ximgproc Extended Image Processing
5354
@{
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/****************************************************************************************
2+
* By downloading, copying, installing or using the software you agree to this license. *
3+
* If you do not agree to this license, do not download, install, *
4+
* copy or use the software. *
5+
* *
6+
* *
7+
* License Agreement *
8+
* For Open Source Computer Vision Library *
9+
* (3-clause BSD License) *
10+
* *
11+
* Copyright (C) 2000-2016, Intel Corporation, all rights reserved. *
12+
* Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. *
13+
* Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved. *
14+
* Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. *
15+
* Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved. *
16+
* Copyright (C) 2015-2016, Itseez Inc., all rights reserved. *
17+
* Third party copyrights are property of their respective owners. *
18+
* *
19+
* Redistribution and use in source and binary forms, with or without modification, *
20+
* are permitted provided that the following conditions are met: *
21+
* *
22+
* Redistributions of source code must retain the above copyright notice, *
23+
* this list of conditions and the following disclaimer. *
24+
* *
25+
* Redistributions in binary form must reproduce the above copyright notice, *
26+
* this list of conditions and the following disclaimer in the documentation *
27+
* and/or other materials provided with the distribution. *
28+
* *
29+
* Neither the names of the copyright holders nor the names of the contributors *
30+
* may be used to endorse or promote products derived from this software *
31+
* without specific prior written permission. *
32+
* *
33+
* This software is provided by the copyright holders and contributors "as is" and *
34+
* any express or implied warranties, including, but not limited to, the implied *
35+
* warranties of merchantability and fitness for a particular purpose are disclaimed. *
36+
* In no event shall copyright holders or contributors be liable for any direct, *
37+
* indirect, incidental, special, exemplary, or consequential damages *
38+
* (including, but not limited to, procurement of substitute goods or services; *
39+
* loss of use, data, or profits; or business interruption) however caused *
40+
* and on any theory of liability, whether in contract, strict liability, *
41+
* or tort (including negligence or otherwise) arising in any way out of *
42+
* the use of this software, even if advised of the possibility of such damage. *
43+
****************************************************************************************/
44+
45+
/**
46+
* @author {aravind | [email protected]}
47+
* Created on Sun, Feb 14 2016
48+
*/
49+
50+
/**
51+
* Implementation of "The Radon Transform - Theory and Implementation"
52+
* by "Toft, {Peter Aundal} and Sørensen, {John Aasted}"
53+
*
54+
* Online publication: http://petertoft.dk/PhD/
55+
*
56+
*/
57+
58+
#ifndef __OPENCV_RADON_TRANSFORM_HPP__
59+
#define __OPENCV_RADON_TRANSFORM_HPP__
60+
#ifdef __cplusplus
61+
62+
#include "opencv2/core.hpp"
63+
64+
namespace cv {
65+
namespace ximgproc {
66+
67+
/**
68+
* Flags for range of angles
69+
* AR_x_y : theta lies in [x, y] ( both x and y inclusive )
70+
*/
71+
72+
enum RadonAngleRange { AR_1_45 = 1,
73+
AR_46_89 = 2,
74+
AR_90 = 4,
75+
AR_91_135 = 8,
76+
AR_136_179 = 16,
77+
AR_180 = 32
78+
};
79+
80+
/**
81+
* Specifies binary operations
82+
* The enum specifies four binary operations,
83+
* viz. Minimum, Maximum, Average and sum
84+
* of the Radon transformed images.
85+
*/
86+
87+
enum RadonOp { RT_MIN = 1,
88+
RT_MAX = 2,
89+
RT_AVE = 4,
90+
RT_SUM = 8
91+
};
92+
93+
/**
94+
* [radonTransform Computes the Radon transform of the given image]
95+
* @param src [Input source image]
96+
* @param dst [Output image]
97+
* @param angleRange [One of the enums, RadonAngleRange, defaults to 63 ( 1 to 180 degrees)]
98+
* @param operation [One of the enums, RadonOp, defaults to RT_SUM ( SUM OPERATION )]
99+
* @param opDst [Output image of the operation perfomed, defaults to noArray()]
100+
*/
101+
CV_EXPORTS void radonTransform( InputArray src,
102+
OutputArray dst,
103+
int angleRange = 63,
104+
int operation = RT_SUM,
105+
OutputArray opDst = noArray()
106+
);
107+
}
108+
}
109+
110+
#endif // __cplusplus
111+
#endif // __OPENCV_RADON_TRANSFORM_HPP__
5.38 KB
Loading
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/****************************************************************************************
2+
* By downloading, copying, installing or using the software you agree to this license. *
3+
* If you do not agree to this license, do not download, install, *
4+
* copy or use the software. *
5+
* *
6+
* *
7+
* License Agreement *
8+
* For Open Source Computer Vision Library *
9+
* (3-clause BSD License) *
10+
* *
11+
* Copyright (C) 2000-2016, Intel Corporation, all rights reserved. *
12+
* Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. *
13+
* Copyright (C) 2009-2016, NVIDIA Corporation, all rights reserved. *
14+
* Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved. *
15+
* Copyright (C) 2015-2016, OpenCV Foundation, all rights reserved. *
16+
* Copyright (C) 2015-2016, Itseez Inc., all rights reserved. *
17+
* Third party copyrights are property of their respective owners. *
18+
* *
19+
* Redistribution and use in source and binary forms, with or without modification, *
20+
* are permitted provided that the following conditions are met: *
21+
* *
22+
* Redistributions of source code must retain the above copyright notice, *
23+
* this list of conditions and the following disclaimer. *
24+
* *
25+
* Redistributions in binary form must reproduce the above copyright notice, *
26+
* this list of conditions and the following disclaimer in the documentation *
27+
* and/or other materials provided with the distribution. *
28+
* *
29+
* Neither the names of the copyright holders nor the names of the contributors *
30+
* may be used to endorse or promote products derived from this software *
31+
* without specific prior written permission. *
32+
* *
33+
* This software is provided by the copyright holders and contributors "as is" and *
34+
* any express or implied warranties, including, but not limited to, the implied *
35+
* warranties of merchantability and fitness for a particular purpose are disclaimed. *
36+
* In no event shall copyright holders or contributors be liable for any direct, *
37+
* indirect, incidental, special, exemplary, or consequential damages *
38+
* (including, but not limited to, procurement of substitute goods or services; *
39+
* loss of use, data, or profits; or business interruption) however caused *
40+
* and on any theory of liability, whether in contract, strict liability, *
41+
* or tort (including negligence or otherwise) arising in any way out of *
42+
* the use of this software, even if advised of the possibility of such damage. *
43+
****************************************************************************************/
44+
45+
/**
46+
* @author {aravind | [email protected]}
47+
* Created on Mon, Feb 15 2016
48+
*/
49+
50+
/**
51+
*
52+
* C++ Sample program for Radon transform
53+
*
54+
*/
55+
56+
// Necessary headers
57+
#include <math.h>
58+
#include <stdlib.h>
59+
#include <string>
60+
#include <iostream>
61+
62+
#include <opencv2/imgproc.hpp>
63+
#include <opencv2/highgui.hpp>
64+
#include <opencv2/core/utility.hpp>
65+
66+
#include <opencv2/ximgproc.hpp>
67+
68+
using namespace cv::ximgproc;
69+
using namespace cv;
70+
using namespace std;
71+
72+
static void help ( const char **argv ) {
73+
std::cout << std::endl \
74+
<< "This program demonstrates the usage of Radon transform." \
75+
<< std::endl << std::endl << "USAGE: " << std::endl \
76+
<< argv[0] << " <filename> <angle-range-option> <operation>" \
77+
<< std::endl << std::endl;
78+
79+
std::cout << "Default for <angle-range-option> computes for " \
80+
<< "all angles between 1 and 180 degrees." \
81+
<< " ( @see cv::ximgproc::RadonAngleRange )" << std::endl \
82+
<< "Default for <operation> is RT_SUM." \
83+
<< " ( @see cv::ximgproc::RadonOp )" << std::endl \
84+
<< std::endl; \
85+
86+
}
87+
88+
static bool argParser( int argc, const char **argv,
89+
cv::Mat & img,
90+
int & radonAngleRange,
91+
int & radonOperation ) {
92+
if (argc > 4) {
93+
std::cout << "Incorrect arguments" << std::endl;
94+
return false;
95+
}
96+
97+
const char *filename = argc >= 2 ? argv[1]
98+
: "./radon_input.jpg";
99+
img = imread(filename, 0);
100+
if( img.empty() ) {
101+
std::cout << "Unable to load image: " << filename << std::endl;
102+
return false;
103+
}
104+
105+
radonAngleRange = ( argc >= 3 ) ? atoi(argv[2]) : 63; // 1 to 180 degrees
106+
radonOperation = ( argc >= 4 ) ? atoi(argv[3]) : RT_SUM; // Sum up elements
107+
108+
return true;
109+
}
110+
111+
int main( int argc, const char ** argv ) {
112+
113+
cv::Mat img;
114+
int radonAngleRange, radonOperation;
115+
116+
// Display help
117+
help( argv );
118+
119+
if( !argParser( argc, argv, img, radonAngleRange, radonOperation) ) {
120+
return -1;
121+
}
122+
123+
cv::Mat radonTr, operImg;
124+
125+
// Computing the Radon transform with appropriate params
126+
radonTransform( img, radonTr, radonAngleRange, radonOperation, operImg );
127+
128+
// Mat for displaying the Radon transform
129+
cv::Mat radonTrDisp;
130+
131+
double minVal, maxVal;
132+
minMaxLoc(radonTr, &minVal, &maxVal);
133+
134+
// Normalizing radonTr so as to display as a CV_8U image
135+
radonTr -= minVal;
136+
radonTr.convertTo( radonTrDisp, CV_8U, 255.0/(maxVal-minVal) );
137+
138+
// Normalizing operImg so as to display as a CV_8U image
139+
minMaxLoc(operImg, &minVal, &maxVal);
140+
operImg -= minVal;
141+
operImg.convertTo(operImg, CV_8U, 255.0/(maxVal-minVal));
142+
143+
// Displaying the images
144+
cv::imshow("Input", img);
145+
cv::imshow("Radon transform", radonTrDisp);
146+
cv::imshow("Operation(image)", operImg);
147+
148+
cv::waitKey(0);
149+
cv::destroyAllWindows();
150+
151+
return 0;
152+
}

0 commit comments

Comments
 (0)