// ./Imgs/*.jpg ./Sal/ int main(int argc,char *argv[]) { CV_Assert(argc == 3); string imgW = argv[1], salDir = argv[2]; string imgDir, imgExt; vecS namesNE; CmFile::MkDir(salDir); int imgNum = CmFile::GetNamesNE(imgW, namesNE, imgDir, imgExt); for (int i = 0; i < imgNum; i++){ if (CmFile::FilesExist(salDir + namesNE[i] + "_FT.png")) continue; vector<UINT> img(0);// or UINT* imgBuffer; int width(0); int height(0); PictureHandler picHand; picHand.GetPictureBuffer(imgDir + namesNE[i] + imgExt, img, width, height ); int sz = width*height; Saliency sal; vector<double> salmap(0); sal.GetSaliencyMap(img, width, height, salmap, true); vector<UINT> outimg(sz); for( int i = 0; i < sz; i++ ){ int val = int(salmap[i] + 0.5); outimg[i] = val << 16 | val << 8 | val; } picHand.SavePicture(outimg, width, height, namesNE[i], salDir, 0, "_FT");// 0 is for BMP and 1 for JPEG) Mat sal1u = imread(salDir + namesNE[i] + "_FT.bmp", CV_LOAD_IMAGE_GRAYSCALE); imwrite(salDir + namesNE[i] + "_FT.png", sal1u); CmFile::RmFile(salDir + namesNE[i] + "_FT.bmp"); } }
//=========================================================================== /// OnBnClickedButtonCreatesuperpixels /// /// The main function //=========================================================================== void CSLICSuperpixelsDlg::OnBnClickedButtonCreatesuperpixels() { PictureHandler picHand; vector<string> picvec(0); picvec.resize(0); GetPictures(picvec);//user chooses one or more pictures string saveLocation = "C:\\rktemp\\"; BrowseForFolder(saveLocation); int numPics( picvec.size() ); //if(m_spcount < 0 || m_spcount < 20) m_spcount = 20; if(m_spcount < 0) m_spcount = 200; for( int k = 0; k < numPics; k++ ) { UINT* img = NULL; int width(0); int height(0); picHand.GetPictureBuffer( picvec[k], img, width, height ); int sz = width*height; if(m_spcount > sz) AfxMessageBox(L"Number of superpixels exceeds number of pixels in the image"); int* labels = new int[sz]; int numlabels(0); SLIC slic; slic.PerformSLICO_ForGivenK(img, width, height, labels, numlabels, m_spcount, m_compactness);//for a given number K of superpixels //slic.PerformSLICO_ForGivenStepSize(img, width, height, labels, numlabels, m_stepsize, m_compactness);//for a given grid step size //slic.DrawContoursAroundSegments(img, labels, width, height, 0);//for black contours around superpixels slic.DrawContoursAroundSegmentsTwoColors(img, labels, width, height);//for black-and-white contours around superpixels slic.SaveSuperpixelLabels(labels,width,height,picvec[k],saveLocation); if(labels) delete [] labels; picHand.SavePicture(img, width, height, picvec[k], saveLocation, 1, "_SLICO");// 0 is for BMP and 1 for JPEG) if(img) delete [] img; } AfxMessageBox(L"Done!", 0, 0); }