cv::Mat CMyImageProc::GenSaliencyMap(cv::Mat &img) { cv::Mat saliencyImg; std::vector<UINT> temImg; for(int i=0; i<img.rows; i++) { for(int j=0; j<img.cols; j++) { cv::Vec3b &pf = img.at<cv::Vec3b>(i, j); UINT rgb = ( (UINT) ( (pf[0] | ((unsigned short)( pf[1] )<<8)) | (((unsigned long) pf[2])<<16) ) ); temImg.push_back(rgb); } } Saliency ss; std::vector<double> salmap; ss.GetSaliencyMap(temImg, img.cols, img.rows, salmap); saliencyImg = cv::Mat(img.rows, img.cols, CV_8U); int n=0; for(int i=0; i<img.rows; i++) { for(int j=0; j<img.cols; j++, n++) { int val = int (salmap[n] + 0.5); saliencyImg.at<uchar>(i, j) = (uchar) val; } } return saliencyImg; }
// ./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"); } }