|
| 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