├── ApplySaliencyToSurfaceInspection.sdf ├── ApplySaliencyToSurfaceInspection.sln ├── ApplySaliencyToSurfaceInspection.v12.suo ├── ApplySaliencyToSurfaceInspection ├── 0.bmp ├── 00.bmp ├── 01.bmp ├── 2.jpg ├── 3.jpg ├── AC │ ├── AC.cpp │ └── AC.h ├── ApplySaliencyToSurfaceInspection.vcxproj ├── ApplySaliencyToSurfaceInspection.vcxproj.filters ├── ApplySaliencyToSurfaceInspection.vcxproj.user ├── BMS │ ├── BMS.cpp │ └── BMS.h ├── D101.png ├── DemoOfPaper22_Oilpullution.cpp ├── DemoRunDatasets.cpp ├── FT │ ├── FT.cpp │ └── FT.h ├── GMR │ ├── GMR.cpp │ ├── GMR.h │ ├── SLIC.cpp │ ├── SLIC.h │ └── main.cpp ├── HC │ ├── HC.cpp │ └── HC.h ├── LC │ ├── LC.cpp │ └── LC.h ├── MBP │ ├── MBP.cpp │ └── MBP.hpp ├── MSS │ ├── MSS.cpp │ └── MSS.h ├── McueSalTest.cpp ├── PHOT │ ├── PHOT.cpp │ └── PHOT.h ├── RC │ ├── RC.cpp │ ├── RC.h │ └── Segmentation │ │ ├── disjoint-set.h │ │ ├── segment-graph.h │ │ ├── segment-image.cpp │ │ └── segment-image.h ├── Rudinac │ ├── Rudinac.h │ └── saliencyDetectionRudinac.cpp ├── SF │ ├── SF.cpp │ ├── SF.h │ ├── fastmath.h │ ├── filter │ │ ├── filter.cpp │ │ ├── filter.h │ │ ├── permutohedral.cpp │ │ └── permutohedral.h │ ├── superpixel │ │ ├── CMakeLists.txt │ │ ├── superpixel.cpp │ │ └── superpixel.h │ └── test_superpixel.cpp ├── SR │ ├── SR.cpp │ └── SR.h ├── Scratch_6.bmp ├── Wipe_crack_1.bmp ├── apple.jpg ├── bird.jpg ├── exp4_num_32185.jpg ├── exp6_num_116623.jpg ├── image20.jpg ├── image36.jpg ├── itti │ ├── Itti.h │ ├── cvgabor.h │ ├── gabor.cpp │ └── itti.cpp ├── sample.bmp ├── tiger.jpg └── x64 │ └── Release │ ├── AC.obj │ ├── ApplySal.DCC3BB1D.tlog │ ├── ApplySaliencyToSurfaceInspection.lastbuildstate │ ├── CL.read.1.tlog │ ├── CL.write.1.tlog │ ├── cl.command.1.tlog │ ├── link.command.1.tlog │ ├── link.read.1.tlog │ └── link.write.1.tlog │ ├── ApplySaliencyToSurfaceInspection.Build.CppClean.log │ ├── ApplySaliencyToSurfaceInspection.log │ ├── BMS.obj │ ├── DemoRunDatasets.obj │ ├── FT.obj │ ├── GMR.obj │ ├── HC.obj │ ├── LC.obj │ ├── MBP.obj │ ├── MSS.obj │ ├── McueSalTest.obj │ ├── MyDemoOfSaliency.obj │ ├── PHOT.obj │ ├── RC.obj │ ├── SF.obj │ ├── SLIC.obj │ ├── SR.obj │ ├── demoBMS.obj │ ├── filter.obj │ ├── gabor.obj │ ├── itti.obj │ ├── permutohedral.obj │ ├── saliencyDetectionRudinac.obj │ ├── segment-image.obj │ ├── superpixel.obj │ └── vc120.pdb ├── README.md ├── opencv31vs2013x64r.props └── x64 └── Release ├── ApplySaliencyToSurfaceInspection.exe └── ApplySaliencyToSurfaceInspection.pdb /ApplySaliencyToSurfaceInspection.sdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection.sdf -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30723.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ApplySaliencyToSurfaceInspection", "ApplySaliencyToSurfaceInspection\ApplySaliencyToSurfaceInspection.vcxproj", "{DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Debug|x64 = Debug|x64 12 | Release|Win32 = Release|Win32 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Debug|Win32.ActiveCfg = Debug|Win32 17 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Debug|Win32.Build.0 = Debug|Win32 18 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Debug|x64.ActiveCfg = Debug|x64 19 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Debug|x64.Build.0 = Debug|x64 20 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Release|Win32.ActiveCfg = Release|x64 21 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Release|Win32.Build.0 = Release|x64 22 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Release|x64.ActiveCfg = Release|x64 23 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection.v12.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection.v12.suo -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/0.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/0.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/00.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/00.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/01.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/01.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/2.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/3.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/AC/AC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/AC/AC.cpp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/AC/AC.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | using namespace cv; 5 | class AC 6 | { 7 | public: 8 | AC() 9 | { 10 | } 11 | 12 | ~AC() 13 | { 14 | } 15 | 16 | public: 17 | void calculateSaliencyMap(Mat *src, Mat * dst) ; 18 | 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/ApplySaliencyToSurfaceInspection.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {DCC3BB1D-0905-4CC5-BDB1-CF5E3B49F179} 23 | Win32Proj 24 | ApplySaliencyToSurfaceInspection 25 | 26 | 27 | 28 | Application 29 | true 30 | v120 31 | Unicode 32 | 33 | 34 | Application 35 | true 36 | v120 37 | Unicode 38 | 39 | 40 | Application 41 | false 42 | v120 43 | true 44 | Unicode 45 | 46 | 47 | Application 48 | false 49 | v120 50 | true 51 | MultiByte 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | true 72 | 73 | 74 | true 75 | 76 | 77 | false 78 | 79 | 80 | true 81 | 82 | 83 | 84 | 85 | 86 | Level3 87 | Disabled 88 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 89 | true 90 | 91 | 92 | Console 93 | true 94 | 95 | 96 | 97 | 98 | 99 | 100 | Level3 101 | Disabled 102 | WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 103 | true 104 | 105 | 106 | Console 107 | true 108 | 109 | 110 | 111 | 112 | Level3 113 | 114 | 115 | MaxSpeed 116 | true 117 | true 118 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 119 | true 120 | 121 | 122 | Console 123 | true 124 | true 125 | true 126 | 127 | 128 | 129 | 130 | Level3 131 | 132 | 133 | MaxSpeed 134 | true 135 | true 136 | WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) 137 | true 138 | true 139 | true 140 | 141 | 142 | Console 143 | true 144 | true 145 | true 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/ApplySaliencyToSurfaceInspection.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 6 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {0d3243de-aed2-4d1d-adac-a0877e65436b} 14 | 15 | 16 | {d88d4990-bdb0-45f9-87c0-d556ba2fdce2} 17 | 18 | 19 | {e05a9b80-000e-4d53-9904-ec24899113a2} 20 | 21 | 22 | {e171dfae-22f6-4b34-8a2e-1c3bd7d54b51} 23 | 24 | 25 | {22d027a0-80d5-40be-bf44-fc7845ee8b3f} 26 | 27 | 28 | {6bd93fbb-a6e1-44ea-a25b-46a328919e14} 29 | 30 | 31 | {af0fc02b-0bbf-4532-adfd-fbb089a89451} 32 | 33 | 34 | {15823774-6ee4-4629-ba80-b90f299f7085} 35 | 36 | 37 | {68908230-dce9-426a-b167-0e31830b3f51} 38 | 39 | 40 | {e2c3cd06-5c31-4921-8844-9d0ad29b721a} 41 | 42 | 43 | {94b920d2-4dd4-4367-abaa-ec33a4ef45cf} 44 | 45 | 46 | {0f3accad-dae3-4b37-a127-b07709d1936c} 47 | 48 | 49 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 50 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 51 | 52 | 53 | {469924a1-fdf7-42ac-b2e8-2e5e12498cf0} 54 | 55 | 56 | {f2edea44-06b5-4d0c-a869-c459a37d6096} 57 | 58 | 59 | {31e72514-045c-4f73-a46d-2a2987cdaded} 60 | 61 | 62 | 63 | 64 | AllClasses\itti 65 | 66 | 67 | AllClasses\itti 68 | 69 | 70 | AllClasses\Rudinac 71 | 72 | 73 | AllClasses\SR 74 | 75 | 76 | AllClasses\GMR 77 | 78 | 79 | AllClasses\GMR 80 | 81 | 82 | AllClasses\FT 83 | 84 | 85 | AllClasses\LC 86 | 87 | 88 | AllClasses\HC 89 | 90 | 91 | AllClasses\RC 92 | 93 | 94 | AllClasses\RC\Segmentation 95 | 96 | 97 | AllClasses\MBP 98 | 99 | 100 | AllClasses\AC 101 | 102 | 103 | AllClasses\MSS 104 | 105 | 106 | AllClasses\PHOT 107 | 108 | 109 | AllClasses\BMS 110 | 111 | 112 | AllClasses\SF 113 | 114 | 115 | AllClasses\SF 116 | 117 | 118 | AllClasses\SF 119 | 120 | 121 | AllClasses\SF 122 | 123 | 124 | Demo 125 | 126 | 127 | 128 | 129 | AllClasses\itti 130 | 131 | 132 | AllClasses\itti 133 | 134 | 135 | AllClasses\SR 136 | 137 | 138 | AllClasses\Rudinac 139 | 140 | 141 | AllClasses\GMR 142 | 143 | 144 | AllClasses\GMR 145 | 146 | 147 | AllClasses\FT 148 | 149 | 150 | AllClasses\LC 151 | 152 | 153 | AllClasses\HC 154 | 155 | 156 | AllClasses\RC 157 | 158 | 159 | AllClasses\RC\Segmentation 160 | 161 | 162 | AllClasses\RC\Segmentation 163 | 164 | 165 | AllClasses\RC\Segmentation 166 | 167 | 168 | AllClasses\MBP 169 | 170 | 171 | AllClasses\AC 172 | 173 | 174 | AllClasses\MSS 175 | 176 | 177 | AllClasses\PHOT 178 | 179 | 180 | AllClasses\BMS 181 | 182 | 183 | AllClasses\SF 184 | 185 | 186 | AllClasses\SF 187 | 188 | 189 | AllClasses\SF 190 | 191 | 192 | AllClasses\SF 193 | 194 | 195 | AllClasses\SF 196 | 197 | 198 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/ApplySaliencyToSurfaceInspection.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/BMS/BMS.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Implemetation of the saliency detction method described in paper 3 | * "Exploit Surroundedness for Saliency Detection: A Boolean Map Approach", 4 | * Jianming Zhang, Stan Sclaroff, submitted to PAMI, 2014 5 | * 6 | * Copyright (C) 2014 Jianming Zhang 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | * If you have problems about this software, please contact: jmzhang@bu.edu 22 | *******************************************************************************/ 23 | 24 | #include "BMS.h" 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | using namespace cv; 31 | using namespace std; 32 | 33 | #define COV_MAT_REG 50.0f 34 | 35 | 36 | void BMS::BMSinit(const Mat& src, int dw1, bool nm, bool hb, int colorSpace, bool whitening) 37 | 38 | { 39 | mDilationWidth_1=dw1; 40 | mNormalize=nm; 41 | mHandleBorder=hb; 42 | mAttMapCount=0; 43 | mColorSpace=colorSpace; 44 | mWhitening=whitening; 45 | mSrc = src.clone(); 46 | mSaliencyMap = Mat::zeros(src.size(), CV_32FC1); 47 | mBorderPriorMap = Mat::zeros(src.size(), CV_32FC1); 48 | 49 | if (CL_RGB & colorSpace) 50 | whitenFeatMap(mSrc, COV_MAT_REG); 51 | if (CL_Lab & colorSpace) 52 | { 53 | Mat lab; 54 | cvtColor(mSrc, lab, CV_RGB2Lab); 55 | whitenFeatMap(lab, COV_MAT_REG); 56 | } 57 | if (CL_Luv & colorSpace) 58 | { 59 | Mat luv; 60 | cvtColor(mSrc, luv, CV_RGB2Luv); 61 | whitenFeatMap(luv, COV_MAT_REG); 62 | } 63 | } 64 | 65 | 66 | // calculateSaliencyMap(Mat *src, Mat * dst, int sample_step = 8,int dw1 = 7, bool nm = 1, bool hb = 0, int colorSpace = 2, bool whitening = 1, float max_dimension = -1); 67 | void BMS::calculateSaliencyMap(cv::Mat *src, cv::Mat * dst, int sample_step, int dw1, bool nm, bool hb, int colorSpace, bool whitening, float max_dimension) 68 | { 69 | 70 | BMS bms; 71 | bms.BMSinit(*src, dw1, nm, hb, colorSpace, whitening); 72 | bms.computeSaliency((double)sample_step); 73 | *dst = bms.getSaliencyMap(); 74 | 75 | } 76 | void BMS::computeSaliency(double step) 77 | { 78 | for (int i=0;ithresh; 86 | Mat am = getAttentionMap(bm, mDilationWidth_1, mNormalize, mHandleBorder); 87 | mSaliencyMap += am; 88 | mAttMapCount++; 89 | } 90 | } 91 | } 92 | 93 | 94 | cv::Mat BMS::getAttentionMap(const cv::Mat& bm, int dilation_width_1, bool toNormalize, bool handle_border) 95 | { 96 | Mat ret=bm.clone(); 97 | int jump; 98 | if (handle_border) 99 | { 100 | for (int i=0;i0.99 ? BMS_RNG.uniform(5,25):0; 103 | if (ret.at(i,0+jump)!=1) 104 | floodFill(ret,Point(0+jump,i),Scalar(1),0,Scalar(0),Scalar(0),8); 105 | jump = BMS_RNG.uniform(0.0,1.0)>0.99 ?BMS_RNG.uniform(5,25):0; 106 | if (ret.at(i,bm.cols-1-jump)!=1) 107 | floodFill(ret,Point(bm.cols-1-jump,i),Scalar(1),0,Scalar(0),Scalar(0),8); 108 | } 109 | for (int j=0;j0.99 ? BMS_RNG.uniform(5,25):0; 112 | if (ret.at(0+jump,j)!=1) 113 | floodFill(ret,Point(j,0+jump),Scalar(1),0,Scalar(0),Scalar(0),8); 114 | jump= BMS_RNG.uniform(0.0,1.0)>0.99 ? BMS_RNG.uniform(5,25):0; 115 | if (ret.at(bm.rows-1-jump,j)!=1) 116 | floodFill(ret,Point(j,bm.rows-1-jump),Scalar(1),0,Scalar(0),Scalar(0),8); 117 | } 118 | } 119 | else 120 | { 121 | for (int i=0;i(i,0)!=1) 124 | floodFill(ret,Point(0,i),Scalar(1),0,Scalar(0),Scalar(0),8); 125 | if (ret.at(i,bm.cols-1)!=1) 126 | floodFill(ret,Point(bm.cols-1,i),Scalar(1),0,Scalar(0),Scalar(0),8); 127 | } 128 | for (int j=0;j(0,j)!=1) 131 | floodFill(ret,Point(j,0),Scalar(1),0,Scalar(0),Scalar(0),8); 132 | if (ret.at(bm.rows-1,j)!=1) 133 | floodFill(ret,Point(j,bm.rows-1),Scalar(1),0,Scalar(0),Scalar(0),8); 134 | } 135 | } 136 | 137 | ret = ret != 1; 138 | 139 | Mat map1, map2; 140 | map1 = ret & bm; 141 | map2 = ret & (~bm); 142 | 143 | if (dilation_width_1 > 0) 144 | { 145 | dilate(map1, map1, Mat(), Point(-1, -1), dilation_width_1); 146 | dilate(map2, map2, Mat(), Point(-1, -1), dilation_width_1); 147 | } 148 | 149 | map1.convertTo(map1,CV_32FC1); 150 | map2.convertTo(map2,CV_32FC1); 151 | 152 | if (toNormalize) 153 | { 154 | normalize(map1, map1, 1.0, 0.0, NORM_L2); 155 | normalize(map2, map2, 1.0, 0.0, NORM_L2); 156 | } 157 | else 158 | normalize(ret,ret,0.0,1.0,NORM_MINMAX); 159 | return map1+map2; 160 | } 161 | 162 | Mat BMS::getSaliencyMap() 163 | { 164 | Mat ret; 165 | normalize(mSaliencyMap, ret, 0.0, 255.0, NORM_MINMAX); 166 | ret.convertTo(ret,CV_8UC1); 167 | return ret; 168 | } 169 | 170 | void BMS::whitenFeatMap(const cv::Mat& img, float reg) 171 | { 172 | assert(img.channels() == 3 && img.type() == CV_8UC3); 173 | 174 | vector featureMaps; 175 | 176 | if (!mWhitening) 177 | { 178 | split(img, featureMaps); 179 | for (int i = 0; i < featureMaps.size(); i++) 180 | { 181 | normalize(featureMaps[i], featureMaps[i], 255.0, 0.0, NORM_MINMAX); 182 | medianBlur(featureMaps[i], featureMaps[i], 3); 183 | mFeatureMaps.push_back(featureMaps[i]); 184 | } 185 | return; 186 | } 187 | 188 | Mat srcF,meanF,covF; 189 | img.convertTo(srcF, CV_32FC3); 190 | Mat samples = srcF.reshape(1, img.rows*img.cols); 191 | calcCovarMatrix(samples, covF, meanF, CV_COVAR_NORMAL | CV_COVAR_ROWS | CV_COVAR_SCALE, CV_32F); 192 | 193 | covF += Mat::eye(covF.rows, covF.cols, CV_32FC1)*reg; 194 | SVD svd(covF); 195 | Mat sqrtW; 196 | sqrt(svd.w,sqrtW); 197 | Mat sqrtInvCovF = svd.u * Mat::diag(1.0/sqrtW); 198 | 199 | Mat whitenedSrc = srcF.reshape(1, img.rows*img.cols)*sqrtInvCovF; 200 | whitenedSrc = whitenedSrc.reshape(3, img.rows); 201 | 202 | split(whitenedSrc, featureMaps); 203 | 204 | for (int i = 0; i < featureMaps.size(); i++) 205 | { 206 | normalize(featureMaps[i], featureMaps[i], 255.0, 0.0, NORM_MINMAX); 207 | featureMaps[i].convertTo(featureMaps[i], CV_8U); 208 | medianBlur(featureMaps[i], featureMaps[i], 3); 209 | mFeatureMaps.push_back(featureMaps[i]); 210 | } 211 | } -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/BMS/BMS.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Implemetation of the saliency detction method described in paper 3 | * "Exploit Surroundedness for Saliency Detection: A Boolean Map Approach", 4 | * Jianming Zhang, Stan Sclaroff, submitted to PAMI, 2014 5 | * 6 | * Copyright (C) 2014 Jianming Zhang 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | * If you have problems about this software, please contact: jmzhang@bu.edu 22 | *******************************************************************************/ 23 | #define MAX_IMG_DIM 400 24 | #ifndef BMS_H 25 | #define BMS_H 26 | 27 | 28 | #ifdef IMDEBUG 29 | #include 30 | #endif 31 | #include 32 | #include 33 | #include 34 | 35 | static const int CL_RGB = 1; 36 | static const int CL_Lab = 2; 37 | static const int CL_Luv = 4; 38 | 39 | static cv::RNG BMS_RNG; 40 | 41 | class BMS 42 | { 43 | public: 44 | static void calculateSaliencyMap(cv::Mat *src, cv::Mat * dst, int sample_step = 3, int dw1 = 3, bool nm = 1, bool hb = 0, int colorSpace = 2, bool whitening = 1, float max_dimension = -1); 45 | public: 46 | void BMSinit (const cv::Mat& src, int dw1, bool nm, bool hb, int colorSpace, bool whitening); 47 | cv::Mat getSaliencyMap(); 48 | void computeSaliency(double step); 49 | private: 50 | cv::Mat mSaliencyMap; 51 | int mAttMapCount; 52 | cv::Mat mBorderPriorMap; 53 | cv::Mat mSrc; 54 | std::vector mFeatureMaps; 55 | int mDilationWidth_1; 56 | bool mHandleBorder; 57 | bool mNormalize; 58 | bool mWhitening; 59 | int mColorSpace; 60 | cv::Mat getAttentionMap(const cv::Mat& bm, int dilation_width_1, bool toNormalize, bool handle_border); 61 | void whitenFeatMap(const cv::Mat& img, float reg); 62 | void computeBorderPriorMap(float reg, float marginRatio); 63 | }; 64 | 65 | void postProcessByRec8u(cv::Mat& salmap, int kernelWidth); 66 | void postProcessByRec(cv::Mat& salmap, int kernelWidth); 67 | 68 | 69 | 70 | #endif 71 | 72 | 73 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/D101.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/D101.png -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/DemoOfPaper22_Oilpullution.cpp: -------------------------------------------------------------------------------- 1 | 2 | /*This demo Reference to Song, K. C., Hu, S. P., Yan, Y. H., & Li, J. (2014). 3 | Surface defect detection method using saliency linear scanning morphology for silicon 4 | steel strip under oil pollution interference. Isij International, 54(11), 2598-2607. 5 | 6 | code by Yibin Huang 7 | */ 8 | //basice dependency 9 | #include "opencv2/core/core.hpp" 10 | #include "opencv2/core/utility.hpp" 11 | #include "opencv2/imgproc/imgproc.hpp" 12 | #include "opencv2/imgcodecs.hpp" 13 | #include "opencv2/highgui/highgui.hpp" 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | //Classes To include 22 | #include "itti/itti.h" 23 | #include "SR/SR.h" 24 | #include "Rudinac/Rudinac.h" 25 | #include"GMR/GMR.h" 26 | #include "FT/FT.h" 27 | #include "LC/LC.h" 28 | #include "HC/HC.h" 29 | #include "RC/RC.h" 30 | #include "MBP/MBP.hpp" 31 | #include "AC/AC.h" 32 | #include"MSS/MSS.h" 33 | #include"methodSun\Sun.h" 34 | #include"methodSun/EntropyFil.h" 35 | //extern Mat EntropyFiltFn(const Mat& image); 36 | 37 | 38 | Mat img; 39 | int th1 = 100, th2 = 30; 40 | int th3= 15; 41 | bool corlor = 0;//When this value is 1, it will be done on the corlor img as it is default 42 | //in fact I find that in this case gray scale maybe better than LAB space 43 | static void on_trackbar(int, void*) 44 | { 45 | 46 | //step 1 compute saliecy map 47 | Mat gray; 48 | cvtColor(img,gray,CV_RGB2GRAY); 49 | 50 | Mat Sal, SalCanny; 51 | double Time = (double)cvGetTickCount(); 52 | FT::calculateSaliencyMap(&gray, &Sal, corlor, 5); 53 | imshow("Fig5left", Sal); 54 | 55 | 56 | Mat Saluchar; 57 | Sal.convertTo(Saluchar, CV_8UC1, 255.0); 58 | Canny(Saluchar, SalCanny, th1, th2, 3); 59 | imshow("Fig6/a", SalCanny); 60 | int ksize = 2; 61 | Mat Kernel = getStructuringElement(MORPH_CROSS, 62 | Size(2 * ksize + 1, 2 * ksize + 1), 63 | Point(ksize, ksize)); //MORPH_ELLIPSE 64 | 65 | 66 | //step 2 filt the img 67 | 68 | Mat Salfilted; 69 | morphologyEx(Saluchar, Salfilted, MORPH_OPEN, Kernel); 70 | morphologyEx(Salfilted, Salfilted, MORPH_CLOSE, Kernel); 71 | imshow("Fig6/b", Salfilted); 72 | Canny(Salfilted, SalCanny, th1, th2, 3); 73 | imshow("Fig6/c", SalCanny); 74 | 75 | //step3 binarization 76 | Mat otus; 77 | threshold(Salfilted, otus, 0, 255, CV_THRESH_OTSU); 78 | imshow("Fig7/a otus", otus); 79 | Mat imbw = Salfilted > th3; 80 | imshow("Fig7/b", imbw); 81 | int maxValue = 255; 82 | int blockSize = 35; 83 | int constValue = 15; 84 | cv::Mat local; 85 | cv::adaptiveThreshold(Salfilted, local, maxValue, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY , blockSize, constValue); 86 | imshow("local adaptiveThrshold", local); 87 | 88 | //step 4 median blur; 89 | medianBlur(imbw, imbw, 29); 90 | imshow("Fig7/c blur", imbw); 91 | //step 5 fill the defect 92 | //transpose(imbw, imbw ); 93 | 94 | int step0 = imbw.step[0]; 95 | int step1 = imbw.step[1]; 96 | uchar *pbw = imbw.data; 97 | for (int k = 0; k < imbw.rows - 1; k += 1) 98 | { 99 | int lf = 10000, rt = 0; 100 | for (int j = 0; j < imbw.cols - 1; ++j) 101 | { 102 | if (pbw[k*step0 + j *step1] ) 103 | { 104 | if (j < lf) 105 | lf = j; 106 | else 107 | rt = j; 108 | 109 | } 110 | } 111 | for (int j = lf; j < rt; ++j) 112 | { 113 | pbw[k*step0 + j *step1] = 255; 114 | 115 | } 116 | } 117 | for (int k = 0; k < imbw.cols - 1; k += 1) 118 | { 119 | int lf = 10000, rt = 0; 120 | for (int j = 0; j < imbw.rows - 1; ++j) 121 | { 122 | if (pbw[j*step0 + k *step1] ) 123 | { 124 | if (j < lf) 125 | lf = j; 126 | else 127 | rt = j; 128 | 129 | } 130 | } 131 | for (int j = lf; j < rt; ++j) 132 | { 133 | pbw[j*step0 + k *step1] = 255; 134 | 135 | } 136 | } 137 | imshow("Fig 9,b",imbw); 138 | vector > contours; 139 | vector hierarchy; 140 | findContours(imbw, contours, hierarchy, CV_RETR_CCOMP, CV_CHAIN_APPROX_NONE); 141 | Time = (double)cvGetTickCount() - Time; 142 | Mat contoursImage(imbw.rows, imbw.cols, CV_8U, Scalar(0)); 143 | for (int i = 0; i inline T sqr(T x) { return x * x; } 3 | void FT::calculateSaliencyMap(Mat *src, Mat * dst, bool corlor,int ksize) 4 | { 5 | if (corlor && (*src).channels() == 3) //if do it on corlor domain 6 | { 7 | 8 | Mat img3f = (*src); 9 | 10 | img3f.convertTo(img3f, CV_32FC3, 1.0 / 255); 11 | Mat sal(img3f.size(), CV_32F), tImg; 12 | GaussianBlur(img3f, tImg, Size(ksize, ksize), 0); 13 | cvtColor(tImg, tImg, CV_BGR2Lab); 14 | Scalar colorM = mean(tImg); 15 | for (int r = 0; r < tImg.rows; r++) 16 | { 17 | float *s = sal.ptr(r); 18 | float *lab = tImg.ptr(r); 19 | for (int c = 0; c < tImg.cols; c++, lab += 3) 20 | s[c] = (float)(sqr(colorM[0] - lab[0]) + sqr(colorM[1] - lab[1]) + sqr(colorM[2] - lab[2])); 21 | } 22 | normalize(sal, *dst, 0, 1, NORM_MINMAX); 23 | } 24 | else 25 | { 26 | Mat imgf, tImg; 27 | imgf = *src; 28 | 29 | if (imgf.channels() == 3) 30 | { 31 | cvtColor(imgf, imgf, CV_RGB2GRAY); 32 | } 33 | imgf.convertTo(imgf, CV_32FC1, 1.0 / 255); 34 | Scalar colorM = mean(imgf); 35 | GaussianBlur(imgf, tImg, Size(ksize, ksize), 0); 36 | Mat sal(imgf.size(), CV_32F); 37 | for (int r = 0; r < tImg.rows; r++) 38 | { 39 | float *s = sal.ptr(r); 40 | float *gray = tImg.ptr(r); 41 | for (int c = 0; c < tImg.cols; c++) 42 | s[c] = (colorM[0] - gray[c])*(colorM[0] - gray[c]); 43 | } 44 | 45 | normalize(sal, *dst, 0, 1, NORM_MINMAX); 46 | } 47 | } -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/FT/FT.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | using namespace cv; 5 | class FT 6 | { 7 | public: 8 | FT() 9 | { 10 | } 11 | 12 | ~FT() 13 | { 14 | } 15 | 16 | public: 17 | static void calculateSaliencyMap(Mat *src, Mat * dst, bool corlor = 1,int ksize=3); 18 | 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/GMR/GMR.cpp: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | 3 | Copyright: Guangyu Zhong all rights reserved 4 | 5 | Author: Guangyu Zhong 6 | 7 | Date:2014-09-27 8 | 9 | Description: codes for Manifold Ranking Saliency Detection 10 | Reference http://ice.dlut.edu.cn/lu/Project/CVPR13[yangchuan]/cvprsaliency.htm 11 | 12 | **************************************************/ 13 | #include "GMR.h" 14 | using namespace std; 15 | typedef unsigned int UINT; 16 | 17 | GMR::GMR() 18 | { 19 | spNumMax = 200; 20 | compactness = 20.0; 21 | alpha = 0.99f; 22 | theta = 0.1f; 23 | spNum = 0; 24 | } 25 | GMR::~GMR() 26 | { 27 | } 28 | Mat GMR::GeneSp(const Mat &img) 29 | { 30 | int width = img.cols; 31 | int height = img.rows; 32 | int sz = width*height; 33 | UINT *reimg = new UINT[sz * 3]; 34 | for (int c = 0; c<3; c++) 35 | { 36 | for (int i = 0; i(img.at(j, i)[2 - c]); 41 | } 42 | } 43 | int* label = nullptr; 44 | SLIC slic; 45 | slic.DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels(reimg, height, width, label, spNum, spNumMax, compactness); 46 | Mat superpixels(img.size(), CV_16U); 47 | 48 | for (int i = 0; i(i, j) = label[i + j*superpixels.rows]; 53 | } 54 | } 55 | delete [] reimg; 56 | delete [] label; 57 | return superpixels; 58 | } 59 | 60 | Mat GMR::GeneAdjMat(const Mat &spmat) 61 | { 62 | int width = spmat.cols; 63 | int height = spmat.rows; 64 | Mat adjmat(Size(spmat.size()), CV_16U, Scalar(0)); 65 | for (int i = 0; i < height - 1; ++i) 66 | { 67 | for (int j = 0; j < width - 1; ++j) 68 | { 69 | if (spmat.at(i, j) != spmat.at(i + 1, j)) 70 | { 71 | adjmat.at(spmat.at(i, j), spmat.at(i + 1, j)) = 1; 72 | adjmat.at(spmat.at(i + 1, j), spmat.at(i, j)) = 1; 73 | } 74 | if (spmat.at(i, j) != spmat.at(i, j + 1)) 75 | { 76 | adjmat.at(spmat.at(i, j), spmat.at(i, j + 1)) = 1; 77 | adjmat.at(spmat.at(i, j + 1), spmat.at(i, j)) = 1; 78 | } 79 | if (spmat.at(i, j) != spmat.at(i + 1, j + 1)) 80 | { 81 | adjmat.at(spmat.at(i, j), spmat.at(i + 1, j + 1)) = 1; 82 | adjmat.at(spmat.at(i + 1, j + 1), spmat.at(i, j)) = 1; 83 | } 84 | if (spmat.at(i + 1, j) != spmat.at(i, j + 1)) 85 | { 86 | adjmat.at(spmat.at(i + 1, j), spmat.at(i, j + 1)) = 1; 87 | adjmat.at(spmat.at(i, j + 1), spmat.at(i + 1, j)) = 1; 88 | } 89 | } 90 | } 91 | return adjmat; 92 | } 93 | vector GMR::GeneBdQuery(const Mat &superpixels, const int type) 94 | { 95 | int height = superpixels.rows; 96 | int width = superpixels.cols; 97 | Mat transSuper = superpixels.t(); 98 | vector bd; 99 | switch (type) 100 | { 101 | case 1: 102 | bd = superpixels.row(0); 103 | break; 104 | case 2: 105 | bd = superpixels.row(height - 1); 106 | break; 107 | case 3: 108 | bd = transSuper.row(0); 109 | break; 110 | case 4: 111 | bd = transSuper.row(width - 1); 112 | break; 113 | case 5: 114 | vector bdTop = superpixels.row(0); 115 | vector bdDown = superpixels.row(height - 1); 116 | vector bdRight = transSuper.row(0); 117 | vector bdLeft = transSuper.row(width - 1); 118 | bd.insert(bd.end(), bdTop.begin(), bdTop.end()); 119 | bd.insert(bd.end(), bdDown.begin(), bdDown.end()); 120 | bd.insert(bd.end(), bdRight.begin(), bdRight.end()); 121 | bd.insert(bd.end(), bdLeft.begin(), bdLeft.end()); 122 | break; 123 | } 124 | sort(bd.begin(), bd.end()); 125 | bd.erase(unique(bd.begin(), bd.end()), bd.end()); 126 | return bd; 127 | } 128 | 129 | int GMR::GeneFeature(const Mat &img, const Mat &superpixels, const int feaType, Mat &feaSpL, Mat &feaSpA, Mat &feaSpB, Mat &spNpix, Mat &spCnt) 130 | { 131 | Mat feaMap(img.size(),img.type()); 132 | img.copyTo(feaMap); 133 | switch (feaType) 134 | { 135 | case 1: 136 | cvtColor(img, feaMap, CV_BGR2Lab); 137 | break; 138 | case 2: 139 | cvtColor(img, feaMap, CV_BGR2HSV); 140 | break; 141 | default: 142 | break; 143 | } 144 | /*vector feaSpL(spNum, 0); 145 | vector feaSpA(spNum, 0); 146 | vector feaSpB(spNum, 0); 147 | vector spNpix(spNum,0);*/ 148 | //vector< vector > spCnt(spNum, vector(2, 0)); 149 | for (int i = 0; i < superpixels.rows; ++i) 150 | { 151 | for (int j = 0; j < superpixels.cols; ++j) 152 | { 153 | feaSpL.at(superpixels.at(i, j)) += feaMap.at(i, j)[0]; 154 | feaSpA.at(superpixels.at(i, j)) += feaMap.at(i, j)[1]; 155 | feaSpB.at(superpixels.at(i, j)) += feaMap.at(i, j)[2]; 156 | spCnt.at(superpixels.at(i, j),0) += i; 157 | spCnt.at(superpixels.at(i, j),1) += j; 158 | ++spNpix.at(superpixels.at(i, j),0); 159 | } 160 | } 161 | for (int i = 0; i < spNum; ++i) 162 | { 163 | feaSpL.at(i) /= spNpix.at(i); 164 | feaSpA.at(i) /= spNpix.at(i); 165 | feaSpB.at(i) /= spNpix.at(i); 166 | spCnt.at(i, 0) /= spNpix.at(i); 167 | spCnt.at(i, 1) /= spNpix.at(i); 168 | } 169 | /*double minv = 0; 170 | double maxv = 0; 171 | minMaxIdx(feaSpL, &minv, &maxv); 172 | feaSpL = (feaSpL - minv) / (maxv - minv); 173 | minMaxIdx(feaSpA, &minv, &maxv); 174 | feaSpA = (feaSpA - minv) / (maxv - minv); 175 | minMaxIdx(feaSpB, &minv, &maxv); 176 | feaSpB = (feaSpB - minv) / (maxv - minv);*/ 177 | return 0; 178 | 179 | } 180 | 181 | Mat GMR::GeneWeight(const vector &feaSpL, const vector &feaSpA, const vector &feaSpB, const Mat &superpixels, const vector &bd, const Mat &adj) 182 | { 183 | Mat weightMat(Size(spNum, spNum), CV_32F, Scalar(-1)); 184 | int dist = 0; 185 | float minv = (float)numeric_limits::max(); 186 | float maxv = (float)numeric_limits::min(); 187 | for (int i = 0; i < spNum; ++i) 188 | { 189 | for (int j = 0; j < spNum; ++j) 190 | { 191 | if (adj.at(i, j) == 1) 192 | { 193 | dist = sqrt(pow(feaSpL[i] - feaSpL[j], 2)) + sqrt(pow(feaSpA[i] - feaSpA[j], 2)) + sqrt(pow(feaSpB[i] - feaSpB[j], 2)); 194 | weightMat.at(i, j) = dist; 195 | if (dist < minv) 196 | minv = dist; 197 | if (dist > maxv) 198 | maxv = dist; 199 | 200 | for (int k = 0; k < spNum; ++k) 201 | { 202 | if (adj.at(j, k) == 1) 203 | { 204 | dist = sqrt(pow(feaSpL[k] - feaSpL[i], 2)) + sqrt(pow(feaSpA[k] - feaSpA[i], 2)) + sqrt(pow(feaSpB[k] - feaSpB[i], 2)); 205 | weightMat.at(i, k) = dist; 206 | if (dist < minv) 207 | minv = dist; 208 | if (dist > maxv) 209 | maxv = dist; 210 | } 211 | 212 | } 213 | } 214 | 215 | } 216 | } 217 | 218 | for (int i = 0; i < bd.size(); ++i) 219 | { 220 | for (int j = 0; j < bd.size(); ++j) 221 | { 222 | dist = sqrt(pow(feaSpL[bd[i]] - feaSpL[bd[j]], 2)) + sqrt(pow(feaSpA[bd[i]] - feaSpA[bd[j]], 2)) + sqrt(pow(feaSpB[bd[i]] - feaSpB[bd[j]], 2)); 223 | weightMat.at(bd[i], bd[j]) = dist; 224 | if (dist < minv) 225 | minv = dist; 226 | if (dist > maxv) 227 | maxv = dist; 228 | } 229 | } 230 | 231 | for (int i = 0; i < spNum; ++i) 232 | { 233 | for (int j = 0; j < spNum; ++j) 234 | { 235 | if (weightMat.at(i, j)>-1) 236 | { 237 | weightMat.at(i, j) = (weightMat.at(i, j) - minv) / (maxv - minv); 238 | weightMat.at(i, j) = exp(-weightMat.at(i, j) / theta); 239 | } 240 | else 241 | weightMat.at(i, j) = 0; 242 | } 243 | } 244 | 245 | Mat tmpsuperpixels; 246 | normalize(weightMat, tmpsuperpixels, 255.0, 0.0, NORM_MINMAX); 247 | tmpsuperpixels.convertTo(tmpsuperpixels, CV_8UC3, 1.0); 248 | //imshow("sp", tmpsuperpixels); 249 | //waitKey(); 250 | return weightMat; 251 | } 252 | 253 | Mat GMR::GeneY(const vector &bd) 254 | { 255 | Mat Y(Size(spNum, 1), CV_32F, Scalar(0)); 256 | for (int i = 0; i < bd.size(); ++i) 257 | { 258 | Y.at(bd[i]) = 1; 259 | } 260 | return Y; 261 | } 262 | 263 | Mat GMR::inveMat(const Mat &weight, const Mat &Y) 264 | { 265 | Mat D(Size(weight.size()), CV_32F, Scalar(0)); 266 | Mat diagD(Size(weight.rows, 1), CV_32F); 267 | reduce(weight, diagD, 1, CV_REDUCE_SUM); 268 | D = Mat::diag(diagD); 269 | Mat LapMat(Size(weight.size()), CV_32F); 270 | LapMat = D - alpha*weight; 271 | Mat E = Mat::eye(weight.size(), CV_32F); 272 | Mat inverMat(Size(weight.size()), CV_32F); 273 | solve(LapMat, E, inverMat, CV_SVD); 274 | Mat tmpMat = Mat::ones(inverMat.size(), CV_32F) - Mat::eye(inverMat.size(), CV_32F); 275 | inverMat = inverMat.mul(tmpMat); 276 | Mat fData = inverMat*Y.t(); 277 | return fData; 278 | } 279 | 280 | Mat GMR::Sal2Img(const Mat &superpixels, const Mat &Sal) 281 | { 282 | Mat salMap(Size(superpixels.size()), CV_32F); 283 | for (int i = 0; i < superpixels.rows; ++i) 284 | { 285 | for (int j = 0; j < superpixels.cols; ++j) 286 | { 287 | salMap.at(i, j) = Sal.at(superpixels.at(i, j)); 288 | } 289 | } 290 | return salMap; 291 | } 292 | Mat GMR::GeneSal(const Mat &img) 293 | { 294 | Mat superpixels = GeneSp(img); 295 | Mat feaSpL(Size(1, spNum), CV_32F, Scalar(0)); 296 | Mat feaSpA(Size(1, spNum), CV_32F, Scalar(0)); 297 | Mat feaSpB(Size(1, spNum), CV_32F, Scalar(0)); 298 | Mat spNpix(Size(1, spNum), CV_32F, Scalar(0)); 299 | Mat spCnt(Size(2, spNum), CV_32F, Scalar(0)); 300 | GeneFeature(img, superpixels, 1, feaSpL, feaSpA, feaSpB, spNpix, spCnt); 301 | Mat adjmat = GeneAdjMat(superpixels); 302 | vector bd = GeneBdQuery(superpixels, 5); 303 | Mat affmat = GeneWeight(feaSpL, feaSpA, feaSpB, superpixels, bd, adjmat); 304 | Mat Y = GeneY(bd); 305 | Mat Sal = inveMat(affmat, Y); 306 | double minv = 0; 307 | double maxv = 0; 308 | minMaxIdx(Sal, &minv, &maxv); 309 | Sal = (Sal - minv) / (maxv - minv); 310 | Sal = 1 - Sal; 311 | return Sal; 312 | } 313 | void GMR::calculateSaliencyMap(Mat *img, Mat* dst) 314 | { 315 | Mat superpixels = GeneSp(*img); 316 | Mat sal = GeneSal(*img); 317 | 318 | Mat salMap = Sal2Img(superpixels, sal); 319 | Mat tmpsuperpixels; 320 | normalize(salMap, tmpsuperpixels, 255.0, 0.0, NORM_MINMAX); 321 | tmpsuperpixels.convertTo(*dst, CV_8UC1, 1.0); 322 | } 323 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/GMR/GMR.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | 3 | Copyright: Guangyu Zhong all rights reserved 4 | 5 | Author: Guangyu Zhong 6 | 7 | Date:2014-09-27 8 | 9 | Description: codes for Manifold Ranking Saliency Detection 10 | Reference http://ice.dlut.edu.cn/lu/Project/CVPR13[yangchuan]/cvprsaliency.htm 11 | 12 | **************************************************/ 13 | #ifndef _GMR_H 14 | #define _GMR_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "SLIC.h" 22 | using namespace cv; 23 | class GMR 24 | { 25 | public: 26 | GMR(); 27 | ~GMR(); 28 | Mat GeneSal(const Mat &img); 29 | Mat Sal2Img(const Mat &superpixels, const Mat &Sal); 30 | Mat GeneSp(const Mat &img); 31 | void calculateSaliencyMap(Mat *img, Mat* dst); 32 | private: 33 | int spNumMax; 34 | double compactness; 35 | float alpha; 36 | float theta; 37 | int spNum; 38 | Mat GeneAdjMat(const Mat &spmat); 39 | int GeneFeature(const Mat &img, const Mat &superpixels, const int feaType, Mat &feaSpL, Mat &feaSpA, Mat &feaSpB, Mat &spNpix, Mat &spCnt); 40 | Mat GeneWeight(const vector &feaSpL, const vector &feaSpA, const vector &feaSpB, const Mat &superpixels, const vector &bd, const Mat &adj); 41 | vector GeneBdQuery(const Mat &superpixels, const int type); 42 | Mat GeneY(const vector &bd); 43 | Mat inveMat(const Mat &weight, const Mat &Y); 44 | //Mat GeneFeature(const Mat &img); 45 | }; 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/GMR/SLIC.h: -------------------------------------------------------------------------------- 1 | // SLIC.h: interface for the SLIC class. 2 | //=========================================================================== 3 | // This code implements the superpixel method described in: 4 | // 5 | // Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Susstrunk, 6 | // "SLIC Superpixels", 7 | // EPFL Technical Report no. 149300, June 2010. 8 | //=========================================================================== 9 | // Copyright (c) 2012 Radhakrishna Achanta [EPFL]. All rights reserved. 10 | //=========================================================================== 11 | ////////////////////////////////////////////////////////////////////// 12 | 13 | #if !defined(_SLIC_H_INCLUDED_) 14 | #define _SLIC_H_INCLUDED_ 15 | 16 | 17 | #include 18 | #include 19 | #include 20 | using namespace std; 21 | 22 | 23 | class SLIC 24 | { 25 | public: 26 | SLIC(); 27 | virtual ~SLIC(); 28 | //============================================================================ 29 | // Superpixel segmentation for a given step size (superpixel size ~= step*step) 30 | //============================================================================ 31 | void DoSuperpixelSegmentation_ForGivenSuperpixelSize( 32 | const unsigned int* ubuff,//Each 32 bit unsigned int contains ARGB pixel values. 33 | const int width, 34 | const int height, 35 | int*& klabels, 36 | int& numlabels, 37 | const int& superpixelsize, 38 | const double& compactness); 39 | //============================================================================ 40 | // Superpixel segmentation for a given number of superpixels 41 | //============================================================================ 42 | void DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels( 43 | const unsigned int* ubuff, 44 | const int width, 45 | const int height, 46 | int*& klabels, 47 | int& numlabels, 48 | const int& K,//required number of superpixels 49 | const double& compactness);//10-20 is a good value for CIELAB space 50 | //============================================================================ 51 | // Supervoxel segmentation for a given step size (supervoxel size ~= step*step*step) 52 | //============================================================================ 53 | void DoSupervoxelSegmentation( 54 | unsigned int**& ubuffvec, 55 | const int& width, 56 | const int& height, 57 | const int& depth, 58 | int**& klabels, 59 | int& numlabels, 60 | const int& supervoxelsize, 61 | const double& compactness); 62 | //============================================================================ 63 | // Save superpixel labels in a text file in raster scan order 64 | //============================================================================ 65 | void SaveSuperpixelLabels( 66 | const int*& labels, 67 | const int& width, 68 | const int& height, 69 | const string& filename, 70 | const string& path); 71 | //============================================================================ 72 | // Save supervoxel labels in a text file in raster scan, depth order 73 | //============================================================================ 74 | void SaveSupervoxelLabels( 75 | const int**& labels, 76 | const int& width, 77 | const int& height, 78 | const int& depth, 79 | const string& filename, 80 | const string& path); 81 | //============================================================================ 82 | // Function to draw boundaries around superpixels of a given 'color'. 83 | // Can also be used to draw boundaries around supervoxels, i.e layer by layer. 84 | //============================================================================ 85 | void DrawContoursAroundSegments( 86 | unsigned int*& segmentedImage, 87 | int*& labels, 88 | const int& width, 89 | const int& height, 90 | const unsigned int& color ); 91 | 92 | private: 93 | //============================================================================ 94 | // The main SLIC algorithm for generating superpixels 95 | //============================================================================ 96 | void PerformSuperpixelSLIC( 97 | vector& kseedsl, 98 | vector& kseedsa, 99 | vector& kseedsb, 100 | vector& kseedsx, 101 | vector& kseedsy, 102 | int*& klabels, 103 | const int& STEP, 104 | const vector& edgemag, 105 | const double& m = 10.0); 106 | //============================================================================ 107 | // The main SLIC algorithm for generating supervoxels 108 | //============================================================================ 109 | void PerformSupervoxelSLIC( 110 | vector& kseedsl, 111 | vector& kseedsa, 112 | vector& kseedsb, 113 | vector& kseedsx, 114 | vector& kseedsy, 115 | vector& kseedsz, 116 | int**& klabels, 117 | const int& STEP, 118 | const double& compactness); 119 | //============================================================================ 120 | // Pick seeds for superpixels when step size of superpixels is given. 121 | //============================================================================ 122 | void GetLABXYSeeds_ForGivenStepSize( 123 | vector& kseedsl, 124 | vector& kseedsa, 125 | vector& kseedsb, 126 | vector& kseedsx, 127 | vector& kseedsy, 128 | const int& STEP, 129 | const bool& perturbseeds, 130 | const vector& edgemag); 131 | //============================================================================ 132 | // Pick seeds for supervoxels 133 | //============================================================================ 134 | void GetKValues_LABXYZ( 135 | vector& kseedsl, 136 | vector& kseedsa, 137 | vector& kseedsb, 138 | vector& kseedsx, 139 | vector& kseedsy, 140 | vector& kseedsz, 141 | const int& STEP); 142 | //============================================================================ 143 | // Move the superpixel seeds to low gradient positions to avoid putting seeds 144 | // at region boundaries. 145 | //============================================================================ 146 | void PerturbSeeds( 147 | vector& kseedsl, 148 | vector& kseedsa, 149 | vector& kseedsb, 150 | vector& kseedsx, 151 | vector& kseedsy, 152 | const vector& edges); 153 | //============================================================================ 154 | // Detect color edges, to help PerturbSeeds() 155 | //============================================================================ 156 | void DetectLabEdges( 157 | const double* lvec, 158 | const double* avec, 159 | const double* bvec, 160 | const int& width, 161 | const int& height, 162 | vector& edges); 163 | //============================================================================ 164 | // sRGB to XYZ conversion; helper for RGB2LAB() 165 | //============================================================================ 166 | void RGB2XYZ( 167 | const int& sR, 168 | const int& sG, 169 | const int& sB, 170 | double& X, 171 | double& Y, 172 | double& Z); 173 | //============================================================================ 174 | // sRGB to CIELAB conversion (uses RGB2XYZ function) 175 | //============================================================================ 176 | void RGB2LAB( 177 | const int& sR, 178 | const int& sG, 179 | const int& sB, 180 | double& lval, 181 | double& aval, 182 | double& bval); 183 | //============================================================================ 184 | // sRGB to CIELAB conversion for 2-D images 185 | //============================================================================ 186 | void DoRGBtoLABConversion( 187 | const unsigned int*& ubuff, 188 | double*& lvec, 189 | double*& avec, 190 | double*& bvec); 191 | //============================================================================ 192 | // sRGB to CIELAB conversion for 3-D volumes 193 | //============================================================================ 194 | void DoRGBtoLABConversion( 195 | unsigned int**& ubuff, 196 | double**& lvec, 197 | double**& avec, 198 | double**& bvec); 199 | //============================================================================ 200 | // Post-processing of SLIC segmentation, to avoid stray labels. 201 | //============================================================================ 202 | void EnforceLabelConnectivity( 203 | const int* labels, 204 | const int width, 205 | const int height, 206 | int*& nlabels,//input labels that need to be corrected to remove stray labels 207 | int& numlabels,//the number of labels changes in the end if segments are removed 208 | const int& K); //the number of superpixels desired by the user 209 | //============================================================================ 210 | // Post-processing of SLIC supervoxel segmentation, to avoid stray labels. 211 | //============================================================================ 212 | void EnforceSupervoxelLabelConnectivity( 213 | int**& labels,//input - previous labels, output - new labels 214 | const int& width, 215 | const int& height, 216 | const int& depth, 217 | int& numlabels, 218 | const int& STEP); 219 | 220 | private: 221 | int m_width; 222 | int m_height; 223 | int m_depth; 224 | 225 | double* m_lvec; 226 | double* m_avec; 227 | double* m_bvec; 228 | 229 | double** m_lvecvec; 230 | double** m_avecvec; 231 | double** m_bvecvec; 232 | }; 233 | 234 | #endif // !defined(_SLIC_H_INCLUDED_) 235 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/GMR/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | 3 | Copyright: Guangyu Zhong all rights reserved 4 | 5 | Author: Guangyu Zhong 6 | 7 | Date:2014-09-27 8 | 9 | Description: codes for Manifold Ranking Saliency Detection 10 | Reference http://ice.dlut.edu.cn/lu/Project/CVPR13[yangchuan]/cvprsaliency.htm 11 | 12 | **************************************************/ 13 | #include 14 | #include 15 | #include 16 | #include"GMR.h" 17 | using namespace std; 18 | using namespace cv; 19 | 20 | int main(int argc, char* argv[]) 21 | { 22 | Mat img = imread("timg.jpg"); 23 | Mat dst; 24 | GMR SpMat; 25 | /*Mat superpixels = SpMat.GeneSp(img); 26 | Mat sal = SpMat.GeneSal(img); 27 | 28 | Mat salMap = SpMat.Sal2Img(superpixels, sal); 29 | Mat tmpsuperpixels; 30 | normalize(salMap, tmpsuperpixels, 255.0, 0.0, NORM_MINMAX); 31 | tmpsuperpixels.convertTo(tmpsuperpixels, CV_8UC1, 1.0); 32 | imshow("sp", tmpsuperpixels);*/ 33 | SpMat.calculateSaliencyMap(&img,&dst); 34 | imshow("sp", dst); 35 | waitKey(); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/HC/HC.cpp: -------------------------------------------------------------------------------- 1 | #include "HC.h" 2 | using namespace std; 3 | 4 | template inline T sqr(T x) { return x * x; } 5 | typedef vector vecS; 6 | typedef vector vecI; 7 | typedef vector vecF; 8 | typedef vector vecD; 9 | typedef pair CostIdx; 10 | typedef pair CostfIdx; 11 | template inline T vecDist3(const Vec &v1, const Vec &v2) { return sqrt(sqr(v1[0] - v2[0]) + sqr(v1[1] - v2[1]) + sqr(v1[2] - v2[2])); } 12 | template inline T vecSqrDist3(const Vec &v1, const Vec &v2) { return sqr(v1[0] - v2[0]) + sqr(v1[1] - v2[1]) + sqr(v1[2] - v2[2]); } 13 | 14 | void HC::calculateSaliencyMap(Mat *src, Mat * dst) 15 | { 16 | Mat img3f; 17 | (*src).convertTo(img3f, CV_32FC3, 1.0 / 255); 18 | Mat idx1i, binColor3f, colorNums1i, weight1f, _colorSal; 19 | Quantize(img3f, idx1i, binColor3f, colorNums1i); 20 | cvtColor(binColor3f, binColor3f, CV_BGR2Lab); 21 | 22 | normalize(colorNums1i, weight1f, 1, 0, NORM_L1, CV_32F); 23 | GetHC(binColor3f, weight1f, _colorSal); 24 | float* colorSal = (float*)(_colorSal.data); 25 | Mat salHC1f(img3f.size(), CV_32F); 26 | for (int r = 0; r < img3f.rows; r++) 27 | { 28 | float* salV = salHC1f.ptr(r); 29 | int* _idx = idx1i.ptr(r); 30 | for (int c = 0; c < img3f.cols; c++) 31 | salV[c] = colorSal[_idx[c]]; 32 | } 33 | GaussianBlur(salHC1f, salHC1f, Size(3, 3), 0); 34 | 35 | normalize(salHC1f, *dst, 0, 1, NORM_MINMAX); 36 | } 37 | 38 | int HC::Quantize(const Mat& img3f, Mat &idx1i, Mat &_color3f, Mat &_colorNum, double ratio ) 39 | { 40 | static const int clrNums[3] = { 12, 12, 12 }; 41 | static const float clrTmp[3] = { clrNums[0] - 0.0001f, clrNums[1] - 0.0001f, clrNums[2] - 0.0001f }; 42 | static const int w[3] = { clrNums[1] * clrNums[2], clrNums[2], 1 }; 43 | 44 | CV_Assert(img3f.data != NULL); 45 | idx1i = Mat::zeros(img3f.size(), CV_32S); 46 | int rows = img3f.rows, cols = img3f.cols; 47 | if (img3f.isContinuous() && idx1i.isContinuous()) 48 | { 49 | cols *= rows; 50 | rows = 1; 51 | } 52 | 53 | // Build color pallet 54 | std::map pallet; 55 | for (int y = 0; y < rows; y++) 56 | { 57 | const float* imgData = img3f.ptr(y); 58 | int* idx = idx1i.ptr(y); 59 | for (int x = 0; x < cols; x++, imgData += 3) 60 | { 61 | idx[x] = (int)(imgData[0] * clrTmp[0])*w[0] + (int)(imgData[1] * clrTmp[1])*w[1] + (int)(imgData[2] * clrTmp[2]); 62 | pallet[idx[x]] ++; 63 | } 64 | } 65 | 66 | // Fine significant colors 67 | int maxNum = 0; 68 | { 69 | int count = 0; 70 | vector> num; // (num, color) pairs in num 71 | num.reserve(pallet.size()); 72 | for (map::iterator it = pallet.begin(); it != pallet.end(); it++) 73 | num.push_back(pair(it->second, it->first)); // (color, num) pairs in pallet 74 | sort(num.begin(), num.end(), std::greater< pair >()); 75 | 76 | maxNum = (int)num.size(); 77 | int maxDropNum = cvRound(rows * cols * (1 - ratio)); 78 | for (int crnt = num[maxNum - 1].first; crnt < maxDropNum && maxNum > 1; maxNum--) 79 | crnt += num[maxNum - 2].first; 80 | maxNum = min(maxNum, 256); // To avoid very rarely case 81 | if (maxNum < 10) 82 | maxNum = min((int)pallet.size(), 100); 83 | pallet.clear(); 84 | for (int i = 0; i < maxNum; i++) 85 | pallet[num[i].second] = i; 86 | 87 | vector color3i(num.size()); 88 | for (unsigned int i = 0; i < num.size(); i++) 89 | { 90 | color3i[i][0] = num[i].second / w[0]; 91 | color3i[i][1] = num[i].second % w[0] / w[1]; 92 | color3i[i][2] = num[i].second % w[1]; 93 | } 94 | 95 | for (unsigned int i = maxNum; i < num.size(); i++) 96 | { 97 | int simIdx = 0, simVal = INT_MAX; 98 | for (int j = 0; j < maxNum; j++) 99 | { 100 | int d_ij = vecSqrDist3(color3i[i], color3i[j]); 101 | if (d_ij < simVal) 102 | simVal = d_ij, simIdx = j; 103 | } 104 | pallet[num[i].second] = pallet[num[simIdx].second]; 105 | } 106 | } 107 | 108 | _color3f = Mat::zeros(1, maxNum, CV_32FC3); 109 | _colorNum = Mat::zeros(_color3f.size(), CV_32S); 110 | 111 | Vec3f* color = (Vec3f*)(_color3f.data); 112 | int* colorNum = (int*)(_colorNum.data); 113 | for (int y = 0; y < rows; y++) 114 | { 115 | const Vec3f* imgData = img3f.ptr(y); 116 | int* idx = idx1i.ptr(y); 117 | for (int x = 0; x < cols; x++) 118 | { 119 | idx[x] = pallet[idx[x]]; 120 | color[idx[x]] += imgData[x]; 121 | colorNum[idx[x]] ++; 122 | } 123 | } 124 | for (int i = 0; i < _color3f.cols; i++) 125 | color[i] = color[i] / colorNum[i]; 126 | 127 | return _color3f.cols; 128 | } 129 | void HC::GetHC(const Mat &binColor3f, const Mat &weight1f, Mat &_colorSal) 130 | { 131 | int binN = binColor3f.cols; 132 | _colorSal = Mat::zeros(1, binN, CV_32F); 133 | float* colorSal = (float*)(_colorSal.data); 134 | vector>> similar(binN); // Similar color: how similar and their index 135 | Vec3f* color = (Vec3f*)(binColor3f.data); 136 | float *w = (float*)(weight1f.data); 137 | for (int i = 0; i < binN; i++) 138 | { 139 | vector< pair> &similari = similar[i]; 140 | similari.push_back(make_pair(0.f, i)); 141 | for (int j = 0; j < binN; j++) 142 | { 143 | if (i == j) 144 | continue; 145 | float dij = vecDist3(color[i], color[j]); 146 | similari.push_back(make_pair(dij, j)); 147 | colorSal[i] += w[j] * dij; 148 | } 149 | sort(similari.begin(), similari.end()); 150 | } 151 | 152 | SmoothSaliency(binColor3f, _colorSal, 4.0f, similar); 153 | } 154 | void HC::SmoothSaliency(const Mat &binColor3f, Mat &sal1d, float delta, const vector>> &similar) 155 | { 156 | if (sal1d.cols < 2) 157 | return; 158 | CV_Assert(binColor3f.size() == sal1d.size() && sal1d.rows == 1); 159 | int binN = binColor3f.cols; 160 | Vec3f* color = (Vec3f*)(binColor3f.data); 161 | Mat tmpSal; 162 | sal1d.copyTo(tmpSal); 163 | float *sal = (float*)(tmpSal.data); 164 | float *nSal = (float*)(sal1d.data); 165 | 166 | //* Distance based smooth 167 | int n = max(cvRound(binN / delta), 2); 168 | vecF dist(n, 0), val(n); 169 | for (int i = 0; i < binN; i++) 170 | { 171 | const vector< pair> &similari = similar[i]; 172 | float totalDist = 0; 173 | 174 | val[0] = sal[i]; 175 | for (int j = 1; j < n; j++) 176 | { 177 | int ithIdx = similari[j].second; 178 | dist[j] = similari[j].first; 179 | val[j] = sal[ithIdx]; 180 | totalDist += dist[j]; 181 | } 182 | float valCrnt = 0; 183 | for (int j = 0; j < n; j++) 184 | valCrnt += val[j] * (totalDist - dist[j]); 185 | 186 | nSal[i] = valCrnt / ((n - 1) * totalDist); 187 | } 188 | 189 | } 190 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/HC/HC.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace cv; 9 | using namespace std; 10 | 11 | 12 | class HC 13 | { 14 | public: 15 | HC() 16 | { 17 | } 18 | 19 | ~HC() 20 | { 21 | } 22 | 23 | public: 24 | void calculateSaliencyMap(Mat *src, Mat * dst); 25 | private: 26 | int Quantize(const Mat& img3f, Mat &idx1i, Mat &_color3f, Mat &_colorNum, double ratio = 0.95); 27 | void GetHC(const Mat &binColor3f, const Mat &weight1f, Mat &_colorSal); 28 | void SmoothSaliency(const Mat &binColor3f, Mat &sal1d, float delta, const vector >> &similar); 29 | 30 | 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/LC/LC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/LC/LC.cpp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/LC/LC.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | using namespace cv; 5 | class LC 6 | { 7 | public: 8 | LC() 9 | { 10 | } 11 | 12 | ~LC() 13 | { 14 | } 15 | 16 | public: 17 | void calculateSaliencyMap(Mat *src, Mat * dst); 18 | 19 | }; 20 | 21 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/MBP/MBP.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/MBP/MBP.cpp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/MBP/MBP.hpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * Implemetation of the saliency detction method described in paper 3 | * "Minimum Barrier Salient Object Detection at 80 FPS", Jianming Zhang, 4 | * Stan Sclaroff, Zhe Lin, Xiaohui Shen, Brian Price, Radomir Mech, ICCV, 5 | * 2015 6 | * 7 | * Copyright (C) 2015 Jianming Zhang 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | * 22 | * If you have problems about this software, please contact: 23 | * jimmie33@gmail.com 24 | *******************************************************************************/ 25 | 26 | #pragma once 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | using namespace std; 35 | using namespace cv; 36 | static cv::RNG MBS_RNG; 37 | 38 | class MBP 39 | { 40 | public: 41 | MBP(); 42 | MBP(const cv::Mat& src); 43 | void calculateSaliencyMap(cv::Mat*img, cv::Mat* dst); 44 | cv::Mat getSaliencyMap(); 45 | void computeSaliency(bool use_geodesic = false); 46 | cv::Mat getMBSMap() const { return mMBSMap; } 47 | void rasterScan(const cv::Mat& featMap, cv::Mat& map, cv::Mat& lb, Mat& ub); 48 | 49 | void invRasterScan(const Mat& featMap, Mat& map, Mat& lb, Mat& ub); 50 | float getThreshForGeo(const Mat& src); 51 | 52 | void rasterScanGeo(const Mat& featMap, Mat& map, float thresh); 53 | void invRasterScanGeo(const Mat& featMap, Mat& map, float thresh); 54 | 55 | cv::Mat computeCWS(const cv::Mat src, float reg, float marginRatio); 56 | cv::Mat fastMBS(const std::vector featureMaps); 57 | cv::Mat fastGeodesic(const std::vector featureMaps); 58 | 59 | int findFrameMargin(const cv::Mat& img, bool reverse); 60 | bool removeFrame(const cv::Mat& inImg, cv::Mat& outImg, cv::Rect &roi); 61 | Mat doWork( 62 | const Mat& src, 63 | bool use_lab, 64 | bool remove_border, 65 | bool use_geodesic 66 | ); 67 | 68 | void Reconstruct(Mat src, Mat mask, Mat& dst); 69 | Mat morpySmooth(Mat I, int radius); 70 | Mat enhanceConstrast(Mat I, double b = 0.1); 71 | private: 72 | cv::Mat mSaliencyMap; 73 | cv::Mat mMBSMap; 74 | int mAttMapCount; 75 | cv::Mat mBorderPriorMap; 76 | cv::Mat mSrc; 77 | std::vector mFeatureMaps; 78 | void whitenFeatMap(float reg); 79 | void computeBorderPriorMap(float reg, float marginRatio); 80 | }; 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/MSS/MSS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "MSS.h" 6 | 7 | 8 | using namespace std; 9 | 10 | ////////////////////////////////////////////////////////////////////// 11 | // Construction/Destruction 12 | ////////////////////////////////////////////////////////////////////// 13 | 14 | MSS::MSS() 15 | { 16 | 17 | } 18 | 19 | MSS::~MSS() 20 | { 21 | 22 | } 23 | void MSS::calculateSaliencyMap(Mat *src, Mat * dst) 24 | { 25 | int ChanNum = (*src).channels(); 26 | if (ChanNum == 3) 27 | { 28 | Mat img3f; 29 | (*src).convertTo(img3f, CV_32FC3, 1.0 / 255); 30 | Mat sal(img3f.size(), CV_32F), tImg; 31 | cvtColor(img3f, tImg, CV_BGR2Lab); 32 | GaussianBlur(tImg, tImg, Size(3, 3), 0); 33 | int height = img3f.rows; 34 | int width = img3f.cols; 35 | vector lab; 36 | split(tImg, lab); 37 | Mat lvec = lab[0]; 38 | Mat avec = lab[1]; 39 | Mat bvec = lab[2]; 40 | Mat lint, aint, bint; 41 | integral(lvec, lint,CV_32F); 42 | integral(avec, aint, CV_32F); 43 | integral(bvec, bint, CV_32F); 44 | 45 | for (int j = 0; j < height; j++) 46 | { 47 | int yoff = min(j, height - j); 48 | int y1 = max(j - yoff, 0); 49 | int y2 = min(j + yoff, height - 1); 50 | 51 | 52 | float*salmap = sal.ptr(j); 53 | float*ls = lvec.ptr(j); 54 | float*as = avec.ptr(j); 55 | float*bs = bvec.ptr(j); 56 | 57 | 58 | for (int k = 0; k < width; k++) 59 | { 60 | int xoff = min(k, width - k); 61 | int x1 = max(k - xoff, 0); 62 | int x2 = min(k + xoff, width - 1); 63 | double area = (x2 - x1 + 1) * (y2 - y1 + 1); 64 | double lval = (lint.at(y2, x2) + lint.at(y1, x1) - lint.at(y2, x1) - lint.at(y1, x2)) / area; 65 | double aval = (aint.at(y2, x2) + aint.at(y1, x1) - aint.at(y2, x1) - aint.at(y1, x2)) / area; 66 | double bval = (bint.at(y2, x2) + bint.at(y1, x1) - bint.at(y2, x1) - bint.at(y1, x2)) / area; 67 | 68 | salmap[k] = (lval - ls[k]) * (lval - ls[k]) 69 | + (aval - as[k]) * (aval - as[k]) + (bval - bs[k]) 70 | * (bval - bs[k]);//square of the euclidean distance 71 | 72 | 73 | 74 | // cout << salmap[k] << endl; 75 | 76 | 77 | } 78 | } 79 | normalize(sal, *dst, 0, 1, NORM_MINMAX); 80 | 81 | } 82 | 83 | } -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/MSS/MSS.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | using namespace cv; 5 | class MSS 6 | { 7 | public: 8 | MSS(); 9 | ~MSS(); 10 | 11 | public: 12 | void calculateSaliencyMap(Mat *src, Mat * dst); 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/McueSalTest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/McueSalTest.cpp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/PHOT/PHOT.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "PHOT.h" 6 | 7 | 8 | using namespace std; 9 | 10 | ////////////////////////////////////////////////////////////////////// 11 | // Construction/Destruction 12 | ////////////////////////////////////////////////////////////////////// 13 | 14 | PHOT::PHOT() 15 | { 16 | 17 | } 18 | 19 | PHOT::~PHOT() 20 | { 21 | 22 | } 23 | void PHOT::calculateSaliencyMap(Mat *src, Mat * dst) 24 | { 25 | int ChanNum = (*src).channels(); 26 | Mat gray, grayTemp, grayDown; 27 | if (ChanNum == 3) 28 | { 29 | cvtColor(*src, gray, CV_BGR2GRAY); 30 | } 31 | else 32 | gray = *src; 33 | 34 | vector mv; 35 | 36 | 37 | Size imageSize(gray.cols, gray.rows); 38 | Mat realImage(imageSize, CV_64F); 39 | Mat imaginaryImage(imageSize, CV_64F); imaginaryImage.setTo(0); 40 | Mat combinedImage(imageSize, CV_64FC2); 41 | Mat imageDFT; 42 | Mat logAmplitude; 43 | Mat angle(imageSize, CV_64F); 44 | Mat magnitude(imageSize, CV_64F); 45 | Mat logAmplitude_blur; 46 | 47 | vector Rp; 48 | Mat Real(imageSize, CV_64F); 49 | Mat phase(imageSize, CV_64F); imaginaryImage.setTo(0); 50 | Mat DFT, RI; 51 | gray.convertTo(Real, CV_64F); 52 | Rp.push_back(Real); 53 | Rp.push_back(phase); 54 | merge(Rp, RI); 55 | dft(RI, DFT); 56 | split(DFT, Rp); 57 | Mat MAG, PHASE; 58 | cartToPolar(Rp.at(0), Rp.at(1), MAG, PHASE, false); 59 | 60 | Rp.at(0) = Rp.at(0) / MAG; 61 | Rp.at(1) = Rp.at(1) / MAG; 62 | merge(Rp, RI); 63 | dft(RI, RI, CV_DXT_INVERSE_SCALE);//invert dft 64 | split(RI, Rp); 65 | MAG = Rp.at(0); 66 | GaussianBlur(MAG, MAG, Size(7, 7), -1); 67 | Scalar MeanS = mean(MAG); 68 | double m = MeanS[1]; 69 | for (int r = 0; r < MAG.rows; r++) 70 | { 71 | double *s = MAG.ptr(r); 72 | for (int c = 0; c < MAG.cols; c++) 73 | s[c] = (s[c] - m)*(s[c] - m); 74 | } 75 | double minval, maxval; 76 | minMaxLoc(MAG, &minval, &maxval); 77 | //MAG = MAG / maxval;//normaliz 78 | MAG.convertTo(*dst, CV_32F,1 / maxval); 79 | 80 | } -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/PHOT/PHOT.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | using namespace cv; 5 | class PHOT 6 | { 7 | public: 8 | PHOT(); 9 | ~PHOT(); 10 | 11 | public: 12 | static void calculateSaliencyMap(Mat *src, Mat * dst); 13 | 14 | }; 15 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/RC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/RC/RC.cpp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/RC.h: -------------------------------------------------------------------------------- 1 | #include "opencv2/core/core.hpp" 2 | #include 3 | #include "opencv2/imgproc/imgproc.hpp" 4 | #include 5 | #include 6 | #include 7 | #include "Segmentation/segment-image.h" 8 | #include 9 | using namespace std; 10 | using namespace cv; 11 | class RC 12 | { 13 | public: 14 | RC() 15 | { 16 | } 17 | 18 | ~RC() 19 | { 20 | } 21 | void calculateSaliencyMap(Mat *src, Mat * dst); 22 | static int Quantize(const Mat& img3f, Mat &idx1i, Mat &_color3f, Mat &_colorNum, double ratio = 0.95); 23 | 24 | static Mat GetRC(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma); 25 | private: 26 | void caRCulateSaliencyMap(Mat *src, Mat * dst); 27 | static const int SAL_TYPE_NUM = 5; 28 | 29 | static void SmoothSaliency(const Mat &binColor3f, Mat &sal1d, float delta, const vector>> &similar); 30 | static void AbsAngle(const Mat& cmplx32FC2, Mat& mag32FC1, Mat& ang32FC1); 31 | static void GetCmplx(const Mat& mag32F, const Mat& ang32F, Mat& cmplx32FC2); 32 | struct Region{ 33 | Region() { pixNum = 0; } 34 | int pixNum; // Number of pixels 35 | vector > freIdx; // Frequency of each color and its index 36 | Point2d centroid; 37 | }; 38 | static void BuildRegions(const Mat& regIdx1i, vector ®s, const Mat &colorIdx1i, int colorNum); 39 | static void RegionContrast(const vector ®s, const Mat &color3fv, Mat& regSal1d, double sigmaDist); 40 | }; 41 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/Segmentation/disjoint-set.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2006 Pedro Felzenszwalb 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef DISJOINT_SET 20 | #define DISJOINT_SET 21 | 22 | // disjoint-set forests using union-by-rank and path compression (sort of). 23 | 24 | typedef struct { 25 | int rank; 26 | int p; 27 | int size; 28 | } uni_elt; 29 | 30 | class universe { 31 | public: 32 | universe(int elements); 33 | ~universe(); 34 | int find(int x); 35 | void join(int x, int y); 36 | int size(int x) const { return elts[x].size; } 37 | int num_sets() const { return num; } 38 | 39 | private: 40 | uni_elt *elts; 41 | int num; 42 | }; 43 | 44 | __inline universe::universe(int elements) { 45 | elts = new uni_elt[elements]; 46 | num = elements; 47 | for (int i = 0; i < elements; i++) { 48 | elts[i].rank = 0; 49 | elts[i].size = 1; 50 | elts[i].p = i; 51 | } 52 | } 53 | 54 | __inline universe::~universe() { 55 | delete [] elts; 56 | } 57 | 58 | __inline int universe::find(int x) { 59 | int y = x; 60 | while (y != elts[y].p) 61 | y = elts[y].p; 62 | elts[x].p = y; 63 | return y; 64 | } 65 | 66 | __inline void universe::join(int x, int y) { 67 | if (elts[x].rank > elts[y].rank) { 68 | elts[y].p = x; 69 | elts[x].size += elts[y].size; 70 | } else { 71 | elts[x].p = y; 72 | elts[y].size += elts[x].size; 73 | if (elts[x].rank == elts[y].rank) 74 | elts[y].rank++; 75 | } 76 | num--; 77 | } 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/Segmentation/segment-graph.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2006 Pedro Felzenszwalb 3 | 4 | This program is free software; you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation; either version 2 of the License, or 7 | (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with this program; if not, write to the Free Software 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | 19 | #ifndef SEGMENT_GRAPH 20 | #define SEGMENT_GRAPH 21 | 22 | #include 23 | #include 24 | #include "disjoint-set.h" 25 | 26 | // threshold function 27 | #define THRESHOLD(size, c) (c/size) 28 | 29 | typedef struct { 30 | float w; 31 | int a, b; 32 | } edge; 33 | 34 | __inline bool operator<(const edge &a, const edge &b) { 35 | return a.w < b.w; 36 | } 37 | 38 | /* 39 | * Segment a graph 40 | * 41 | * Returns a disjoint-set forest representing the segmentation. 42 | * 43 | * num_vertices: number of vertices in graph. 44 | * num_edges: number of edges in graph 45 | * edges: array of edges. 46 | * c: constant for treshold function. 47 | */ 48 | __inline universe *segment_graph(int num_vertices, int num_edges, edge *edges, float c) { 49 | // sort edges by weight 50 | std::sort(edges, edges + num_edges); 51 | 52 | // make a disjoint-set forest 53 | universe *u = new universe(num_vertices); 54 | 55 | // init thresholds 56 | float *threshold = new float[num_vertices]; 57 | for (int i = 0; i < num_vertices; i++) 58 | threshold[i] = THRESHOLD(1,c); 59 | 60 | // for each edge, in non-decreasing weight order... 61 | for (int i = 0; i < num_edges; i++) { 62 | edge *pedge = &edges[i]; 63 | 64 | // components conected by this edge 65 | int a = u->find(pedge->a); 66 | int b = u->find(pedge->b); 67 | if (a != b) { 68 | if ((pedge->w <= threshold[a]) && 69 | (pedge->w <= threshold[b])) { 70 | u->join(a, b); 71 | a = u->find(a); 72 | threshold[a] = pedge->w + THRESHOLD(u->size(a), c); 73 | } 74 | } 75 | } 76 | 77 | // free up 78 | delete threshold; 79 | return u; 80 | } 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/Segmentation/segment-image.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "segment-graph.h" 10 | #include "segment-image.h" 11 | using namespace cv; 12 | using namespace std; 13 | template inline T sqr(T x) { return x * x; } 14 | // dissimilarity measure between pixels 15 | static inline float diff(const Mat &img3f, int x1, int y1, int x2, int y2) 16 | { 17 | const Vec3f &p1 = img3f.at(y1, x1); 18 | const Vec3f &p2 = img3f.at(y2, x2); 19 | return sqrt(sqr(p1[0] - p2[0]) + sqr(p1[1] - p2[1]) + sqr(p1[2] - p2[2])); 20 | } 21 | 22 | /* 23 | * Segment an image 24 | * 25 | * Returns a color image representing the segmentation. 26 | * 27 | * Input: 28 | * im: image to segment. 29 | * sigma: to smooth the image. 30 | * c: constant for threshold function. 31 | * min_size: minimum component size (enforced by post-processing stage). 32 | * num_ccs: number of connected components in the segmentation. 33 | * Output: 34 | * colors: colors assigned to each components 35 | * pImgInd: index of each components, [0, colors.size() -1] 36 | */ 37 | int SegmentImage(const Mat &_src3f, Mat &pImgInd, double sigma, double c, int min_size) 38 | { 39 | CV_Assert(_src3f.type() == CV_32FC3); 40 | int width(_src3f.cols), height(_src3f.rows); 41 | Mat smImg3f; 42 | GaussianBlur(_src3f, smImg3f, Size(), sigma, 0, BORDER_REPLICATE); 43 | 44 | // build graph 45 | edge *edges = new edge[width*height*4]; 46 | int num = 0; 47 | { 48 | for (int y = 0; y < height; y++) { 49 | for (int x = 0; x < width; x++) { 50 | if (x < width-1) { 51 | edges[num].a = y * width + x; 52 | edges[num].b = y * width + (x+1); 53 | edges[num].w = diff(smImg3f, x, y, x+1, y); 54 | num++; 55 | } 56 | 57 | if (y < height-1) { 58 | edges[num].a = y * width + x; 59 | edges[num].b = (y+1) * width + x; 60 | edges[num].w = diff(smImg3f, x, y, x, y+1); 61 | num++; 62 | } 63 | 64 | if ((x < width-1) && (y < height-1)) { 65 | edges[num].a = y * width + x; 66 | edges[num].b = (y+1) * width + (x+1); 67 | edges[num].w = diff(smImg3f, x, y, x+1, y+1); 68 | num++; 69 | } 70 | 71 | if ((x < width-1) && (y > 0)) { 72 | edges[num].a = y * width + x; 73 | edges[num].b = (y-1) * width + (x+1); 74 | edges[num].w = diff(smImg3f, x, y, x+1, y-1); 75 | num++; 76 | } 77 | } 78 | } 79 | } 80 | 81 | // segment 82 | universe *u = segment_graph(width*height, num, edges, (float)c); 83 | 84 | // post process small components 85 | for (int i = 0; i < num; i++) { 86 | int a = u->find(edges[i].a); 87 | int b = u->find(edges[i].b); 88 | if ((a != b) && ((u->size(a) < min_size) || (u->size(b) < min_size))) 89 | u->join(a, b); 90 | } 91 | delete [] edges; 92 | 93 | // pick random colors for each component 94 | map marker; 95 | pImgInd.create(smImg3f.size(), CV_32S); 96 | 97 | int idxNum = 0; 98 | for (int y = 0; y < height; y++) { 99 | int *imgIdx = pImgInd.ptr(y); 100 | for (int x = 0; x < width; x++) { 101 | int comp = u->find(y * width + x); 102 | if (marker.find(comp) == marker.end()) 103 | marker[comp] = idxNum++; 104 | 105 | int idx = marker[comp]; 106 | imgIdx[x] = idx; 107 | } 108 | } 109 | delete u; 110 | 111 | return idxNum; 112 | } 113 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/RC/Segmentation/segment-image.h: -------------------------------------------------------------------------------- 1 | /* 2 | Modified by Ming-Ming on Aug. 15th, 2010. 3 | 4 | Copyright (C) 2006 Pedro Felzenszwalb 5 | 6 | This program is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 | */ 20 | 21 | #ifndef SEGMENT_IMAGE 22 | #define SEGMENT_IMAGE 23 | 24 | 25 | /* 26 | * Segment an image 27 | * 28 | * Returns a color image representing the segmentation. 29 | * 30 | * Input: 31 | * im: image to segment. 32 | * sigma: to smooth the image. 33 | * c: constant for threshold function. 34 | * min_size: minimum component size (enforced by post-processing stage). 35 | * num_ccs: number of connected components in the segmentation. 36 | * Output: 37 | * colors: colors assigned to each components 38 | * pImgInd: index of each components 39 | */ 40 | 41 | //"Default: k = 500, sigma = 1.0, min_size = 1000\n") or k = 200, sigma = 0.5, min_size = 50 42 | int SegmentImage(const cv::Mat &_src3f, cv::Mat &pImgInd, double sigma = 0.5, double c = 1, int min_size = 50); 43 | int SegmentImageI(const cv::Mat &_src3f, cv::Mat &pImgInd, double sigma = 0.5, double c = 1, int min_size = 50); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/Rudinac/Rudinac.h: -------------------------------------------------------------------------------- 1 | //=================================================================================== 2 | // Name : saliencyDetectionRudinac.h 3 | // Author : Joris van de Weem, joris.vdweem@gmail.com 4 | // Version : 1.0 5 | // Copyright : Copyright (c) 2010 LGPL 6 | // Description : C++ implementation of "Maja Rudinac, Pieter P. Jonker. 7 | // "Saliency Detection and Object Localization in Indoor Environments". 8 | // ICPR'2010. pp.404~407 9 | //=================================================================================== 10 | 11 | #ifndef _RUDINAC_H_INCLUDED_ 12 | #define _RUDINAC_H_INCLUDED_ 13 | 14 | 15 | 16 | // OpenCV 17 | #include "cv.h" 18 | #include "opencv2/highgui/highgui.hpp" 19 | 20 | using namespace cv; 21 | using namespace std; 22 | 23 | 24 | class Rudinac 25 | { 26 | 27 | 28 | 29 | public: 30 | Rudinac() 31 | { 32 | 33 | } 34 | 35 | ~Rudinac() 36 | { 37 | 38 | } 39 | 40 | 41 | void calculateSaliencyMap(const Mat* src, Mat* dst, int corlor = 1); 42 | 43 | private: 44 | Mat r,g,b,RG,BY,I; 45 | void createChannels(const Mat* src); 46 | void createSaliencyMap(const Mat src, Mat* dst); 47 | }; 48 | #endif 49 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/Rudinac/saliencyDetectionRudinac.cpp: -------------------------------------------------------------------------------- 1 | //=================================================================================== 2 | // Name : saliencyDetectionRudinac.cpp 3 | // Author : Joris van de Weem, joris.vdweem@gmail.com 4 | // Version : 1.1 5 | // Copyright : Copyright (c) 2011 LGPL 6 | // Description : C++ implementation of "Maja Rudinac, Pieter P. Jonker. 7 | // "Saliency Detection and Object Localization in Indoor Environments". 8 | // ICPR'2010. pp.404~407 9 | //=================================================================================== 10 | // v1.1: Ported to Robot Operating System (ROS) 11 | 12 | #include "Rudinac.h" 13 | #include "opencv2/core/core.hpp" 14 | #include "opencv2/core/utility.hpp" 15 | #include "opencv2/imgproc/imgproc.hpp" 16 | #include "opencv2/imgcodecs.hpp" 17 | #include "opencv2/highgui/highgui.hpp" 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | //void Rudinac::imageCB(const sensor_msgs::ImageConstPtr& msg_ptr) 26 | //{ 27 | // cv_bridge::CvImagePtr cv_ptr; 28 | // sensor_msgs::Image salmap_; 29 | // geometry_msgs::Point salientpoint_; 30 | // 31 | // Mat image_, saliencymap_; 32 | // Point pt_salient; 33 | // double maxVal; 34 | // 35 | // try 36 | // { 37 | // cv_ptr = cv_bridge::toCvCopy(msg_ptr, enc::BGR8); 38 | // } 39 | // catch (cv_bridge::Exception& e) 40 | // { 41 | // ROS_ERROR("cv_bridge exception: %s", e.what()); 42 | // } 43 | // cv_ptr->image.copyTo(image_); 44 | // 45 | // 46 | // saliencymap_.create(image_.size(),CV_8UC1); 47 | // Rudinac::calculateSaliencyMap(&image_, &saliencymap_); 48 | // 49 | // //-- Return most salient point --// 50 | // cv::minMaxLoc(saliencymap_,NULL,&maxVal,NULL,&pt_salient); 51 | // salientpoint_.x = pt_salient.x; 52 | // salientpoint_.y = pt_salient.y; 53 | // 54 | // 55 | // // CONVERT FROM CV::MAT TO ROSIMAGE FOR PUBLISHING 56 | // saliencymap_.convertTo(saliencymap_, CV_8UC1,255); 57 | // fillImage(salmap_, "mono8",saliencymap_.rows, saliencymap_.cols, saliencymap_.step, const_cast(saliencymap_.data)); 58 | // 59 | // saliencymap_pub_.publish(salmap_); 60 | // point_pub_.publish(salientpoint_); 61 | // 62 | // return; 63 | //} 64 | 65 | 66 | void Rudinac::calculateSaliencyMap(const Mat* src, Mat* dst, int corlor ) 67 | { 68 | Size imageSize(128,128); 69 | Mat srcDown(imageSize,CV_64F); 70 | Mat magnitudeI(imageSize,CV_64F); 71 | 72 | Mat magnitudeRG(imageSize,CV_64F); 73 | 74 | Mat magnitudeBY(imageSize,CV_64F); 75 | Mat magnitude(imageSize,CV_64F); 76 | 77 | resize(*src, srcDown, imageSize, 0, 0, INTER_LINEAR); 78 | 79 | createChannels(&srcDown); 80 | createSaliencyMap(I,&magnitudeI); 81 | if (corlor) 82 | createSaliencyMap(RG,&magnitudeRG); 83 | if (corlor) 84 | createSaliencyMap(BY,&magnitudeBY); 85 | if (corlor) 86 | magnitude = (magnitudeI + magnitudeRG + magnitudeBY); 87 | else 88 | magnitude = magnitudeI; 89 | GaussianBlur(magnitude, magnitude, Size(5,5), 0, 0, BORDER_DEFAULT); 90 | 91 | //-- Scale to domain [0,1] --// 92 | double minVal,maxVal; 93 | minMaxLoc(magnitude, &minVal, &maxVal); 94 | magnitude = magnitude / maxVal; 95 | 96 | resize(magnitude, *dst, dst->size(), 0, 0, INTER_LINEAR); 97 | } 98 | 99 | 100 | void Rudinac::createChannels(const Mat* src) 101 | { 102 | 103 | b.create(src->size(),CV_32F); 104 | g.create(src->size(),CV_32F); 105 | r.create(src->size(),CV_32F); 106 | I.create(src->size(),CV_32F); 107 | vector planes; 108 | split(*src, planes); 109 | Mat rgmax(src->size(),CV_32F); 110 | Mat rgbmax(src->size(),CV_32F); 111 | Mat mask(src->size(),CV_32F); 112 | 113 | for(int j=0; j(j,i) = planes[0].at(j,i); 117 | g.at(j,i) = planes[1].at(j,i); 118 | r.at(j,i) = planes[2].at(j,i); 119 | } 120 | 121 | I = r+g+b; 122 | //threshold(I, I, 255, 255, THRESH_TRUNC); // Saturation as in Matlab? 123 | I = I/3; 124 | 125 | rgmax = max(r,g); 126 | rgbmax = max(rgmax,b); 127 | 128 | //-- Prevent that the lowest value is zero, because you cannot divide by zero. 129 | for(int j=0; j(j,i) == 0) rgbmax.at(j,i) = 1; 133 | } 134 | 135 | 136 | RG = abs(r-g)/rgbmax; 137 | BY = abs(b - min(r,g))/rgbmax; 138 | 139 | rgbmax = rgbmax/255; 140 | //-- If max(r,g,b)<0.1 all components should be zero to stop large fluctuations of the color opponency values at low luminance --// 141 | threshold(rgbmax,mask,.1,1,THRESH_BINARY); 142 | RG = RG.mul(mask); 143 | BY = BY.mul(mask); 144 | I = I.mul(mask); 145 | } 146 | 147 | 148 | 149 | void Rudinac::createSaliencyMap(const Mat src, Mat* dst) 150 | { 151 | vector mv; 152 | 153 | Mat realImage(src.size(),CV_64F); 154 | Mat imaginaryImage(src.size(),CV_64F); imaginaryImage.setTo(0); 155 | Mat combinedImage(src.size(),CV_64FC2); 156 | Mat image_DFT; 157 | Mat logAmplitude; 158 | Mat angle(src.size(),CV_64F); 159 | Mat Magnitude(src.size(),CV_64F); 160 | Mat logAmplitude_blur; 161 | 162 | for(int j=0; j(j,i) = src.at(j,i); 165 | } 166 | } 167 | 168 | 169 | mv.push_back(realImage); 170 | mv.push_back(imaginaryImage); 171 | merge(mv,combinedImage); 172 | 173 | dft( combinedImage, image_DFT); 174 | split(image_DFT, mv); 175 | 176 | //-- Get magnitude and phase of frequency spectrum --// 177 | cartToPolar(mv.at(0), mv.at(1), Magnitude, angle, false); 178 | log(Magnitude,logAmplitude); 179 | 180 | //-- Blur log amplitude with averaging filter --// 181 | blur(logAmplitude, logAmplitude_blur, Size(3,3), Point(-1,-1), BORDER_DEFAULT); 182 | exp(logAmplitude - logAmplitude_blur,Magnitude); 183 | 184 | polarToCart(Magnitude, angle,mv.at(0), mv.at(1),false); 185 | merge(mv,image_DFT); 186 | dft(image_DFT,combinedImage,CV_DXT_INVERSE); 187 | 188 | split(combinedImage,mv); 189 | cartToPolar(mv.at(0), mv.at(1), Magnitude, angle, false); 190 | Magnitude = Magnitude.mul(Magnitude); 191 | 192 | Mat tempFloat(src.size(),CV_32F); 193 | for(int j=0; j(j,i) = Magnitude.at(j,i); 196 | 197 | *dst = tempFloat; 198 | } 199 | 200 | 201 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/SF.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Philipp Krähenbühl 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Stanford University nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "SF.h" 29 | #include "fastmath.h" 30 | 31 | #include "./filter/filter.h" 32 | 33 | SaliencySettings::SaliencySettings() { 34 | // Superpixel settings 35 | n_superpixels_ = 400; 36 | n_iterations_= 5; 37 | superpixel_color_weight_ = 1; 38 | 39 | // Saliency filter radii 40 | sigma_p_ = 0.25; 41 | sigma_c_ = 20.0; 42 | k_ = 3; // The paper states K=6 (but then I think we used standard deviation and not variance, was probably a typo) 43 | 44 | // Upsampling parameters 45 | min_saliency_ = 0.1; 46 | alpha_ = 1.0 / 30.0; 47 | beta_ = 1.0 / 30.0; 48 | 49 | // Various algorithm settings 50 | upsample_ = true; 51 | uniqueness_ = true; 52 | distribution_ = true; 53 | filter_uniqueness_ = filter_distribution_ = false; 54 | use_spix_color_ = false; // Disabled to get a slightly better performance 55 | } 56 | 57 | 58 | SF::SF( SaliencySettings settings ): settings_(settings), superpixel_( settings.n_superpixels_, settings.superpixel_color_weight_, settings.n_iterations_ ) { 59 | } 60 | Mat_< float > SF::saliency( const Mat_< Vec3b >& im ) const { 61 | // Convert the image to the lab space 62 | Mat_ rgbim, labim; 63 | im.convertTo( rgbim, CV_32F, 1.0/255. ); 64 | cvtColor( rgbim, labim, CV_BGR2Lab ); 65 | 66 | // Do the abstraction 67 | Mat_ segmentation = superpixel_.segment( labim ); 68 | std::vector< SuperpixelStatistic > stat = superpixel_.stat( labim, im, segmentation ); 69 | 70 | // Compute the uniqueness 71 | std::vector unique( stat.size(), 1 ); 72 | if (settings_.uniqueness_) { 73 | if (settings_.filter_uniqueness_) 74 | unique = uniquenessFilter( stat ); 75 | else 76 | unique = uniqueness( stat ); 77 | } 78 | 79 | // Compute the distribution 80 | std::vector dist( stat.size(), 0 ); 81 | if (settings_.distribution_) { 82 | if (settings_.filter_distribution_) 83 | dist = distributionFilter( stat ); 84 | else 85 | dist = distribution( stat ); 86 | } 87 | 88 | // Combine the two measures 89 | std::vector sp_saliency( stat.size() ); 90 | for( int i=0; i r; 95 | if (settings_.upsample_) 96 | r = assignFilter( im, segmentation, stat, sp_saliency ); 97 | else 98 | r = assign( segmentation, sp_saliency ); 99 | 100 | // Rescale the saliency to [0..1] 101 | double mn, mx; 102 | minMaxLoc( r, &mn, & mx ); 103 | r = (r - mn) / (mx - mn); 104 | 105 | // Increase the saliency value until we are below the minimal threshold 106 | double m_sal = settings_.min_saliency_ * r.size().area(); 107 | for( float sm = sum( r )[0]; sm < m_sal; sm = sum( r )[0] ) 108 | r = min( r*m_sal/sm, 1.0f ); 109 | 110 | return r; 111 | } 112 | 113 | void SF::calculateSaliencyMap(Mat *src, Mat * dst) 114 | { 115 | Mat_ rgbim, labim; 116 | (*src).convertTo(rgbim, CV_32F, 1.0 / 255.); 117 | cvtColor(rgbim, labim, CV_BGR2Lab); 118 | 119 | // Do the abstraction 120 | Mat_ segmentation = superpixel_.segment(labim); 121 | std::vector< SuperpixelStatistic > stat = superpixel_.stat(labim, *src, segmentation); 122 | 123 | // Compute the uniqueness 124 | std::vector unique(stat.size(), 1); 125 | if (settings_.uniqueness_) { 126 | if (settings_.filter_uniqueness_) 127 | unique = uniquenessFilter(stat); 128 | else 129 | unique = uniqueness(stat); 130 | } 131 | 132 | // Compute the distribution 133 | std::vector dist(stat.size(), 0); 134 | if (settings_.distribution_) { 135 | if (settings_.filter_distribution_) 136 | dist = distributionFilter(stat); 137 | else 138 | dist = distribution(stat); 139 | } 140 | 141 | // Combine the two measures 142 | std::vector sp_saliency(stat.size()); 143 | for (int i = 0; i r; 148 | if (settings_.upsample_) 149 | r = assignFilter(*src, segmentation, stat, sp_saliency); 150 | else 151 | r = assign(segmentation, sp_saliency); 152 | 153 | // Rescale the saliency to [0..1] 154 | double mn, mx; 155 | minMaxLoc(r, &mn, &mx); 156 | r = (r - mn) / (mx - mn); 157 | 158 | // Increase the saliency value until we are below the minimal threshold 159 | double m_sal = settings_.min_saliency_ * r.size().area(); 160 | for (float sm = sum(r)[0]; sm < m_sal; sm = sum(r)[0]) 161 | r = min(r*m_sal / sm, 1.0f); 162 | 163 | *dst= r; 164 | 165 | } 166 | 167 | // Normalize a vector of floats to the range [0..1] 168 | void normVec( std::vector< float > &r ){ 169 | const int N = r.size(); 170 | float mn = r[0], mx = r[0]; 171 | for( int i=1; i r[i]) 173 | mn = r[i]; 174 | if (mx < r[i]) 175 | mx = r[i]; 176 | } 177 | for( int i=0; i SF::uniqueness( const std::vector< SuperpixelStatistic >& stat ) const { 181 | const int N = stat.size(); 182 | std::vector< float > r( N ); 183 | const float sp = 0.5 / (settings_.sigma_p_ * settings_.sigma_p_); 184 | for( int i=0; i SF::distribution( const std::vector< SuperpixelStatistic >& stat ) const { 206 | const int N = stat.size(); 207 | std::vector< float > r( N ); 208 | const float sc = 0.5 / (settings_.sigma_c_*settings_.sigma_c_); 209 | for( int i=0; i SF::uniquenessFilter( const std::vector< SuperpixelStatistic >& stat ) const { 236 | const int N = stat.size(); 237 | 238 | // Setup the data and features 239 | std::vector< Vec2f > features( stat.size() ); 240 | Mat_ data( stat.size(), 5 ); 241 | for( int i=0; i(), data.ptr(), 5 ); 253 | 254 | // Compute the uniqueness 255 | std::vector< float > r( N ); 256 | for( int i=0; i SF::distributionFilter( const std::vector< SuperpixelStatistic >& stat ) const { 267 | const int N = stat.size(); 268 | 269 | // Setup the data and features 270 | std::vector< Vec3f > features( stat.size() ); 271 | Mat_ data( stat.size(), 4 ); 272 | for( int i=0; i(), data.ptr(), 4 ); 283 | 284 | // Compute the uniqueness 285 | std::vector< float > r( N ); 286 | for( int i=0; i SF::assign( const Mat_< int >& seg, const std::vector< float >& sal ) const { 293 | return Superpixel::assign( sal, seg ); 294 | } 295 | Mat_< float > SF::assignFilter( const Mat_< Vec3b >& im, const Mat_< int >& seg, const std::vector< SuperpixelStatistic >& stat, const std::vector< float >& sal ) const { 296 | std::vector< float > source_features( seg.size().area()*5 ), target_features( im.size().area()*5 ); 297 | Mat_< Vec2f > data( seg.size() ); 298 | // There is a type on the paper: alpha and beta are actually squared, or directly applied to the values 299 | const float a = settings_.alpha_, b = settings_.beta_; 300 | 301 | const int D = 5; 302 | // Create the source features 303 | for( int j=0,k=0; j(), data.ptr(), 2 ); 332 | } 333 | else { 334 | Filter filter( target_features.data(), im.cols*im.rows, D ); 335 | filter.filter( data.ptr(), data.ptr(), 2 ); 336 | } 337 | 338 | Mat_ r( im.size() ); 339 | for( int j=0; j 31 | 32 | struct SaliencySettings{ 33 | SaliencySettings(); 34 | 35 | // Superpixel settings 36 | int n_superpixels_, n_iterations_; 37 | float superpixel_color_weight_; 38 | 39 | // Saliency filter radii 40 | float sigma_p_; // Radius for the uniqueness operator [eq 1] 41 | float sigma_c_; // Color radius for the distribution operator [eq 3] 42 | float k_; // The sharpness parameter of the exponential in the merging operation [eq 5] 43 | 44 | // Upsampling parameters 45 | float min_saliency_; // Minimum number of salient pixels for final rescaling 46 | float alpha_, beta_; 47 | 48 | // Various algorithm settings 49 | // Enable or disable parts of the algorithm 50 | bool upsample_, uniqueness_, distribution_, filter_uniqueness_, filter_distribution_; 51 | // Should we use the image color or superpixel color as a feature for upsampling 52 | bool use_spix_color_; 53 | }; 54 | 55 | class SF { 56 | protected: 57 | SaliencySettings settings_; 58 | Superpixel superpixel_; 59 | protected: 60 | std::vector< float > uniqueness( const std::vector< SuperpixelStatistic > & stat ) const; 61 | std::vector< float > uniquenessFilter( const std::vector< SuperpixelStatistic > & stat ) const; 62 | std::vector< float > distribution( const std::vector< SuperpixelStatistic > & stat ) const; 63 | std::vector< float > distributionFilter( const std::vector< SuperpixelStatistic > & stat ) const; 64 | Mat_ assign( const Mat_ & seg, const std::vector< float > & sal ) const; 65 | 66 | // std::vector< float > uniquenessFilter( const std::vector< SuperpixelStatistic > & stat ) const; 67 | // std::vector< float > distributionFilter( const std::vector< SuperpixelStatistic > & stat ) const; 68 | Mat_ assignFilter( const Mat_ & im, const Mat_ & seg, const std::vector< SuperpixelStatistic > & stat, const std::vector< float > & sal ) const ; 69 | public: 70 | SF( SaliencySettings settings = SaliencySettings() ); 71 | Mat_ saliency(const Mat_ & im) const; 72 | void calculateSaliencyMap(Mat *src, Mat * dst); 73 | }; 74 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/fastmath.h: -------------------------------------------------------------------------------- 1 | // This code here comes from http://www.xnoiz.co.cc/fast-exp-x/ 2 | 3 | /* 4 | Copyright (c) 2011, Philipp Krähenbühl 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | * Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | * Neither the name of the Stanford University nor the 15 | names of its contributors may be used to endorse or promote products 16 | derived from this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 19 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 22 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #pragma once 31 | 32 | inline float fast_log2 (float val) { 33 | int * const exp_ptr = reinterpret_cast (&val); 34 | int x = *exp_ptr; 35 | const int log_2 = ((x >> 23) & 255) - 128; 36 | x &= ~(255 << 23); 37 | x += 127 << 23; 38 | *exp_ptr = x; 39 | 40 | return (val + log_2); 41 | } 42 | inline float fast_log (const float &val) { 43 | return (fast_log2 (val) * 0.69314718f); 44 | } 45 | inline float very_fast_exp(float x) { 46 | // err <= 3e-3 47 | // return 1 48 | // -x*(0.9664 49 | // -x*(0.3536)); 50 | 51 | return 1 52 | -x*(0.9999999995f 53 | -x*(0.4999999206f 54 | 55 | -x*(0.1666653019f 56 | -x*(0.0416573475f 57 | -x*(0.0083013598f 58 | 59 | -x*(0.0013298820f 60 | -x*(0.0001413161f))))))); 61 | } 62 | inline float fast_exp(float x) { 63 | bool lessZero = true; 64 | if (x < 0) { 65 | 66 | lessZero = false; 67 | x = -x; 68 | 69 | } 70 | // This diry little trick only works because of the normalization and the fact that one element in the normalization is 1 71 | if (x > 20) 72 | return 0; 73 | int mult = 0; 74 | 75 | while (x > 0.69*2*2*2) { 76 | 77 | mult+=3; 78 | x /= 8.0f; 79 | } 80 | 81 | while (x > 0.69*2*2) { 82 | mult+=2; 83 | 84 | x /= 4.0f; 85 | } 86 | while (x > 0.69) { 87 | 88 | mult++; 89 | x /= 2.0f; 90 | } 91 | 92 | x = very_fast_exp(x); 93 | while (mult) { 94 | 95 | mult--; 96 | x = x*x; 97 | } 98 | 99 | if (lessZero) { 100 | return 1 / x; 101 | 102 | } else { 103 | return x; 104 | } 105 | } 106 | 107 | #ifdef __SSE__ 108 | #include 109 | #include "sse_defs.h" 110 | inline __m128 very_fast_exp(__m128 x) { 111 | return _mm_set1_ps(1) 112 | -x*(_mm_set1_ps(0.9999999995) 113 | -x*(_mm_set1_ps(0.4999999206) 114 | 115 | -x*(_mm_set1_ps(0.1666653019) 116 | -x*(_mm_set1_ps(0.0416573475) 117 | -x*(_mm_set1_ps(0.0083013598) 118 | 119 | -x*(_mm_set1_ps(0.0013298820) 120 | -x*(_mm_set1_ps(0.0001413161)))))))); 121 | } 122 | inline __m128 fast_exp(__m128 x) { 123 | const __m128 zero = _mm_set1_ps( 0.0f ); 124 | __m128 lessZero = _mm_cmplt_ps( zero, x ); 125 | __m128 one = _mm_set1_ps(1.0); 126 | // Invert x of less than 0 127 | x = _mm_add_ps( _mm_and_ps(lessZero,x), _mm_andnot_ps(lessZero,-x) ); 128 | 129 | // This diry little trick only works because of the normalization and then fact that one element in the normalization is 1 130 | __m128 set_zero = _mm_cmple_ps( x, _mm_set1_ps(20.0) ); 131 | 132 | // Bring it into range 133 | __m128 mult = zero; 134 | for( int i=4, j=2; i>0; i/=2, j-- ){ 135 | __m128 cmp = _mm_cmpgt_ps( x, _mm_set1_ps( 0.69*i ) ); 136 | mult += _mm_and_ps( cmp, _mm_set1_ps( j+1 ) ); 137 | x = x / (_mm_and_ps( cmp, _mm_set1_ps( 2*i-1 )) + one); 138 | } 139 | 140 | x = very_fast_exp(x); 141 | 142 | while(1){ 143 | __m128 cmp = _mm_cmpgt_ps( mult, _mm_set1_ps(0.0) ); 144 | if (!_mm_movemask_ps(cmp)) break; 145 | mult -= _mm_and_ps( cmp, one ); 146 | x *= (_mm_and_ps( cmp, x-one ) + one); 147 | } 148 | 149 | x = _mm_add_ps( _mm_and_ps(lessZero,one/x), _mm_andnot_ps(lessZero,x) ); 150 | return _mm_and_ps( set_zero, x ); 151 | } 152 | #endif 153 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/filter/filter.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Philipp Krähenbühl 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Stanford University nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | #include "permutohedral.h" 28 | #include "filter.h" 29 | 30 | Filter::Filter( const float * source_features, int N_source, const float * target_features, int N_target, int feature_dim ):n1_(N_source),o1_(0),n2_(N_target), o2_(N_source){ 31 | permutohedral_ = new Permutohedral(); 32 | float * features = new float[ (N_source+N_target)*feature_dim ]; 33 | memcpy( features, source_features, N_source*feature_dim*sizeof(float) ); 34 | memcpy( features+N_source*feature_dim, target_features, N_target*feature_dim*sizeof(float) ); 35 | permutohedral_->init( features, feature_dim, N_source+N_target ); 36 | delete[] features; 37 | } 38 | Filter::Filter( const float * features, int N, int feature_dim ):n1_(N),o1_(0),n2_(N), o2_(0){ 39 | permutohedral_ = new Permutohedral(); 40 | permutohedral_->init( features, feature_dim, N ); 41 | } 42 | Filter::~Filter(){ 43 | delete permutohedral_; 44 | } 45 | void Filter::filter( const float * source, float * target, int value_size ){ 46 | permutohedral_->compute( target, source, value_size, o1_, o2_, n1_, n2_ ); 47 | } 48 | void Filter::reverseFilter( const float * source, float * target, int value_size ){ 49 | permutohedral_->compute( target, source, value_size, o2_, o1_, n2_, n1_ ); 50 | } 51 | 52 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/filter/filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Philipp Krähenbühl 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Stanford University nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #pragma once 29 | 30 | // This function defines a simplified interface to the permutohedral lattice 31 | // We assume a filter standard deviation of 1 32 | class Permutohedral; 33 | class Filter{ 34 | protected: 35 | int n1_, o1_, n2_, o2_; 36 | Permutohedral * permutohedral_; 37 | // Don't copy 38 | Filter( const Filter& filter ){} 39 | public: 40 | // Use different source and target features 41 | Filter( const float * source_features, int N_source, const float * target_features, int N_target, int feature_dim ); 42 | // Use the same source and target features 43 | Filter( const float * features, int N, int feature_dim ); 44 | // 45 | ~Filter(); 46 | // Filter a bunch of values 47 | void filter( const float * source, float * target, int value_size ); 48 | // Reverse filter (swap source and target features) 49 | void reverseFilter( const float * source, float * target, int value_size ); 50 | }; 51 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/filter/permutohedral.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Philipp Krähenbühl 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Stanford University nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "permutohedral.h" 29 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/superpixel/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library( superpixel superpixel.cpp ) 2 | target_link_libraries( superpixel ${OpenCV_LIBS} ) 3 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SF/superpixel/superpixel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Philipp Krähenbühl 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the Stanford University nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY Philipp Krähenbühl ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL Philipp Krähenbühl BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #include "superpixel.h" 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | SuperpixelStatistic::SuperpixelStatistic() : mean_color_( 0.f, 0.f, 0.f ), mean_position_( 0.f, 0.f ) { 35 | } 36 | 37 | Superpixel::Superpixel( int K, float col_w, int n_iter, bool geodesic ) : K_( K ), col_w_( col_w ), n_iter_(n_iter), geodesic_(geodesic) { 38 | } 39 | 40 | Mat_< int > Superpixel::segment( const Mat_< Vec3f >& im ) const { 41 | if (geodesic_) 42 | return geodesicSegmentation( im ); 43 | else 44 | return slic( im ); 45 | } 46 | Mat_< int > Superpixel::geodesicSegmentation( const Mat_< Vec3f >& im ) const { 47 | std::uniform_int_distribution distribution(-2, 2); 48 | std::mt19937 engine; // Mersenne twister MT19937 49 | auto randint = std::bind(distribution, engine); 50 | 51 | // Compute the spacing and grid size of the superpixels 52 | double sp_area = 1.0 * im.cols * im.rows / K_; 53 | int Kx = 0.5 + im.cols / sqrt( sp_area ), Ky = 0.5 + im.rows / sqrt( sp_area ); 54 | int K = Kx*Ky; 55 | 56 | int win_sz = 1.0 * sqrt(sp_area) + 1; 57 | 58 | // Initialize the seeds on a regular grid 59 | std::vector< int64 > cnt( K ); 60 | std::vector< Point2d > seedsd( K ); 61 | std::vector< Point > seeds( K ); 62 | for( int i=0,k=0; i dx( im.size() ), dy( im.size() ); 67 | 68 | for( int j=0; j dist( im.size() ); 78 | Mat_ label( im.size() ); 79 | for( int it=0; it::max(); 82 | label = -1; 83 | for( int k=0; k=0; j-- ) 100 | for( int i=im.cols-1; i>=0; i-- ) { 101 | if (i && dist(j,i) + dx(j,i-1) < dist(j,i-1)) { 102 | dist(j,i-1) = dist(j,i) + dx(j,i-1); 103 | label(j,i-1) = label(j,i); 104 | } 105 | if (j && dist(j,i) + dx(j-1,i) < dist(j-1,i)) { 106 | dist(j-1,i) = dist(j,i) + dy(j-1,i); 107 | label(j-1,i) = label(j,i); 108 | } 109 | } 110 | } 111 | for( int k=0; k 0) 153 | seeds[k] = Point( 0.5 + seedsd[k].x / cnt[k], 0.5 + seedsd[k].y / cnt[k] ); 154 | } 155 | return label; 156 | } 157 | // We are implementing SLIC here. I'm too lazy to enfoce the connectivity 158 | Mat_< int > Superpixel::slic( const Mat_< Vec3f >& im ) const { 159 | // Compute the spacing and grid size of the superpixels 160 | double sp_area = 1.0 * im.cols * im.rows / K_; 161 | int Kx = 0.5 + im.cols / sqrt( sp_area ), Ky = 0.5 + im.rows / sqrt( sp_area ); 162 | int K = Kx*Ky; 163 | 164 | int win_sz = 1.0 * sqrt(sp_area) + 1; 165 | 166 | // Initialize the seeds on a regular grid 167 | std::vector< int64 > cnt( K ); 168 | std::vector< Point2d > seedsd( K ); 169 | std::vector< Point > seeds( K ); 170 | for( int i=0,k=0; i dist( im.size() ); 176 | Mat_ label( im.size() ); 177 | for( int it=0; it::max(); 180 | label = -1; 181 | for( int k=0; k 0) 223 | seeds[k] = Point( 0.5 + seedsd[k].x / cnt[k], 0.5 + seedsd[k].y / cnt[k] ); 224 | } 225 | return label; 226 | } 227 | 228 | std::vector< SuperpixelStatistic > Superpixel::stat( const Mat_< Vec3f >& im, const Mat_< Vec3b >& rgb, const Mat_< int >& segmentation ) const { 229 | int K = nLabels( segmentation ); 230 | std::vector< SuperpixelStatistic > stat( K ); 231 | std::vector< double > cnt( K, 1e-10 ); 232 | 233 | for( int j=0; j=0 ) { 237 | stat[ l ].mean_color_ += im(j,i); 238 | stat[ l ].mean_rgb_ += rgb(j,i); 239 | stat[ l ].mean_position_ += Vec2f( i, j ); 240 | cnt[ l ] += 1; 241 | } 242 | } 243 | for( int i=0; i Superpixel::visualizeMeanColor( const Mat_< int >& segmentation, const std::vector< SuperpixelStatistic >& stat ) const { 256 | std::vector< Vec3f > colors; 257 | for( int k=0; k Superpixel::visualizeRandom( const Mat_< int >& segmentation ) const { 262 | srand(segmentation.size().area()); 263 | 264 | int n_label = nLabels( segmentation ); 265 | 266 | std::vector< Vec3f > colors; 267 | for( int k=0; k& segmentation ) const { 273 | int n_label = 0; 274 | for( int j=0; j 30 | using namespace cv; 31 | 32 | struct SuperpixelStatistic { 33 | Vec3f mean_color_; 34 | Vec3f mean_rgb_; 35 | Vec2f mean_position_; 36 | int size_; 37 | SuperpixelStatistic(); 38 | }; 39 | 40 | class Superpixel { 41 | protected: 42 | int K_, n_iter_; 43 | float col_w_; 44 | bool geodesic_; 45 | Mat_ slic( const Mat_ & im ) const; 46 | Mat_ geodesicSegmentation( const Mat_ & im ) const; 47 | public: 48 | Superpixel( int K, float col_w, int n_iter=5, bool geodesic=true ); 49 | Mat_ segment( const Mat_ & im ) const; 50 | std::vector< SuperpixelStatistic > stat( const Mat_ & im, const Mat_< Vec3b >& rgb, const Mat_ & segmentation ) const; 51 | Mat_ visualizeMeanColor( const Mat_ & segmentation, const std::vector< SuperpixelStatistic > & stat ) const; 52 | Mat_ visualizeRandom( const Mat_ & segmentation ) const; 53 | template< typename T > 54 | static Mat_ assign( const std::vector & val, const Mat_ & segmentation ); 55 | int nLabels( const Mat_ & segmentation ) const; 56 | }; 57 | 58 | template< typename T > 59 | Mat_ Superpixel::assign( const std::vector & val, const Mat_ & segmentation ) { 60 | Mat_ r( segmentation.size() ); 61 | for( int j=0; j 30 | 31 | int main( int argc, char * argv[] ) { 32 | if (argc < 2) { 33 | printf("Usage: %s image\n", argv[0] ); 34 | return -1; 35 | } 36 | Mat im = imread( argv[1] ); 37 | Mat_ imf, bimf, labim; 38 | im.convertTo( imf, CV_32F, 1.0/255. ); 39 | cvtColor( imf, labim, CV_BGR2Lab ); 40 | 41 | Superpixel spix( 100, 1.0 ); 42 | Mat_ seg = spix.segment( labim ); 43 | imshow( "im", imf ); 44 | imshow( "sp", spix.visualizeRandom( seg ) ); 45 | imshow( "mn", spix.visualizeMeanColor( seg, spix.stat( imf, im, seg ) ) ); 46 | if (argc > 2) 47 | imwrite( argv[2], spix.visualizeMeanColor( seg, spix.stat( imf, im, seg ) )*255 ); 48 | waitKey(); 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SR/SR.cpp: -------------------------------------------------------------------------------- 1 | //=================================================================================== 2 | // Name : saliencyDetectionHou.cpp 3 | // Author : Oytun Akman, oytunakman@gmail.com 4 | // Editor : Joris van de Weem, joris.vdweem@gmail.com (Conversion to ROS) 5 | // Version : 1.2 6 | // Copyright : Copyright (c) 2010 LGPL 7 | // Description : C++ implementation of "Saliency Detection: A Spectral Residual 8 | // Approach" by Xiaodi Hou and Liqing Zhang (CVPR 2007). 9 | //=================================================================================== 10 | // v1.1: Changed Gaussianblur of logamplitude to averaging blur and gaussian kernel of saliency map to sigma = 8, kernelsize = 5 11 | // for better consistency with the paper. (Joris) 12 | // v1.2: Ported to Robot Operating System (ROS) (Joris) 13 | 14 | #include "SR.h" 15 | #include "opencv2/core/core.hpp" 16 | #include "opencv2/core/utility.hpp" 17 | #include "opencv2/imgproc/imgproc.hpp" 18 | #include "opencv2/imgcodecs.hpp" 19 | #include "opencv2/highgui/highgui.hpp" 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | 29 | void SR::calculateSaliencyMap(const Mat* src, Mat* dst) 30 | { 31 | Mat grayTemp, grayDown; 32 | vector mv; 33 | //Size imageSize(160,120); 34 | Size imageSize((*src).cols , (*src).rows ); 35 | Mat realImage(imageSize,CV_64F); 36 | Mat imaginaryImage(imageSize,CV_64F); imaginaryImage.setTo(0); 37 | Mat combinedImage(imageSize,CV_64FC2); 38 | Mat imageDFT; 39 | Mat logAmplitude; 40 | Mat angle(imageSize,CV_64F); 41 | Mat magnitude(imageSize,CV_64F); 42 | Mat logAmplitude_blur; 43 | 44 | cvtColor(*src, grayTemp, CV_BGR2GRAY); 45 | resize(grayTemp, grayDown, imageSize, 0, 0, INTER_LINEAR); 46 | for(int j=0; j(j,i) = grayDown.at(j,i); 49 | 50 | mv.push_back(realImage); 51 | mv.push_back(imaginaryImage); 52 | merge(mv,combinedImage); 53 | dft( combinedImage, imageDFT); 54 | split(imageDFT, mv); 55 | 56 | //-- Get magnitude and phase of frequency spectrum --// 57 | cartToPolar(mv.at(0), mv.at(1), magnitude, angle, false); 58 | log(magnitude,logAmplitude); 59 | //-- Blur log amplitude with averaging filter --// 60 | blur(logAmplitude, logAmplitude_blur, Size(3,3), Point(-1,-1), BORDER_DEFAULT); 61 | 62 | exp(logAmplitude - logAmplitude_blur,magnitude); 63 | //-- Back to cartesian frequency domain --// 64 | polarToCart(magnitude, angle, mv.at(0), mv.at(1), false); 65 | merge(mv, imageDFT); 66 | dft( imageDFT, combinedImage, CV_DXT_INVERSE); 67 | split(combinedImage, mv); 68 | 69 | cartToPolar(mv.at(0), mv.at(1), magnitude, angle, false); 70 | GaussianBlur(magnitude, magnitude, Size(5,5), 8, 0, BORDER_DEFAULT); 71 | magnitude = magnitude.mul(magnitude); 72 | 73 | double minVal,maxVal; 74 | minMaxLoc(magnitude, &minVal, &maxVal); 75 | magnitude = magnitude / maxVal;//normalize 76 | 77 | Mat tempFloat(imageSize,CV_32F); 78 | 79 | for(int j=0; j(j,i) = magnitude.at(j,i); 82 | 83 | resize(tempFloat, *dst, dst->size(), 0, 0, INTER_LINEAR); 84 | } 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/SR/SR.h: -------------------------------------------------------------------------------- 1 | //=================================================================================== 2 | // Name : saliencyDetectionHou.h 3 | // Author : Oytun Akman, oytunakman@gmail.com 4 | // Version : 1.0 5 | // Copyright : Copyright (c) 2010 LGPL 6 | // Description : C++ implementation of "Saliency Detection: A Spectral Residual 7 | // Approach" by Xiaodi Hou and Liqing Zhang (CVPR 2007). 8 | //=================================================================================== 9 | 10 | #ifndef _SALIENCYMAPHOU_H_INCLUDED_ 11 | #define _SALIENCYMAPHOU_H_INCLUDED_ 12 | 13 | // ROS 14 | 15 | 16 | // OpenCV 17 | #include "cv.h" 18 | #include "opencv2/highgui/highgui.hpp" 19 | 20 | using namespace cv; 21 | using namespace std; 22 | 23 | 24 | class SR 25 | { 26 | 27 | 28 | 29 | public: 30 | SR() 31 | { 32 | 33 | } 34 | 35 | 36 | ~SR() 37 | { 38 | 39 | } 40 | 41 | //void imageCB(const sensor_msgs::ImageConstPtr& msg_ptr); 42 | void calculateSaliencyMap(const Mat* src, Mat* dst); 43 | }; 44 | #endif 45 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/Scratch_6.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/Scratch_6.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/Wipe_crack_1.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/Wipe_crack_1.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/apple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/apple.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/bird.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/bird.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/exp4_num_32185.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/exp4_num_32185.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/exp6_num_116623.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/exp6_num_116623.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/image20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/image20.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/image36.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/image36.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/itti/Itti.h: -------------------------------------------------------------------------------- 1 | //=================================================================================== 2 | // Name : saliencyDetectionItti.h 3 | // Author : Oytun Akman, oytunakman@gmail.com 4 | // Version : 1.0 5 | // Copyright : Copyright (c) 2010 LGPL 6 | // Description : C++ implementation of "A Model of Saliency-Based Visual Attention 7 | // for Rapid Scene Analysis" by Laurent Itti, Christof Koch and Ernst 8 | // Niebur (PAMI 1998). 9 | //=================================================================================== 10 | 11 | #ifndef _ITTI_H_INCLUDED_ 12 | #define _ITTI_H_INCLUDED_ 13 | 14 | 15 | 16 | // OpenCV 17 | #include "cv.h" 18 | #include "opencv2/highgui/highgui.hpp" 19 | #include "opencv2/core/core.hpp" 20 | #include "opencv2/core/utility.hpp" 21 | #include "opencv2/imgproc/imgproc.hpp" 22 | #include "opencv2/imgcodecs.hpp" 23 | #include "opencv2/highgui/highgui.hpp" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | using namespace cv; 32 | using namespace std; 33 | 34 | 35 | class ITTI 36 | { 37 | 38 | 39 | public: 40 | ITTI() 41 | { 42 | 43 | } 44 | 45 | 46 | ~ITTI() 47 | { 48 | 49 | } 50 | 51 | 52 | void calculateSaliencyMap(const Mat* src, Mat * dst, int corlor = 1, int scaleBase = 3); 53 | void viewFeaturemaps(); 54 | void combineFeatureMaps(int corlor,int scale); 55 | 56 | Mat conspicuityMap_I; 57 | Mat conspicuityMap_C; 58 | Mat conspicuityMap_O; 59 | Mat S; 60 | 61 | private: 62 | Mat r, g, b, R, G, B, Y, I; 63 | vector gaussianPyramid_I; 64 | vector gaussianPyramid_R; 65 | vector gaussianPyramid_G; 66 | vector gaussianPyramid_B; 67 | vector gaussianPyramid_Y; 68 | 69 | void createChannels(const Mat* src); 70 | void createScaleSpace(const Mat* src, vector* dst, int scale); 71 | 72 | void normalize_rgb(); 73 | void create_RGBY(); 74 | void createIntensityFeatureMaps(); 75 | void createColorFeatureMaps(); 76 | void createOrientationFeatureMaps(int orientation); 77 | void mapNormalization(Mat* src); 78 | void clearBuffers(); 79 | 80 | vector featureMaps_I; 81 | vector featureMaps_RG; 82 | vector featureMaps_BY; 83 | vector featureMaps_0; 84 | vector featureMaps_45; 85 | vector featureMaps_90; 86 | vector featureMaps_135; 87 | }; 88 | #endif 89 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/itti/cvgabor.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2006 by Mian Zhou * 3 | * M.Zhou@reading.ac.uk * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | #ifndef CVGABOR_H 21 | #define CVGABOR_H 22 | 23 | #include 24 | 25 | 26 | #include 27 | #include 28 | using namespace std; 29 | 30 | #define PI 3.14159265 31 | #define FALSE 0 32 | #define TRUE 1 33 | #define CV_GABOR_REAL 1 34 | #define CV_GABOR_IMAG 2 35 | #define CV_GABOR_MAG 3 36 | #define CV_GABOR_PHASE 4 37 | 38 | /** 39 | @author Mian Zhou 40 | */ 41 | class CvGabor{ 42 | public: 43 | CvGabor(); 44 | 45 | ~CvGabor(); 46 | 47 | CvGabor(int iMu, int iNu); 48 | CvGabor(int iMu, int iNu, float dSigma); 49 | CvGabor(int iMu, int iNu, float dSigma, float dF); 50 | CvGabor(float dPhi, int iNu); 51 | CvGabor(float dPhi, int iNu, float dSigma); 52 | CvGabor(float dPhi, int iNu, float dSigma, float dF); 53 | bool IsInit(); 54 | long mask_width(); 55 | IplImage* get_image(int Type); 56 | bool IsKernelCreate(); 57 | long get_mask_width(); 58 | void Init(int iMu, int iNu, double dSigma, double dF); 59 | void Init(double dPhi, int iNu, double dSigma, double dF); 60 | void output_file(const char *filename, int Type); 61 | CvMat* get_matrix(int Type); 62 | void show(int Type); 63 | void conv_img(IplImage *src, IplImage *dst, int Type); 64 | 65 | protected: 66 | float Sigma; 67 | float F; 68 | float Kmax; 69 | float K; 70 | float Phi; 71 | bool bInitialised; 72 | bool bKernel; 73 | long Width; 74 | CvMat *Imag; 75 | CvMat *Real; 76 | private: 77 | void creat_kernel(); 78 | 79 | }; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/itti/gabor.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2006 by Mian Zhou * 3 | * M.Zhou@reading.ac.uk * 4 | * * 5 | * This program is free software; you can redistribute it and/or modify * 6 | * it under the terms of the GNU General Public License as published by * 7 | * the Free Software Foundation; either version 2 of the License, or * 8 | * (at your option) any later version. * 9 | * * 10 | * This program is distributed in the hope that it will be useful, * 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 | * GNU General Public License for more details. * 14 | * * 15 | * You should have received a copy of the GNU General Public License * 16 | * along with this program; if not, write to the * 17 | * Free Software Foundation, Inc., * 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 | ***************************************************************************/ 20 | #include "cvgabor.h" 21 | 22 | #undef DEBUG 23 | //#define DEBUG 24 | CvGabor::CvGabor() 25 | { 26 | } 27 | 28 | 29 | CvGabor::~CvGabor() 30 | { 31 | cvReleaseMat(&Real); 32 | cvReleaseMat(&Imag); 33 | } 34 | 35 | 36 | /*! 37 | \fn CvGabor::CvGabor(int iMu, int iNu) 38 | Construct a gabor 39 | 40 | Parameters: 41 | iMu The orientation iMu*PI/8, 42 | iNu The scale, 43 | 44 | Returns: 45 | None, 46 | 47 | Create a gabor with a orientation iMu*PI/8, and with a scale iNu. The sigma (Sigma) and the spatial frequence (F) are set to 2*PI and sqrt(2) defaultly. It calls Init() to generate parameters and kernels. 48 | */ 49 | CvGabor::CvGabor(int iMu, int iNu) 50 | { 51 | //Initilise the parameters 52 | 53 | Sigma = 2 * PI; 54 | F = sqrt(2.0); 55 | Init(iMu, iNu, Sigma, F); 56 | 57 | } 58 | 59 | /*! 60 | \fn CvGabor::CvGabor(int iMu, int iNu, double dSigma) 61 | Construct a gabor 62 | 63 | Parameters: 64 | iMu The orientation iMu*PI/8, 65 | iNu The scale, 66 | dSigma The sigma value of Gabor, 67 | 68 | Returns: 69 | None 70 | 71 | Create a gabor with a orientation iMu*PI/8, a scale iNu, and a sigma value dSigma. The spatial frequence (F) is set to sqrt(2) defaultly. It calls Init() to generate parameters and kernels. 72 | */ 73 | CvGabor::CvGabor(int iMu, int iNu, float dSigma) 74 | { 75 | F = sqrt(2.0); 76 | Init(iMu, iNu, dSigma, F); 77 | } 78 | 79 | 80 | /*! 81 | \fn CvGabor::CvGabor(int iMu, int iNu, double dSigma, double dF) 82 | Construct a gabor 83 | 84 | Parameters: 85 | iMu The orientation iMu*PI/8 86 | iNu The scale 87 | dSigma The sigma value of Gabor 88 | dF The spatial frequency 89 | 90 | Returns: 91 | None 92 | 93 | Create a gabor with a orientation iMu*PI/8, a scale iNu, a sigma value dSigma, and a spatial frequence dF. It calls Init() to generate parameters and kernels. 94 | */ 95 | CvGabor::CvGabor(int iMu, int iNu, float dSigma, float dF) 96 | { 97 | 98 | Init(iMu, iNu, dSigma, dF); 99 | 100 | } 101 | 102 | 103 | /*! 104 | \fn CvGabor::CvGabor(double dPhi, int iNu) 105 | Construct a gabor 106 | 107 | Parameters: 108 | dPhi The orientation in arc 109 | iNu The scale 110 | 111 | Returns: 112 | None 113 | 114 | Create a gabor with a orientation dPhi, and with a scale iNu. The sigma (Sigma) and the spatial frequence (F) are set to 2*PI and sqrt(2) defaultly. It calls Init() to generate parameters and kernels. 115 | */ 116 | CvGabor::CvGabor(float dPhi, int iNu) 117 | { 118 | 119 | Sigma = 2 * PI; 120 | F = sqrt(2.0); 121 | Init(dPhi, iNu, Sigma, F); 122 | } 123 | 124 | 125 | /*! 126 | \fn CvGabor::CvGabor(double dPhi, int iNu, double dSigma) 127 | Construct a gabor 128 | 129 | Parameters: 130 | dPhi The orientation in arc 131 | iNu The scale 132 | dSigma The sigma value of Gabor 133 | 134 | Returns: 135 | None 136 | 137 | Create a gabor with a orientation dPhi, a scale iNu, and a sigma value dSigma. The spatial frequence (F) is set to sqrt(2) defaultly. It calls Init() to generate parameters and kernels. 138 | */ 139 | CvGabor::CvGabor(float dPhi, int iNu, float dSigma) 140 | { 141 | 142 | F = sqrt(2.0); 143 | Init(dPhi, iNu, dSigma, F); 144 | } 145 | 146 | 147 | /*! 148 | \fn CvGabor::CvGabor(double dPhi, int iNu, double dSigma, double dF) 149 | Construct a gabor 150 | 151 | Parameters: 152 | dPhi The orientation in arc 153 | iNu The scale 154 | dSigma The sigma value of Gabor 155 | dF The spatial frequency 156 | 157 | Returns: 158 | None 159 | 160 | Create a gabor with a orientation dPhi, a scale iNu, a sigma value dSigma, and a spatial frequence dF. It calls Init() to generate parameters and kernels. 161 | */ 162 | CvGabor::CvGabor(float dPhi, int iNu, float dSigma, float dF) 163 | { 164 | 165 | Init(dPhi, iNu, dSigma, dF); 166 | } 167 | 168 | /*! 169 | \fn CvGabor::IsInit() 170 | Determine the gabor is initilised or not 171 | 172 | Parameters: 173 | None 174 | 175 | Returns: 176 | a boolean value, TRUE is initilised or FALSE is non-initilised. 177 | 178 | Determine whether the gabor has been initlized - variables F, K, Kmax, Phi, Sigma are filled. 179 | */ 180 | bool CvGabor::IsInit() 181 | { 182 | 183 | return bInitialised; 184 | } 185 | 186 | /*! 187 | \fn CvGabor::mask_width() 188 | Give out the width of the mask 189 | 190 | Parameters: 191 | None 192 | 193 | Returns: 194 | The long type show the width. 195 | 196 | Return the width of mask (should be NxN) by the value of Sigma and iNu. 197 | */ 198 | long CvGabor::mask_width() 199 | { 200 | 201 | long lWidth; 202 | if (IsInit() == FALSE) { 203 | perror("Error: The Object has not been initilised in mask_width()!\n"); 204 | return 0; 205 | } 206 | else { 207 | //determine the width of Mask 208 | float dModSigma = Sigma / K; 209 | float dWidth = cvRound(dModSigma * 6 + 1); 210 | //test whether dWidth is an odd. 211 | if (fmod(dWidth, (float)2.0) == 0.0) dWidth++; 212 | lWidth = (long)dWidth; 213 | 214 | return lWidth; 215 | } 216 | } 217 | 218 | 219 | /*! 220 | \fn CvGabor::creat_kernel() 221 | Create gabor kernel 222 | 223 | Parameters: 224 | None 225 | 226 | Returns: 227 | None 228 | 229 | Create 2 gabor kernels - REAL and IMAG, with an orientation and a scale 230 | */ 231 | void CvGabor::creat_kernel() 232 | { 233 | 234 | 235 | { 236 | CvMat *mReal, *mImag; 237 | mReal = cvCreateMat(Width, Width, CV_32FC1); 238 | mImag = cvCreateMat(Width, Width, CV_32FC1); 239 | 240 | /**************************** Gabor Function ****************************/ 241 | int x, y; 242 | float dReal; 243 | float dImag; 244 | float dTemp1, dTemp2, dTemp3; 245 | 246 | for (int i = 0; i < Width; i++) 247 | { 248 | for (int j = 0; j < Width; j++) 249 | { 250 | x = i - (Width - 1) / 2; 251 | y = j - (Width - 1) / 2; 252 | dTemp1 = (pow(K, 2) / pow(Sigma, 2))*exp(-(pow((float)x, 2) + pow((float)y, 2))*pow(K, 2) / (2 * pow(Sigma, 2))); 253 | dTemp2 = cos(K*cos(Phi)*x + K*sin(Phi)*y) - exp(-(pow(Sigma, 2) / 2)); 254 | dTemp3 = sin(K*cos(Phi)*x + K*sin(Phi)*y); 255 | dReal = dTemp1*dTemp2; 256 | dImag = dTemp1*dTemp3; 257 | //gan_mat_set_el(pmReal, i, j, dReal); 258 | cvmSet((CvMat*)mReal, i, j, dReal); 259 | //gan_mat_set_el(pmImag, i, j, dImag); 260 | cvmSet((CvMat*)mImag, i, j, dImag); 261 | 262 | } 263 | } 264 | /**************************** Gabor Function ****************************/ 265 | bKernel = TRUE; 266 | cvCopy(mReal, Real, NULL); 267 | cvCopy(mImag, Imag, NULL); 268 | 269 | cvReleaseMat(&mReal); 270 | cvReleaseMat(&mImag); 271 | } 272 | } 273 | 274 | 275 | /*! 276 | \fn CvGabor::get_image(int Type) 277 | Get the speific type of image of Gabor 278 | 279 | Parameters: 280 | Type The Type of gabor kernel, e.g. REAL, IMAG, MAG, PHASE 281 | 282 | Returns: 283 | Pointer to image structure, or NULL on failure 284 | 285 | Return an Image (gandalf image class) with a specific Type "REAL" "IMAG" "MAG" "PHASE" 286 | */ 287 | IplImage* CvGabor::get_image(int Type) 288 | { 289 | 290 | if (IsKernelCreate() == FALSE) 291 | { 292 | perror("Error: the Gabor kernel has not been created in get_image()!\n"); 293 | return NULL; 294 | } 295 | else 296 | { 297 | IplImage* pImage; 298 | IplImage *newimage; 299 | newimage = cvCreateImage(cvSize(Width, Width), IPL_DEPTH_8U, 1); 300 | //printf("Width is %d.\n",(int)Width); 301 | //printf("Sigma is %f.\n", Sigma); 302 | //printf("F is %f.\n", F); 303 | //printf("Phi is %f.\n", Phi); 304 | 305 | //pImage = gan_image_alloc_gl_d(Width, Width); 306 | pImage = cvCreateImage(cvSize(Width, Width), IPL_DEPTH_32F, 1); 307 | 308 | 309 | CvMat* kernel = cvCreateMat(Width, Width, CV_32FC1); 310 | double ve; 311 | switch (Type) 312 | { 313 | case 1: //Real 314 | 315 | cvCopy((CvMat*)Real, (CvMat*)kernel, NULL); 316 | //pImage = cvGetImage( (CvMat*)kernel, pImageGL ); 317 | for (int i = 0; i < kernel->rows; i++) 318 | { 319 | for (int j = 0; j < kernel->cols; j++) 320 | { 321 | ve = cvGetReal2D((CvMat*)kernel, i, j); 322 | cvSetReal2D((IplImage*)pImage, j, i, ve); 323 | } 324 | } 325 | break; 326 | case 2: //Imag 327 | cvCopy((CvMat*)Imag, (CvMat*)kernel, NULL); 328 | //pImage = cvGetImage( (CvMat*)kernel, pImageGL ); 329 | for (int i = 0; i < kernel->rows; i++) 330 | { 331 | for (int j = 0; j < kernel->cols; j++) 332 | { 333 | ve = cvGetReal2D((CvMat*)kernel, i, j); 334 | cvSetReal2D((IplImage*)pImage, j, i, ve); 335 | } 336 | } 337 | break; 338 | case 3: //Magnitude 339 | ///@todo 340 | break; 341 | case 4: //Phase 342 | ///@todo 343 | break; 344 | } 345 | 346 | cvNormalize((IplImage*)pImage, (IplImage*)pImage, 0, 255, CV_MINMAX, NULL); 347 | 348 | 349 | cvConvertScaleAbs((IplImage*)pImage, (IplImage*)newimage, 1, 0); 350 | 351 | cvReleaseMat(&kernel); 352 | 353 | cvReleaseImage(&pImage); 354 | 355 | return newimage; 356 | } 357 | } 358 | 359 | 360 | /*! 361 | \fn CvGabor::IsKernelCreate() 362 | Determine the gabor kernel is created or not 363 | 364 | Parameters: 365 | None 366 | 367 | Returns: 368 | a boolean value, TRUE is created or FALSE is non-created. 369 | 370 | Determine whether a gabor kernel is created. 371 | */ 372 | bool CvGabor::IsKernelCreate() 373 | { 374 | 375 | return bKernel; 376 | } 377 | 378 | 379 | /*! 380 | \fn CvGabor::get_mask_width() 381 | Reads the width of Mask 382 | 383 | Parameters: 384 | None 385 | 386 | Returns: 387 | Pointer to long type width of mask. 388 | */ 389 | long CvGabor::get_mask_width() 390 | { 391 | return Width; 392 | } 393 | 394 | 395 | /*! 396 | \fn CvGabor::Init(int iMu, int iNu, double dSigma, double dF) 397 | Initilize the.gabor 398 | 399 | Parameters: 400 | iMu The orientations which is iMu*PI.8 401 | iNu The scale can be from -5 to infinit 402 | dSigma The Sigma value of gabor, Normally set to 2*PI 403 | dF The spatial frequence , normally is sqrt(2) 404 | 405 | Returns: 406 | 407 | Initilize the.gabor with the orientation iMu, the scale iNu, the sigma dSigma, the frequency dF, it will call the function creat_kernel(); So a gabor is created. 408 | */ 409 | void CvGabor::Init(int iMu, int iNu, double dSigma, double dF) 410 | { 411 | //Initilise the parameters 412 | bInitialised = FALSE; 413 | bKernel = FALSE; 414 | 415 | Sigma = dSigma; 416 | F = dF; 417 | 418 | Kmax = PI / 2; 419 | 420 | // Absolute value of K 421 | K = Kmax / pow(F, (float)iNu); 422 | Phi = PI*iMu / 8; 423 | bInitialised = TRUE; 424 | Width = mask_width(); 425 | Real = cvCreateMat(Width, Width, CV_32FC1); 426 | Imag = cvCreateMat(Width, Width, CV_32FC1); 427 | creat_kernel(); 428 | } 429 | 430 | 431 | /*! 432 | \fn CvGabor::Init(double dPhi, int iNu, double dSigma, double dF) 433 | Initilize the.gabor 434 | 435 | Parameters: 436 | dPhi The orientations 437 | iNu The scale can be from -5 to infinit 438 | dSigma The Sigma value of gabor, Normally set to 2*PI 439 | dF The spatial frequence , normally is sqrt(2) 440 | 441 | Returns: 442 | None 443 | 444 | Initilize the.gabor with the orientation dPhi, the scale iNu, the sigma dSigma, the frequency dF, it will call the function creat_kernel(); So a gabor is created.filename The name of the image file 445 | file_format The format of the file, e.g. GAN_PNG_FORMAT 446 | image The image structure to be written to the file 447 | octrlstr Format-dependent control structure 448 | 449 | */ 450 | void CvGabor::Init(double dPhi, int iNu, double dSigma, double dF) 451 | { 452 | 453 | bInitialised = FALSE; 454 | bKernel = FALSE; 455 | Sigma = dSigma; 456 | F = dF; 457 | 458 | Kmax = PI / 2; 459 | 460 | // Absolute value of K 461 | K = Kmax / pow(F, (float)iNu); 462 | Phi = dPhi; 463 | bInitialised = TRUE; 464 | Width = mask_width(); 465 | Real = cvCreateMat(Width, Width, CV_32FC1); 466 | Imag = cvCreateMat(Width, Width, CV_32FC1); 467 | creat_kernel(); 468 | } 469 | 470 | 471 | 472 | /*! 473 | \fn CvGabor::get_matrix(int Type) 474 | Get a matrix by the type of kernel 475 | 476 | Parameters: 477 | Type The type of kernel, e.g. REAL, IMAG, MAG, PHASE 478 | 479 | Returns: 480 | Pointer to matrix structure, or NULL on failure. 481 | 482 | Return the gabor kernel. 483 | */ 484 | CvMat* CvGabor::get_matrix(int Type) 485 | { 486 | if (!IsKernelCreate()) { perror("Error: the gabor kernel has not been created!\n"); return NULL; } 487 | switch (Type) 488 | { 489 | case CV_GABOR_REAL: 490 | return Real; 491 | break; 492 | case CV_GABOR_IMAG: 493 | return Imag; 494 | break; 495 | case CV_GABOR_MAG: 496 | return NULL; 497 | break; 498 | case CV_GABOR_PHASE: 499 | return NULL; 500 | break; 501 | } 502 | return NULL; 503 | } 504 | 505 | 506 | 507 | 508 | /*! 509 | \fn CvGabor::output_file(const char *filename, Gan_ImageFileFormat file_format, int Type) 510 | Writes a gabor kernel as an image file. 511 | 512 | Parameters: 513 | filename The name of the image file 514 | file_format The format of the file, e.g. GAN_PNG_FORMAT 515 | Type The Type of gabor kernel, e.g. REAL, IMAG, MAG, PHASE 516 | Returns: 517 | None 518 | 519 | Writes an image from the provided image structure into the given file and the type of gabor kernel. 520 | */ 521 | void CvGabor::output_file(const char *filename, int Type) 522 | { 523 | IplImage *pImage; 524 | pImage = get_image(Type); 525 | if (pImage != NULL) 526 | { 527 | if (cvSaveImage(filename, pImage)) printf("%s has been written successfully!\n", filename); 528 | else printf("Error: writting %s has failed!\n", filename); 529 | } 530 | else 531 | perror("Error: the image is empty in output_file()!\n"); 532 | 533 | cvReleaseImage(&pImage); 534 | } 535 | 536 | 537 | 538 | 539 | 540 | 541 | /*! 542 | \fn CvGabor::show(int Type) 543 | */ 544 | void CvGabor::show(int Type) 545 | { 546 | if (!IsInit()) { 547 | perror("Error: the gabor kernel has not been created!\n"); 548 | } 549 | else { 550 | IplImage *pImage; 551 | pImage = get_image(Type); 552 | cvNamedWindow("Testing", 1); 553 | cvShowImage("Testing", pImage); 554 | cvWaitKey(0); 555 | cvDestroyWindow("Testing"); 556 | cvReleaseImage(&pImage); 557 | } 558 | 559 | } 560 | 561 | 562 | 563 | 564 | /*! 565 | \fn CvGabor::conv_img(IplImage *src, IplImage *dst, int Type) 566 | */ 567 | void CvGabor::conv_img(IplImage *src, IplImage *dst, int Type) 568 | { 569 | double ve, re, im; 570 | 571 | CvMat *mat = cvCreateMat(src->width, src->height, CV_32FC1); 572 | for (int i = 0; i < src->width; i++) 573 | { 574 | for (int j = 0; j < src->height; j++) 575 | { 576 | ve = cvGetReal2D((IplImage*)src, j, i); 577 | cvSetReal2D((CvMat*)mat, i, j, ve); 578 | } 579 | } 580 | 581 | CvMat *rmat = cvCreateMat(src->width, src->height, CV_32FC1); 582 | CvMat *imat = cvCreateMat(src->width, src->height, CV_32FC1); 583 | 584 | CvMat *kernel = cvCreateMat(Width, Width, CV_32FC1); 585 | 586 | switch (Type) 587 | { 588 | case CV_GABOR_REAL: 589 | cvCopy((CvMat*)Real, (CvMat*)kernel, NULL); 590 | cvFilter2D((CvMat*)mat, (CvMat*)mat, (CvMat*)kernel, cvPoint((Width - 1) / 2, (Width - 1) / 2)); 591 | break; 592 | case CV_GABOR_IMAG: 593 | cvCopy((CvMat*)Imag, (CvMat*)kernel, NULL); 594 | cvFilter2D((CvMat*)mat, (CvMat*)mat, (CvMat*)kernel, cvPoint((Width - 1) / 2, (Width - 1) / 2)); 595 | break; 596 | case CV_GABOR_MAG: 597 | /* Real Response */ 598 | cvCopy((CvMat*)Real, (CvMat*)kernel, NULL); 599 | cvFilter2D((CvMat*)mat, (CvMat*)rmat, (CvMat*)kernel, cvPoint((Width - 1) / 2, (Width - 1) / 2)); 600 | /* Imag Response */ 601 | cvCopy((CvMat*)Imag, (CvMat*)kernel, NULL); 602 | cvFilter2D((CvMat*)mat, (CvMat*)imat, (CvMat*)kernel, cvPoint((Width - 1) / 2, (Width - 1) / 2)); 603 | /* Magnitude response is the square root of the sum of the square of real response and imaginary response */ 604 | for (int i = 0; i < mat->rows; i++) 605 | { 606 | for (int j = 0; j < mat->cols; j++) 607 | { 608 | re = cvGetReal2D((CvMat*)rmat, i, j); 609 | im = cvGetReal2D((CvMat*)imat, i, j); 610 | ve = sqrt(re*re + im*im); 611 | cvSetReal2D((CvMat*)mat, i, j, ve); 612 | } 613 | } 614 | break; 615 | case CV_GABOR_PHASE: 616 | break; 617 | } 618 | 619 | if (dst->depth == IPL_DEPTH_8U) 620 | { 621 | cvNormalize((CvMat*)mat, (CvMat*)mat, 0, 255, CV_MINMAX); 622 | for (int i = 0; i < mat->rows; i++) 623 | { 624 | for (int j = 0; j < mat->cols; j++) 625 | { 626 | ve = cvGetReal2D((CvMat*)mat, i, j); 627 | ve = cvRound(ve); 628 | cvSetReal2D((IplImage*)dst, j, i, ve); 629 | } 630 | } 631 | } 632 | 633 | if (dst->depth == IPL_DEPTH_32F) 634 | { 635 | for (int i = 0; i < mat->rows; i++) 636 | { 637 | for (int j = 0; j < mat->cols; j++) 638 | { 639 | ve = cvGetReal2D((CvMat*)mat, i, j); 640 | cvSetReal2D((IplImage*)dst, j, i, ve); 641 | } 642 | } 643 | } 644 | 645 | cvReleaseMat(&kernel); 646 | cvReleaseMat(&imat); 647 | cvReleaseMat(&rmat); 648 | cvReleaseMat(&mat); 649 | } 650 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/itti/itti.cpp: -------------------------------------------------------------------------------- 1 | #include "cvgabor.h" 2 | #include "itti.h" 3 | #include "opencv2/core/core.hpp" 4 | #include "opencv2/core/utility.hpp" 5 | #include "opencv2/imgproc/imgproc.hpp" 6 | #include "opencv2/imgcodecs.hpp" 7 | #include "opencv2/highgui/highgui.hpp" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | void ITTI::calculateSaliencyMap(const Mat* src, Mat* dst, int corlor, int scaleBase) 15 | { 16 | createChannels(src);//Create a pyramid for 9 layers.The top is same as src img 17 | createIntensityFeatureMaps(); //intensity feature 18 | if (corlor) 19 | createColorFeatureMaps(); //corlor 20 | createOrientationFeatureMaps(0); //orientation 21 | createOrientationFeatureMaps(2); 22 | createOrientationFeatureMaps(4); 23 | createOrientationFeatureMaps(6); 24 | combineFeatureMaps(corlor, scaleBase); 25 | resize(S, *dst, src->size(), 0, 0, INTER_LINEAR); 26 | //viewFeaturemaps(); 27 | clearBuffers(); 28 | } 29 | 30 | void ITTI::createChannels(const Mat* src) 31 | { 32 | b.create(src->size(), CV_32F); 33 | g.create(src->size(), CV_32F); 34 | r.create(src->size(), CV_32F); 35 | I.create(src->size(), CV_32F); 36 | vector planes; 37 | split(*src, planes); 38 | 39 | for (int j = 0; j(j, i) = planes[0].at(j, i); 43 | g.at(j, i) = planes[1].at(j, i); 44 | r.at(j, i) = planes[2].at(j, i); 45 | } 46 | 47 | I = r + g + b; 48 | I = I / 3; 49 | 50 | normalize_rgb(); 51 | create_RGBY(); 52 | createScaleSpace(&I, &gaussianPyramid_I, 8); 53 | createScaleSpace(&R, &gaussianPyramid_R, 8); 54 | createScaleSpace(&G, &gaussianPyramid_G, 8); 55 | createScaleSpace(&B, &gaussianPyramid_B, 8); 56 | createScaleSpace(&Y, &gaussianPyramid_Y, 8); 57 | } 58 | 59 | /*r,g and b channels are normalized by I in order to decouple hue from intensity 60 | Because hue variations are not perceivable at very low luminance normalization is only applied at the locations 61 | where I is larger than max(I)/10 (other locations yield zero r,g,b)*/ 62 | void ITTI::normalize_rgb() 63 | { 64 | double minVal, maxVal; 65 | minMaxLoc(I, &minVal, &maxVal); 66 | Mat mask_I; 67 | cv::threshold(I, mask_I, maxVal / 10, 1.0, THRESH_BINARY); 68 | 69 | r = r / I; 70 | g = g / I; 71 | b = b / I; 72 | r = r.mul(mask_I); 73 | g = g.mul(mask_I); 74 | b = b.mul(mask_I); 75 | } 76 | 77 | void ITTI::create_RGBY() 78 | { 79 | Mat gb = g + b; 80 | Mat rb = r + b; 81 | Mat rg = r + g; 82 | Mat rg_ = r - g; 83 | 84 | R = r - gb / 2; 85 | G = g - rb / 2; 86 | B = b - rg / 2; 87 | Y = rg / 2 - abs(rg_ / 2) - b; 88 | 89 | Mat mask; 90 | threshold(R, mask, 0.0, 1.0, THRESH_BINARY); 91 | R = R.mul(mask); 92 | threshold(G, mask, 0.0, 1.0, THRESH_BINARY); 93 | G = G.mul(mask); 94 | threshold(B, mask, 0.0, 1.0, THRESH_BINARY); 95 | B = B.mul(mask); 96 | threshold(Y, mask, 0.0, 1.0, THRESH_BINARY); 97 | Y = Y.mul(mask); 98 | } 99 | 100 | void ITTI::createScaleSpace(const Mat* src, vector* dst, int scale) 101 | { 102 | buildPyramid(*src, *dst, scale); 103 | } 104 | 105 | void ITTI::createIntensityFeatureMaps() 106 | { //result is featureMaps_I,for 6 channels of coares to fine diffren img, size of them is equal to 2 2 3 3 4 4 layer for the gaussian pyrmid 107 | int fineScaleNumber = 3; 108 | int scaleDiff = 2; 109 | int c[3] = { 2, 3, 4 }; 110 | int delta[2] = { 3, 4 }; 111 | 112 | for (int scaleIndex = 0; scaleIndex < fineScaleNumber; scaleIndex++) //for the intensity layer 2 3 4 113 | { 114 | Mat fineScaleImage = gaussianPyramid_I.at(c[scaleIndex]); 115 | Size fineScaleImageSize = fineScaleImage.size(); 116 | 117 | for (int scaleDiffIndex = 0; scaleDiffIndexconv_img(&src_fineScaleImage, gbr_fineScaleImage, CV_GABOR_REAL); 187 | Mat src_responseImg = cvarrToMat(gbr_fineScaleImage); 188 | 189 | for (int scaleDiffIndex = 0; scaleDiffIndexconv_img(&src_coarseScaleImage, gbr_coarseScaleImage, CV_GABOR_REAL); 196 | Mat coarse_responseImg = cvarrToMat(gbr_coarseScaleImage); 197 | 198 | Mat coarseScaleImageUp; 199 | resize(coarse_responseImg, coarseScaleImageUp, fineScaleImageSize, 0, 0, INTER_LINEAR); 200 | 201 | Mat temp = abs(src_responseImg - coarseScaleImageUp); 202 | Mat O_cs(temp.size(), CV_32F); 203 | 204 | for (int j = 0; j(j, i) = temp.at(j, i); 207 | 208 | if (orientation == 0) 209 | featureMaps_0.push_back(O_cs); 210 | if (orientation == 2) 211 | featureMaps_45.push_back(O_cs); 212 | if (orientation == 4) 213 | featureMaps_90.push_back(O_cs); 214 | if (orientation == 6) 215 | featureMaps_135.push_back(O_cs); 216 | 217 | cvReleaseImage(&gbr_coarseScaleImage); 218 | } 219 | cvReleaseImage(&gbr_fineScaleImage); 220 | } 221 | } 222 | 223 | void ITTI::combineFeatureMaps(int corlor, int scale) 224 | { 225 | Size scaleImageSize = gaussianPyramid_I.at(scale).size(); 226 | conspicuityMap_I.create(scaleImageSize, CV_32F); conspicuityMap_I.setTo(0); 227 | if ( corlor) 228 | conspicuityMap_C.create(scaleImageSize, CV_32F); conspicuityMap_C.setTo(0); 229 | conspicuityMap_O.create(scaleImageSize, CV_32F); conspicuityMap_O.setTo(0); 230 | Mat ori_0(scaleImageSize, CV_32F); ori_0.setTo(0); 231 | Mat ori_45(scaleImageSize, CV_32F); ori_45.setTo(0); 232 | Mat ori_90(scaleImageSize, CV_32F); ori_90.setTo(0); 233 | Mat ori_135(scaleImageSize, CV_32F); ori_135.setTo(0); 234 | 235 | Mat featureMap, featureMap_scaled, RG, BY, RG_scaled, BY_scaled; 236 | 237 | for (int index = 0; index<3 * 2; index++) 238 | { 239 | resize(featureMaps_I.at(index), featureMap_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 240 | mapNormalization(&featureMap_scaled); 241 | conspicuityMap_I = conspicuityMap_I + featureMap_scaled; 242 | if (corlor) 243 | { 244 | resize(featureMaps_RG.at(index), RG_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 245 | resize(featureMaps_BY.at(index), BY_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 246 | mapNormalization(&RG_scaled); 247 | mapNormalization(&BY_scaled); 248 | conspicuityMap_C = conspicuityMap_C + (RG_scaled + BY_scaled); 249 | } 250 | resize(featureMaps_0.at(index), featureMap_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 251 | mapNormalization(&featureMap_scaled); 252 | ori_0 = ori_0 + featureMap_scaled; 253 | resize(featureMaps_45.at(index), featureMap_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 254 | mapNormalization(&featureMap_scaled); 255 | ori_45 = ori_45 + featureMap_scaled; 256 | resize(featureMaps_90.at(index), featureMap_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 257 | mapNormalization(&featureMap_scaled); 258 | ori_90 = ori_90 + featureMap_scaled; 259 | resize(featureMaps_135.at(index), featureMap_scaled, scaleImageSize, 0, 0, INTER_LINEAR); 260 | mapNormalization(&featureMap_scaled); 261 | ori_135 = ori_135 + featureMap_scaled; 262 | } 263 | 264 | mapNormalization(&ori_0); 265 | mapNormalization(&ori_45); 266 | mapNormalization(&ori_90); 267 | mapNormalization(&ori_135); 268 | conspicuityMap_O = ori_0 + ori_45 + ori_90 + ori_135; 269 | 270 | mapNormalization(&conspicuityMap_I); 271 | if (corlor) mapNormalization(&conspicuityMap_C); 272 | mapNormalization(&conspicuityMap_O); 273 | /*imshow("conspicuityMap_I", conspicuityMap_I); 274 | imshow("conspicuityMap_O", conspicuityMap_O);*/ 275 | if (corlor) { S = conspicuityMap_I + conspicuityMap_C + conspicuityMap_O; S = S / 3; } 276 | else 277 | { 278 | S = conspicuityMap_I + conspicuityMap_O; 279 | S = S / 2; 280 | } 281 | } 282 | void ITTI::mapNormalization(Mat* src) 283 | { 284 | double minVal, maxVal; 285 | minMaxLoc(*src, &minVal, &maxVal); 286 | *src = *src / (float)maxVal; 287 | } 288 | 289 | void ITTI::clearBuffers() 290 | { 291 | gaussianPyramid_I.clear(); 292 | gaussianPyramid_R.clear(); 293 | gaussianPyramid_G.clear(); 294 | gaussianPyramid_B.clear(); 295 | gaussianPyramid_Y.clear(); 296 | featureMaps_I.clear(); 297 | featureMaps_RG.clear(); 298 | featureMaps_BY.clear(); 299 | featureMaps_0.clear(); 300 | featureMaps_45.clear(); 301 | featureMaps_90.clear(); 302 | featureMaps_135.clear(); 303 | } 304 | void ITTI::viewFeaturemaps() 305 | { 306 | char str[25]; 307 | for (int i = 0; i < featureMaps_I.size(); i++) 308 | { 309 | _itoa_s(i, str, 10); 310 | string name = "featureMaps_I"; name+=str; 311 | imshow(name, featureMaps_I.at(i)/255); 312 | } 313 | for (int i = 0; i < featureMaps_RG.size(); i++) 314 | { 315 | _itoa_s(i, str, 10); 316 | string name = "featureMaps_RG"; name += str; 317 | imshow(name, featureMaps_RG.at(i)/255); 318 | } 319 | for (int i = 0; i < featureMaps_0.size(); i++) 320 | { 321 | _itoa_s(i, str, 10); 322 | string name = "featureMaps_0"; name += str; 323 | imshow(name, featureMaps_0.at(i)/255); 324 | } 325 | 326 | 327 | } -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/sample.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/sample.bmp -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/tiger.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/tiger.jpg -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/AC.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/AC.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/ApplySaliencyToSurfaceInspection.lastbuildstate: -------------------------------------------------------------------------------- 1 | #TargetFrameworkVersion=v4.0:PlatformToolSet=v120:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit 2 | Release|x64|E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\| 3 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/CL.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/CL.read.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/CL.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/CL.write.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/cl.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/cl.command.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.command.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.command.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.read.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.read.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.write.1.tlog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/ApplySal.DCC3BB1D.tlog/link.write.1.tlog -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySaliencyToSurfaceInspection.Build.CppClean.log: -------------------------------------------------------------------------------- 1 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\vc120.pdb 2 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\sr.obj 3 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\saliencydetectionrudinac.obj 4 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\itti.obj 5 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\gabor.obj 6 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\slic.obj 7 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\gmr.obj 8 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\segment-image.obj 9 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\rc.obj 10 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\lc.obj 11 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\hc.obj 12 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demo.obj 13 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\mbp.obj 14 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\mss.obj 15 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\ft.obj 16 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\ac.obj 17 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\sun.obj 18 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\entropyfil.obj 19 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demoofpaper22_oilpullution.obj 20 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demoharris.obj 21 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demoharrislikesaliency.obj 22 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demophot.obj 23 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\mydemoofsaliency.obj 24 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\demorundatasets.obj 25 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\phot.obj 26 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\testifallthejobisreadyforevaluate.obj 27 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\bms.obj 28 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\superpixel.obj 29 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\permutohedral.obj 30 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\filter.obj 31 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\saliency.obj 32 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\sf.obj 33 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\x64\release\applysaliencytosurfaceinspection.exe 34 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\x64\release\applysaliencytosurfaceinspection.pdb 35 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\cl.command.1.tlog 36 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\cl.read.1.tlog 37 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\cl.write.1.tlog 38 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\link.command.1.tlog 39 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\link.read.1.tlog 40 | e:\datasets\saliecydataset\applysaliencytosurfaceinspection\applysaliencytosurfaceinspection\x64\release\applysal.dcc3bb1d.tlog\link.write.1.tlog 41 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/ApplySaliencyToSurfaceInspection.log: -------------------------------------------------------------------------------- 1 | 生成启动时间为 2018/2/24 17:00:16。 2 | 1>项目“E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\ApplySaliencyToSurfaceInspection\ApplySaliencyToSurfaceInspection.vcxproj”在节点 2 上(Build 个目标)。 3 | 1>ClCompile: 4 | D:\win10Bigsoftwares\vs2013\VC\bin\x86_amd64\CL.exe /c /Zi /nologo /W3 /WX- /sdl /MP /O2 /Oi /GL /D WIN32 /D NDEBUG /D _CONSOLE /D _LIB /D _MBCS /Gm- /EHsc /MD /GS /Gy /Qpar /fp:precise /Zc:wchar_t /Zc:forScope /Fo"x64\Release\\" /Fd"x64\Release\vc120.pdb" /Gd /TP /errorReport:prompt DemoRunDatasets.cpp 5 | DemoRunDatasets.cpp 6 | 1>G:\opencv31\opencv\build\include\opencv2/core/mat.hpp(1965): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 7 | 1>G:\opencv31\opencv\build\include\opencv2/core/persistence.hpp : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 8 | 1>G:\opencv31\opencv\build\include\opencv2/core/utility.hpp : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 9 | 1>DemoRunDatasets.cpp(75): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 10 | 1>DemoRunDatasets.cpp(76): warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据 11 | 1>DemoRunDatasets.cpp(108): warning C4267: “=”: 从“size_t”转换到“int”,可能丢失数据 12 | 1>DemoRunDatasets.cpp(112): warning C4267: “=”: 从“size_t”转换到“int”,可能丢失数据 13 | Link: 14 | D:\win10Bigsoftwares\vs2013\VC\bin\x86_amd64\link.exe /ERRORREPORT:PROMPT /OUT:"E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\x64\Release\ApplySaliencyToSurfaceInspection.exe" /INCREMENTAL /NOLOGO opencv_world310.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\x64\Release\ApplySaliencyToSurfaceInspection.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\x64\Release\ApplySaliencyToSurfaceInspection.lib" /MACHINE:X64 x64\Release\AC.obj 15 | x64\Release\BMS.obj 16 | x64\Release\DemoRunDatasets.obj 17 | x64\Release\FT.obj 18 | x64\Release\GMR.obj 19 | x64\Release\SLIC.obj 20 | x64\Release\HC.obj 21 | x64\Release\gabor.obj 22 | x64\Release\itti.obj 23 | x64\Release\LC.obj 24 | x64\Release\MBP.obj 25 | x64\Release\MSS.obj 26 | x64\Release\PHOT.obj 27 | x64\Release\RC.obj 28 | "x64\Release\segment-image.obj" 29 | x64\Release\saliencyDetectionRudinac.obj 30 | x64\Release\filter.obj 31 | x64\Release\permutohedral.obj 32 | x64\Release\SF.obj 33 | x64\Release\superpixel.obj 34 | x64\Release\SR.obj 35 | 1>LINK : warning LNK4075: 忽略“/INCREMENTAL”(由于“/LTCG”规范) 36 | 正在生成代码 37 | 已完成代码的生成 38 | ApplySaliencyToSurfaceInspection.vcxproj -> E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\x64\Release\ApplySaliencyToSurfaceInspection.exe 39 | 1>已完成生成项目“E:\datasets\SaliecyDataset\ApplySaliencyToSurfaceInspection\ApplySaliencyToSurfaceInspection\ApplySaliencyToSurfaceInspection.vcxproj”(Build 个目标)的操作。 40 | 41 | 生成成功。 42 | 43 | 已用时间 00:00:05.34 44 | -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/BMS.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/BMS.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/DemoRunDatasets.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/DemoRunDatasets.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/FT.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/FT.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/GMR.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/GMR.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/HC.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/HC.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/LC.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/LC.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/MBP.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/MBP.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/MSS.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/MSS.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/McueSalTest.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/McueSalTest.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/MyDemoOfSaliency.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/MyDemoOfSaliency.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/PHOT.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/PHOT.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/RC.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/RC.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/SF.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/SF.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/SLIC.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/SLIC.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/SR.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/SR.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/demoBMS.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/demoBMS.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/filter.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/filter.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/gabor.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/gabor.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/itti.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/itti.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/permutohedral.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/permutohedral.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/saliencyDetectionRudinac.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/saliencyDetectionRudinac.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/segment-image.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/segment-image.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/superpixel.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/superpixel.obj -------------------------------------------------------------------------------- /ApplySaliencyToSurfaceInspection/x64/Release/vc120.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/ApplySaliencyToSurfaceInspection/x64/Release/vc120.pdb -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | This toolbox is from the upcoming paper "Saliency of magnetic tile surface defects" . 3 | 4 | The 14 models in this toolbox are: 5 | ITTI and BMS based visual attention mechanism; FT, LC and HC based on global color rarity; AC and MSS} based on local color rarity; SR, Rudinac and PHOT based on frequency domain analysis; RC , SF and GMR based on region or superpixel contrast; and MBP based on the fast Minimum Barrier distance transformation. 6 | 7 | 8 | The models are fast in running, easy to transplant and denpended on opencv only. 9 | 10 | The version of the Opencv we used is Opencv3.1, and we compile it with Vs2013 on a windows 10 x64 computer. 11 | 12 | If you need some images to test, you can download from [https://github.com/abin24/Magnetic-tile-defect-datasets.](https://github.com/abin24/Magnetic-tile-defect-datasets.) 13 | 14 | If you want to use the Mcue method in our paper, you can run the McueSalTest.cpp file. 15 | 16 | 17 | References of this toolbox can be found in our paper. 18 | 19 | 20 | It is welcomed to use our toolbox. 21 | And if it is used in your research, please cite our paper. 22 | 23 | 24 | If you have any questions, please contact me by 25 | [huangyibin2014@ia.ac.cn](huangyibin2014@ia.ac.cn) 26 | -------------------------------------------------------------------------------- /opencv31vs2013x64r.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | G:\opencv31\opencv\build\include\opencv;G:\opencv31\opencv\build\include\opencv2;G:\opencv31\opencv\build\include\;$(IncludePath) 7 | G:\opencv31\opencv\build\x64\vc12\lib;$(LibraryPath) 8 | 9 | 10 | 11 | opencv_world310.lib;%(AdditionalDependencies) 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /x64/Release/ApplySaliencyToSurfaceInspection.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/x64/Release/ApplySaliencyToSurfaceInspection.exe -------------------------------------------------------------------------------- /x64/Release/ApplySaliencyToSurfaceInspection.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abin24/Saliency-detection-toolbox/6df5873c079b4e472c3b1a44dcc4ef4531287ed2/x64/Release/ApplySaliencyToSurfaceInspection.pdb --------------------------------------------------------------------------------