Skip to content

Commit

Permalink
Add SaliencyCut
Browse files Browse the repository at this point in the history
  • Loading branch information
MingMingCheng committed Jul 28, 2014
1 parent 4feff6b commit 47d5265
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 47 deletions.
15 changes: 1 addition & 14 deletions CmLib/CmLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ using namespace std;
#pragma comment( lib, cvLIB("core"))
#pragma comment( lib, cvLIB("imgproc"))
#pragma comment( lib, cvLIB("highgui"))
#pragma comment( lib, cvLIB("features2d"))
#pragma comment( lib, cvLIB("flann"))
#pragma comment( lib, cvLIB("calib3d"))
#pragma comment( lib, cvLIB("objdetect"))
#pragma comment( lib, cvLIB("contrib"))
#pragma comment( lib, cvLIB("nonfree"))
#pragma comment( lib, cvLIB("legacy"))
#pragma comment( lib, cvLIB("ml"))
#pragma comment( lib, cvLIB("photo"))
#pragma comment( lib, cvLIB("stitching"))
#pragma comment( lib, cvLIB("ts"))
#pragma comment( lib, cvLIB("video"))
#pragma comment( lib, cvLIB("videostab"))
using namespace cv;


Expand Down Expand Up @@ -117,7 +104,7 @@ using namespace cv;
// Saliency detection algorithms
#include "./Saliency/CmSaliencyRC.h"
#include "./Saliency/CmSaliencyGC.h"
//#include "./Saliency/CmSalCut.h"
#include "./Saliency/CmSalCut.h"
//#include "./Saliency/CmGrabCutUI.h"
//
//
Expand Down
2 changes: 2 additions & 0 deletions CmLib/CmLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
<ClInclude Include="Illustration\CmShow.h" />
<ClInclude Include="OtherAlg\CmCurveEx.h" />
<ClInclude Include="OtherAlg\CmValStructVec.h" />
<ClInclude Include="Saliency\CmSalCut.h" />
<ClInclude Include="Saliency\CmSaliencyGC.h" />
<ClInclude Include="Saliency\CmSaliencyRC.h" />
<ClInclude Include="Segmentation\EfficientGraphBased\disjoint-set.h" />
Expand Down Expand Up @@ -196,6 +197,7 @@
<ClCompile Include="Illustration\CmIllu.cpp" />
<ClCompile Include="Illustration\CmShow.cpp" />
<ClCompile Include="OtherAlg\CmCurveEx.cpp" />
<ClCompile Include="Saliency\CmSalCut.cpp" />
<ClCompile Include="Saliency\CmSaliencyGC.cpp" />
<ClCompile Include="Saliency\CmSaliencyRC.cpp" />
<ClCompile Include="Segmentation\EfficientGraphBased\segment-image.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions CmLib/CmLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@
<ClInclude Include="OtherAlg\CmValStructVec.h">
<Filter>OhterAlg</Filter>
</ClInclude>
<ClInclude Include="Saliency\CmSalCut.h">
<Filter>Saliency</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
Expand Down Expand Up @@ -237,5 +240,8 @@
<ClCompile Include="Illustration\CmIllu.cpp">
<Filter>Illustration</Filter>
</ClCompile>
<ClCompile Include="Saliency\CmSalCut.cpp">
<Filter>Saliency</Filter>
</ClCompile>
</ItemGroup>
</Project>
14 changes: 7 additions & 7 deletions CmLib/Illustration/CmEvaluation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void CmEvaluation::Evaluate(CStr gtW, CStr &salDir, CStr &resName, vecS &des)
CV_Assert(fpr[i].size() == tpr[i].size() && precision[i].size() == recall[i].size() && fpr[i].size() == precision[i].size());
for (size_t t = 0; t < fpr[i].size(); t++){
double fMeasure = (1+betaSqr) * precision[i][t] * recall[i][t] / (betaSqr * precision[i][t] + recall[i][t]);
//avgFMeasure[i] += fMeasure/fpr[i].size(); // Doing average like this might have strange effect as in:
avgFMeasure[i] += fMeasure/fpr[i].size(); // Doing average like this might have strange effect as in:
maxFMeasure[i] = max(maxFMeasure[i], fMeasure);
if (t > 0){
areaROC[i] += (tpr[i][t] + tpr[i][t - 1]) * (fpr[i][t - 1] - fpr[i][t]) / 2.0;
Expand Down Expand Up @@ -182,17 +182,17 @@ double CmEvaluation::interUnionBBox(const Vec4i &box1, const Vec4i &box2) // eac
return ov;
}

void CmEvaluation::EvalueMask(CStr gtW, CStr &maskDir, CStr &gtExt, CStr &des, CStr resFile, double betaSqr, bool alertNul, CStr suffix)
void CmEvaluation::EvalueMask(CStr gtW, CStr &maskDir, CStr &des, CStr resFile, double betaSqr, bool alertNul, CStr suffix)
{
vecS descri(1); descri[0] = des;
EvalueMask(gtW, maskDir, gtExt, descri, resFile, betaSqr, alertNul, suffix);
EvalueMask(gtW, maskDir, descri, resFile, betaSqr, alertNul, suffix);
}

void CmEvaluation::EvalueMask(CStr gtW, CStr &maskDir, CStr &gtExt, vecS &des, CStr resFile, double betaSqr, bool alertNul, CStr suffix)
void CmEvaluation::EvalueMask(CStr gtW, CStr &maskDir, vecS &des, CStr resFile, double betaSqr, bool alertNul, CStr suffix)
{
vecS namesNS;
string gtDir;
int imgNum = CmFile::GetNamesNoSuffix(gtW, namesNS, gtExt, gtDir);
string gtDir, gtExt;
int imgNum = CmFile::GetNamesNE(gtW, namesNS, gtDir, gtExt);
int methodNum = (int)des.size();
vecD pr(methodNum), rec(methodNum), count(methodNum), fm(methodNum);
for (int i = 0; i < imgNum; i++){
Expand Down Expand Up @@ -230,7 +230,7 @@ void CmEvaluation::EvalueMask(CStr gtW, CStr &maskDir, CStr &gtExt, vecS &des, C
CmEvaluation::PrintVector(f, pr, "PrecisionMask" + suffix);
CmEvaluation::PrintVector(f, rec, "RecallMask" + suffix);
CmEvaluation::PrintVector(f, fm, "FMeasureMask" + suffix);
fprintf(f, "bar(%s);\ntitle('%s')\n", _S("FMeasureMask" + suffix), _S("FMeasureMask" + suffix));
fprintf(f, "bar([%s]');\ntitle('%s');\ngrid on\n", _S("PrecisionMask" + suffix + "; RecallMask" + suffix + "; FMeasureMask" + suffix), _S("Segmentation" + suffix));
fclose(f);
}

Expand Down
4 changes: 2 additions & 2 deletions CmLib/Illustration/CmEvaluation.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct CmEvaluation
static void Evaluate(CStr gtW, CStr &salDir, CStr &resName, CStr &des) {vecS descri(1); descri[0] = des; Evaluate(gtW, salDir, resName, descri);}

// Plot the FMeasure bar
static void EvalueMask(CStr gtW, CStr &maskDir, CStr &gtExt, vecS &des, CStr resFile, double betaSqr = 0.3, bool alertNul = false, CStr suffix = "");
static void EvalueMask(CStr gtW, CStr &maskDir, CStr &gtExt, CStr &des, CStr resFile, double betaSqr = 0.3, bool alertNul = false, CStr suffix = "");
static void EvalueMask(CStr gtW, CStr &maskDir, vecS &des, CStr resFile, double betaSqr = 0.3, bool alertNul = false, CStr suffix = "");
static void EvalueMask(CStr gtW, CStr &maskDir, CStr &des, CStr resFile, double betaSqr = 0.3, bool alertNul = false, CStr suffix = "");

public: // Assistant functions

Expand Down
2 changes: 1 addition & 1 deletion CmLib/Saliency/CmSaliencyGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ int CmSaliencyGC::Demo(CStr imgW, CStr salDir)
imwrite(outName + "_GC.png", sal1f*255);
}
tm.Stop();
printf("Speed: %g seconds = %g fps\n", tm.TimeInSeconds()/imgNum, imgNum/tm.TimeInSeconds());
printf("Speed of GC method: %g seconds = %g fps\n", tm.TimeInSeconds()/imgNum, imgNum/tm.TimeInSeconds());

des.push_back("GC");
CmEvaluation::Evaluate(imgDir + "*.png", salDir, salDir + "Eval.m", des);
Expand Down
2 changes: 1 addition & 1 deletion CmLib/Saliency/CmSaliencyRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void CmSaliencyRC::Get(CStr &imgNameW, CStr &salFileDir)
#pragma omp parallel for
for (int i = 0; i < imgNum; i++){
string name = names[i] + ext;
printf("Processing %d/%dth image: %-20s\r", i, imgNum, name.c_str());
//printf("Processing %d/%dth image: %-20s\r", i, imgNum, name.c_str());
Mat sal, img3f = imread(inDir + name);
if (img3f.data == NULL){
printf("Can't load image %s, in %s:%d\n", name.c_str(), __FILE__, __LINE__);
Expand Down
14 changes: 5 additions & 9 deletions CmLib/Saliency/CmSaliencyRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,11 @@ struct CmSaliencyRC

/************************************************************************/
/*[1]R. Achanta, S. Hemami, F. Estrada and S. Susstrunk, Frequency-tuned*/
/* Salient Region Detection, IEEE International Conference on Computer*/
/* Vision and Pattern Recognition (CVPR), 2009. */
/* Salient Region Detection, IEEE CVPR, 2009. */
/*[2]Y. Zhai and M. Shah. Visual attention detection in video sequences */
/* using spatiotemporal cues. In ACM Multimedia, pages 815¨C824. ACM, */
/* 2006. */
/*[3]M.-M. Cheng, G.-X. Zhang, N. J. Mitra, X. Huang, S.-M. Hu. Global */
/* Contrast based Salient Region Detection. IEEE CVPR, p. 409-416, */
/* 2011 */
/* using spatiotemporal cues. In ACM Multimedia 2006. */
/*[3]M.-M. Cheng, N. J. Mitra, X. Huang, P.H.S. Torr S.-M. Hu. Global */
/* Contrast based Salient Region Detection. IEEE PAMI, 2014. */
/*[4]X. Hou and L. Zhang. Saliency detection: A spectral residual */
/* approach. In IEEE Conference on Computer Vision and Pattern */
/* Recognition, 2007. CVPR 2007, pages 1¨C8, 2007. */
/* approach. In IEEE CVPR 2007, 2007. */
/************************************************************************/
3 changes: 1 addition & 2 deletions CurveExtractionHHME09/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@



// TODO: reference additional headers your program requires here
#include <Cmcode\CmLib\cmlib.h>
#include "..\CmLib\cmlib.h"
33 changes: 22 additions & 11 deletions Saliency/SaliencyMain.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
// SaliencyICCV13.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

int main(int argc, char* argv[])
{
CStr wkDir = "D:/Saliency/MSRA10K/";
CStr wkDir = "D:/WkDir/Saliency/MSRA10K/";
CStr inDir = wkDir + "Imgs/", outDir = wkDir + "Saliency/";
CmFile::Copy2Dir(inDir + "*.jpg", outDir);

CStr srcDir = "D:/Downloads/MSRA10K_Maps_Cuts/SaliencyCut/";
vecS namesNE;
int imgNum = CmFile::GetNamesNE(srcDir + "*_RCC.png", namesNE);
for (int i = 0; i < imgNum; i++)
CmFile::Copy(srcDir + namesNE[i] + ".png", outDir + namesNE[i] + "O.png");


// Saliency detection method pretended in my ICCV 2013 paper http://mmcheng.net/effisalobj/.
return CmSaliencyGC::Demo(wkDir + "Imgs/*.jpg", wkDir + "/Saliency/");
//CmSaliencyGC::Demo(inDir + "*.jpg", outDir);

// Saliency detection method presented in PAMI 2014 (CVPR 2011) paper http://mmcheng.net/salobj/.
CmSalCut::Demo(inDir + "83262*.jpg", inDir + "*.png", outDir);

//CmSaliencyRC::Get(inDir + "*.jpg", outDir);

// Saliency detection method presented in CVPR11 paper and its journal version http://mmcheng.net/salobj/.
return CmSaliencyRC::Demo("D:/WkDir/Saliency/FT1000/");
vecS des, desCut;
des.push_back("RC"); des.push_back("GC");
desCut.push_back("RCC"); desCut.push_back("RCCO");
//CmEvaluation::Evaluate(inDir + "*.png", outDir, wkDir + "Results.m", des);
CmEvaluation::EvalueMask(inDir + "*.png", outDir, desCut, wkDir + "CutRes.m");

vecS des;
des.push_back("_RC");
des.push_back("_HC");
CmEvaluation::Evaluate(wkDir + "Imgs/*.png", wkDir + "Saliency/", wkDir + "Results.m", des);
return 0;
}
10 changes: 10 additions & 0 deletions SpReco/SREngine.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#pragma once

/************************************************************************/
/* Notice: this project is used to support speech recognition of my */
/* ImageSpirit project. Please see the corresponding paper for more */
/* details. The CORE part of ImageSpirit system will be made public */
/* available soon. More resource: http://mmcheng.net/imagespirit/ */
/* ImageSpirit: Verbal Guided Image Parsing. M.-M. Cheng, S. Zheng, */
/* W.-Y. Lin, V. Vineet, P. Sturgess, N. Crook, N. Mitra, P. Torr, */
/* ACM TOG, 2014. */
/************************************************************************/

#include <sphelper.h> // Microsoft Speech API

class SREngine
Expand Down
11 changes: 11 additions & 0 deletions SpReco/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/************************************************************************/
/* Notice: this project is used to support speech recognition of my */
/* ImageSpirit project. Please see the corresponding paper for more */
/* details. The CORE part of ImageSpirit system will be made public */
/* available soon. More resource: http://mmcheng.net/imagespirit/ */
/* ImageSpirit: Verbal Guided Image Parsing. M.-M. Cheng, S. Zheng, */
/* W.-Y. Lin, V. Vineet, P. Sturgess, N. Crook, N. Mitra, P. Torr, */
/* ACM TOG, 2014. */
/************************************************************************/

#include "stdafx.h"
#include "SpRecoUI.h"


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Expand Down

0 comments on commit 47d5265

Please sign in to comment.