void grayDctDenoisingInvoker::operator() (const Range &range) const { for (int i = range.start; i <= range.end - 1; ++i) { int y = i / (src.cols - psize); int x = i % (src.cols - psize); Rect patchNum( x, y, psize, psize ); Mat patch(psize, psize, CV_32FC1); src(patchNum).copyTo( patch ); dct(patch, patch); float *data = (float *) patch.data; for (int k = 0; k < psize*psize; ++k) data[k] *= fabs(data[k]) > thresh; idct(patch, patches[i]); } }
// extract patch from images // !!!!!!coution!!!!!!! // this function is use for negatime mode!!!!! void extractPosPatches(std::vector<CPosDataset> &posSet, std::vector<CPosPatch> &posPatch, CConfig conf, const int treeNum, const CClassDatabase &classDatabase){ cv::Rect tempRect; std::vector<CPosPatch> tPosPatch(0);//, posPatch(0); std::vector<std::vector<CPosPatch> > patchPerClass(classDatabase.vNode.size()); int pixNum; nCk nck; int classNum = 0; posPatch.clear(); tempRect.width = conf.p_width; tempRect.height = conf.p_height; std::cout << "image num is " << posSet.size(); std::cout << "extracting patch from image" << std::endl; for(int l = 0;l < posSet.size(); ++l){ for(int j = 0; j < posSet.at(l).img.at(0)->cols - conf.p_width; j += conf.stride){ for(int k = 0; k < posSet.at(l).img.at(0)->rows - conf.p_height; k += conf.stride){ tempRect.x = j; tempRect.y = k; pixNum = 0; int centerDepthFlag = 1; // detect negative patch for(int m = j; m < j + conf.p_width; ++m){ for(int n = k; n < k + conf.p_height; ++n){ pixNum += (int)(posSet.at(l).img.at(1)->at<ushort>(n, m)); } } // set patch class classNum = classDatabase.search(posSet.at(l).getParam()->getClassName());//dataSet.at(l).className.at(0)); if(classNum == -1){ std::cout << "class not found!" << std::endl; exit(-1); } //tPatch.setPatch(temp, image.at(l), dataSet.at(l), classNum); CPosPatch posTemp(&posSet.at(l),tempRect); if (pixNum > 0 && posSet.at(l).img.at(1)->at<ushort>(k + (conf.p_height / 2) + 1, j + (conf.p_width / 2) + 1 ) != 0){ tPosPatch.push_back(posTemp); patchPerClass.at(classNum).push_back(posTemp); } // if }//x }//y }//allimages std::vector<int> patchNum(patchPerClass.size(),conf.patchRatio); for(int i = 0; i < patchPerClass.size(); ++i){ if(i == treeNum % patchPerClass.size()) patchNum.at(i) = conf.patchRatio; else patchNum.at(i) = conf.patchRatio * conf.acPatchRatio; } // choose patch from each image for(int i = 0; i < patchPerClass.size(); ++i){ if(patchPerClass.at(i).size() > conf.patchRatio){ std::set<int> chosenPatch = nck.generate(patchPerClass.at(i).size(),patchNum.at(i));// conf.patchRatio);//totalPatchNum * conf.patchRatio); std::set<int>::iterator ite = chosenPatch.begin(); while(ite != chosenPatch.end()){ //std::cout << "this is for debug ite is " << tPosPatch.at(*ite).center << std::endl; posPatch.push_back(patchPerClass.at(i).at(*ite)); ite++; } }else{ std::cout << "can't extruct enough patch" << std::endl; } } return; }