版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Resource.h/NO_DEPENDENCIES/ Microsoft Visual C+ generated include file./ Used by SLICSuperpixels.rc/#define IDD_SLICSUPERPIXELS_DIALOG 102#define IDR_MAINFRAME 128#define IDC_BUTTON_CREATESUPERPIXELS 1000#define IDC_EDIT_SPCOUNT 1001#define IDC_EDIT2 1002#define IDC_EDIT_COMPACTNESS 1002/ Next defau
2、lt values for new objects/ #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 129#define _APS_NEXT_COMMAND_VALUE 32771#define _APS_NEXT_CONTROL_VALUE 1003#define _APS_NEXT_SYMED_VALUE 101#endif#endifStdafx.h/ stdafx.h : include file for standard system include f
3、iles,/ or project specific include files that are used frequently,/ but are changed infrequently#pragma once#ifndef _SECURE_ATL#define _SECURE_ATL 1#endif#ifndef VC_EXTRALEAN#define VC_EXTRALEAN / Exclude rarely-used stuff from Windows headers#endif#include "targetver.h"#define _ATL_CSTRIN
4、G_EXPLICIT_CONSTRUCTORS / some CString constructors will be explicit/ turns off MFC's hiding of some common and often safely ignored warning messages#define _AFX_ALL_WARNINGS#include <afxwin.h> / MFC core and standard components#include <afxext.h> / MFC extensions#ifndef _AFX_NO_OLE_
5、SUPPORT#include <afxdtctl.h> / MFC support for Internet Explorer 4 Common Controls#endif#ifndef _AFX_NO_AFXCMN_SUPPORT#include <afxcmn.h> / MFC support for Windows Common Controls#endif / _AFX_NO_AFXCMN_SUPPORT#include <afxcontrolbars.h> / MFC support for ribbons and control barsSL
6、IC.h/ SLIC.h: interface for the SLIC class./=/ This code implements the superpixel method described in:/ Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Susstrunk,/ "SLIC Superpixels",/ EPFL Technical Report no. 149300, June 2010./=/Copyright (c) 2012
7、 Radhakrishna Achanta EPFL. All rights reserved./=/#if !defined(_SLIC_H_INCLUDED_)#define _SLIC_H_INCLUDED_#include <vector>#include <string>#include <algorithm>using namespace std;class SLIC public:SLIC();virtual SLIC();/=/ Superpixel segmentation for a given step size (superpixel
8、 size = step*step)/= void DoSuperpixelSegmentation_ForGivenSuperpixelSize( const unsigned int* ubuff,/Each 32 bit unsigned int contains ARGB pixel values.const intwidth,const intheight,int*&klabels,int&numlabels, const int&superpixelsize, const double& compactness);/=/ Superpixel seg
9、mentation for a given number of superpixels/= void DoSuperpixelSegmentation_ForGivenNumberOfSuperpixels( const unsigned int* ubuff,const intwidth,const intheight,int*&klabels,int&numlabels, const int&K,/required number of superpixels const double& compactness);/10-20 is a good value
10、for CIELAB space/=/ Supervoxel segmentation for a given step size (supervoxel size = step*step*step)/=void DoSupervoxelSegmentation(unsigned int*&ubuffvec,const int&width,const int&height,const int&depth,int*&klabels,int&numlabels, const int&supervoxelsize, const double&a
11、mp; compactness);/=/ Save superpixel labels in a text file in raster scan order/=void SaveSuperpixelLabels(const int*&labels,const int&width,const int&height,const string&filename,const string&path);/=/ Save supervoxel labels in a text file in raster scan, depth order/=void SaveS
12、upervoxelLabels(const int*&labels,const int&width,const int&height,const int&depth,const string&filename,const string&path);/=/ Function to draw boundaries around superpixels of a given 'color'./ Can also be used to draw boundaries around supervoxels, i.e layer by lay
13、er./=void DrawContoursAroundSegments(unsigned int*&segmentedImage,int*&labels,const int&width,const int&height,const unsigned int&color );private:/=/ The main SLIC algorithm for generating superpixels/=void PerformSuperpixelSLIC(vector<double>&kseedsl,vector<double&g
14、t;&kseedsa,vector<double>&kseedsb,vector<double>&kseedsx,vector<double>&kseedsy,int*&klabels,const int&STEP, const vector<double>&edgemag,const double&m = 10.0);/=/ The main SLIC algorithm for generating supervoxels/=void PerformSupervoxelSLIC(
15、vector<double>&kseedsl,vector<double>&kseedsa,vector<double>&kseedsb,vector<double>&kseedsx,vector<double>&kseedsy,vector<double>&kseedsz,int*&klabels,const int&STEP,const double&compactness);/=/ Pick seeds for superpixels when
16、step size of superpixels is given./=void GetLABXYSeeds_ForGivenStepSize(vector<double>&kseedsl,vector<double>&kseedsa,vector<double>&kseedsb,vector<double>&kseedsx,vector<double>&kseedsy,const int&STEP,const bool&perturbseeds,const vector<
17、double>&edgemag);/=/ Pick seeds for supervoxels/=void GetKValues_LABXYZ(vector<double>&kseedsl,vector<double>&kseedsa,vector<double>&kseedsb,vector<double>&kseedsx,vector<double>&kseedsy,vector<double>&kseedsz,const int&STEP);/=/
18、 Move the superpixel seeds to low gradient positions to avoid putting seeds/ at region boundaries./=void PerturbSeeds(vector<double>&kseedsl,vector<double>&kseedsa,vector<double>&kseedsb,vector<double>&kseedsx,vector<double>&kseedsy,const vector<d
19、ouble>&edges);/=/ Detect color edges, to help PerturbSeeds()/=void DetectLabEdges(const double*lvec,const double*avec,const double*bvec,const int&width,const int&height,vector<double>&edges);/=/ sRGB to XYZ conversion; helper for RGB2LAB()/=void RGB2XYZ(const int&sR,cons
20、t int&sG,const int&sB,double&X,double&Y,double&Z);/=/ sRGB to CIELAB conversion (uses RGB2XYZ function)/=void RGB2LAB(const int&sR,const int&sG,const int&sB,double&lval,double&aval,double&bval);/=/ sRGB to CIELAB conversion for 2-D images/=void DoRGBtoLABC
21、onversion(const unsigned int*&ubuff,double*&lvec,double*&avec,double*&bvec);/=/ sRGB to CIELAB conversion for 3-D volumes/=void DoRGBtoLABConversion(unsigned int*&ubuff,double*&lvec,double*&avec,double*&bvec);/=/ Post-processing of SLIC segmentation, to avoid stray la
22、bels./=void EnforceLabelConnectivity(const int*labels,const intwidth,const intheight,int*&nlabels,/input labels that need to be corrected to remove stray labelsint&numlabels,/the number of labels changes in the end if segments are removedconst int&K); /the number of superpixels desired b
23、y the user/=/ Post-processing of SLIC supervoxel segmentation, to avoid stray labels./=void EnforceSupervoxelLabelConnectivity(int*&labels,/input - previous labels, output - new labelsconst int&width,const int&height,const int&depth,int&numlabels,const int&STEP);private:intm_
24、width;intm_height;intm_depth;double*m_lvec;double*m_avec;double*m_bvec;double*m_lvecvec;double*m_avecvec;double*m_bvecvec;#endif / !defined(_SLIC_H_INCLUDED_)SLICSuperpixels.h/ SLICSuperpixels.h : main header file for the PROJECT_NAME application/#pragma once#ifndef _AFXWIN_H_#error "include
25、39;stdafx.h' before including this file for PCH"#endif#include "resource.h"/ main symbols/ CSLICSuperpixelsApp:/ See SLICSuperpixels.cpp for the implementation of this class/class CSLICSuperpixelsApp : public CWinAppExpublic:CSLICSuperpixelsApp();/ Overridespublic:virtual BOOL Ini
26、tInstance();/ ImplementationDECLARE_MESSAGE_MAP();extern CSLICSuperpixelsApp theApp;SLICSuperpixelsDlg.h/ SLICSuperpixelsDlg.h : header file/#include <vector>#include <string>using namespace std;#pragma once/ CSLICSuperpixelsDlg dialogclass CSLICSuperpixelsDlg : public CDialog/ Construct
27、ionpublic:CSLICSuperpixelsDlg(CWnd* pParent = NULL);/ standard constructor/ Dialog Dataenum IDD = IDD_SLICSUPERPIXELS_DIALOG ;protected:virtual void DoDataExchange(CDataExchange* pDX);/ DDX/DDV support/ Implementationprotected:HICON m_hIcon;/ Generated message map functionsvirtual BOOL OnInitDialog(
28、);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP()public:afx_msg void OnBnClickedButtonCreatesuperpixels();private:bool BrowseForFolder(string& folderpath);void GetPictures(vector<string>& picvec);void DoSupervoxelVideoSegmentation();public:afx_msg void On
29、EnChangeEditSpcount();afx_msg void OnEnChangeEditCompactness();int m_spcount;double m_compactness;SLIC.cpp/ SLIC.cpp: implementation of the SLIC class./ Copyright (C) Radhakrishna Achanta 2012/ All rights reserved/ Email: firstname.lastnameepfl.ch/#include "stdafx.h"#include <cfloat>
30、#include <cmath>#include <iostream>#include <fstream>#include "SLIC.h"/ Construction/Destruction/SLIC:SLIC()m_lvec = NULL;m_avec = NULL;m_bvec = NULL;m_lvecvec = NULL;m_avecvec = NULL;m_bvecvec = NULL;SLIC:SLIC()if(m_lvec) delete m_lvec;if(m_avec) delete m_avec;if(m_bvec)
31、 delete m_bvec;if(m_lvecvec)for( int d = 0; d < m_depth; d+ ) delete m_lvecvecd;delete m_lvecvec;if(m_avecvec)for( int d = 0; d < m_depth; d+ ) delete m_avecvecd;delete m_avecvec;if(m_bvecvec)for( int d = 0; d < m_depth; d+ ) delete m_bvecvecd;delete m_bvecvec;/=/RGB2XYZ/ sRGB (D65 illunina
32、nt assumption) to XYZ conversion/=void SLIC:RGB2XYZ(const int&sR,const int&sG,const int&sB,double&X,double&Y,double&Z)double R = sR/255.0;double G = sG/255.0;double B = sB/255.0;double r, g, b;if(R <= 0.04045)r = R/12.92;elser = pow(R+0.055)/1.055,2.4);if(G <= 0.04045)g
33、 = G/12.92;elseg = pow(G+0.055)/1.055,2.4);if(B <= 0.04045)b = B/12.92;elseb = pow(B+0.055)/1.055,2.4);X = r*0.4124564 + g*0.3575761 + b*0.1804375;Y = r*0.2126729 + g*0.7151522 + b*0.0721750;Z = r*0.0193339 + g*0.1191920 + b*0.9503041;/=/RGB2LAB/=void SLIC:RGB2LAB(const int& sR, const int&
34、; sG, const int& sB, double& lval, double& aval, double& bval)/-/ sRGB to XYZ conversion/-double X, Y, Z;RGB2XYZ(sR, sG, sB, X, Y, Z);/-/ XYZ to LAB conversion/-double epsilon = 0.008856;/actual CIE standarddouble kappa = 903.3;/actual CIE standarddouble Xr = 0.950456;/reference whit
35、edouble Yr = 1.0;/reference whitedouble Zr = 1.088754;/reference whitedouble xr = X/Xr;double yr = Y/Yr;double zr = Z/Zr;double fx, fy, fz;if(xr > epsilon)fx = pow(xr, 1.0/3.0);elsefx = (kappa*xr + 16.0)/116.0;if(yr > epsilon)fy = pow(yr, 1.0/3.0);elsefy = (kappa*yr + 16.0)/116.0;if(zr > ep
36、silon)fz = pow(zr, 1.0/3.0);elsefz = (kappa*zr + 16.0)/116.0;lval = 116.0*fy-16.0;aval = 500.0*(fx-fy);bval = 200.0*(fy-fz);/=/DoRGBtoLABConversion/For whole image: overlaoded floating point version/=void SLIC:DoRGBtoLABConversion(const unsigned int*&ubuff,double*&lvec,double*&avec,doubl
37、e*&bvec)int sz = m_width*m_height;lvec = new doublesz;avec = new doublesz;bvec = new doublesz;for( int j = 0; j < sz; j+ )int r = (ubuffj >> 16) & 0xFF;int g = (ubuffj >> 8) & 0xFF;int b = (ubuffj ) & 0xFF;RGB2LAB( r, g, b, lvecj, avecj, bvecj );/=/DoRGBtoLABConversion
38、/ For whole volume/=void SLIC:DoRGBtoLABConversion(unsigned int*&ubuff,double*&lvec,double*&avec,double*&bvec)int sz = m_width*m_height;for( int d = 0; d < m_depth; d+ )for( int j = 0; j < sz; j+ )int r = (ubuffdj >> 16) & 0xFF;int g = (ubuffdj >> 8) & 0xFF;
39、int b = (ubuffdj ) & 0xFF;RGB2LAB( r, g, b, lvecdj, avecdj, bvecdj );/=/ DrawContoursAroundSegments/ Internal contour drawing option exists. One only needs to comment the if/ statement inside the loop that looks at neighbourhood./=void SLIC:DrawContoursAroundSegments(unsigned int*&ubuff,int*
40、&labels,const int&width,const int&height,const unsigned int&color )const int dx88 = -1, -1, 0, 1, 1, 1, 0, -1;const int dy88 = 0, -1, -1, -1, 0, 1, 1, 1;/*int sz = width*height;vector<bool> istaken(sz, false);int mainindex(0);for( int j = 0; j < height; j+ )for( int k = 0; k < width; k+ )int np(0);for( int i = 0; i < 8; i+ )int x = k + dx
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025绿丝生态农业世界加盟合同
- 2025商场布置合同
- 2025私人墓地买卖合同
- 气管插管科普宣教
- 儿童身高胸围测量与营养
- 生物课堂技能训练
- 重性抑郁症常见症状及护理技巧分享
- 医务人员锐器伤处理知识试卷含答案
- 2025年预防接种技能大赛试题及答案
- 黑客科普知识讲座
- 2025年广东省考公务员考试(公安专业科目)考试试题
- 天车工高级考试题库及答案
- 公司内部营运管理制度
- 化工单位销售管理制度
- T/CNCA 022-2022煤矿用可伸缩带式输送机无基础安装装置
- 流行精粹 课件-2024-2025学年高中音乐人音版(2019)必修音乐鉴赏
- 男护士职业发展现状与未来路径
- 入团考试2025年价值观分享试题及答案
- 国家电投笔试题及答案
- 光伏运维方案
- 轻质砖隔墙工程施工合同
评论
0/150
提交评论