void ShadingGS::_eleProperty(int gID, int eleID, int index, float& shading, float& reflectance){ DataManager& dm = *m_dmPtr; mat_3f& inputImg = dm.getInput(); cv::Size imgSize = inputImg.size(); int eX = eleID % imgSize.width; int eY = eleID / imgSize.width; cv::Vec3f& rgb = inputImg(eY,eX); float pixInt = cv::norm(rgb); shading = (index+ m_base)/MRF_LABEL_NUM; reflectance = pixInt / shading; }
cv::Mat CMyImageProc::GenTextonMap(cv::Mat &img, int clusterCount ) { int n_sigmas, n_orientations; mH2 filterbank; vector<vector<Mat> > response; cv::Mat inputImg(img.rows, img.cols, CV_8UC1); cv::cvtColor(img, inputImg, COLOR_BGR2GRAY); //imread("src.png"); n_sigmas = 3; n_orientations = 6; //int clusterCount = 32; createFilterbank(filterbank, n_sigmas, n_orientations); apply_filterbank(inputImg, filterbank, response, n_sigmas, n_orientations); //cout<<float(response[0][0].at<uchar>(0,0))<<endl; cv::Mat samples(inputImg.rows * inputImg.cols, 8, CV_32F); //MR8 cv::Mat centers, labels; int attempts = 5; for(int k=0, i=0; i<inputImg.rows; i++){ for(int j=0; j<inputImg.cols; j++, k++){ for(int d=0, ii = 0; ii<3; ii++){ for(int jj=0; jj<response[ii].size(); jj++, d++){ samples.at<float>(k,d) = float(response[ii][jj].at<uchar>(i,j)); } } } } //cout<<"samples transfer over!"<<endl; // Apply KMeans cv::kmeans(samples, clusterCount, labels, TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 10, 1.0), attempts, KMEANS_PP_CENTERS, centers); cv:: Mat textonImg(inputImg.rows, inputImg.cols, CV_8UC1, Scalar(uchar(0))); for(int k=0, i=0; i<inputImg.rows; i++){ for(int j=0; j<inputImg.cols; j++, k++){ int l = labels.at<int>(k,0); double f_l = l / (double)clusterCount; textonImg.at<uchar>(i,j) = (uchar) (int (f_l*255.0+0.5)); } } //imshow("textons", texton); //imwrite("texton_map.png", texton); return textonImg; }