void PvtDead::initFromGas(Opm::DeckKeywordConstPtr pvdgKeyword) { int numRegions = Opm::PvdgTable::numTables(pvdgKeyword); // resize the attributes of the object b_.resize(numRegions); viscosity_.resize(numRegions); for (int regionIdx = 0; regionIdx < numRegions; ++regionIdx) { Opm::PvdgTable pvdgTable(pvdgKeyword, regionIdx); // Copy data const std::vector<double>& press = pvdgTable.getPressureColumn(); const std::vector<double>& b = pvdgTable.getFormationFactorColumn(); const std::vector<double>& visc = pvdgTable.getViscosityColumn(); const int sz = b.size(); std::vector<double> bInv(sz); for (int i = 0; i < sz; ++i) { bInv[i] = 1.0 / b[i]; } b_[regionIdx] = NonuniformTableLinear<double>(press, bInv); viscosity_[regionIdx] = NonuniformTableLinear<double>(press, visc); } }
int analyse(const char* filename, const char* outFile){ Mat img = cv_imread(filename), imgG, imgTmp; if(!img.data){ //cerr << "invalid image" << endl; throw "[ghosts] invalid image"; } cvtColor(img, imgG, CV_BGR2GRAY); int bCntX = (img.cols - w ) / bSize, bCntY = (img.rows - w) / bSize; int bCnt = bCntX * bCntY; int bCntR = bCnt; int res = 0; vector<vector<vector<double> > > bGhosts(bCnt); vector<vector<vector<double> > > bInv(bCnt); vector<double> bPredict(bCnt); for(int i = 0; i < bCnt; i++){ bGhosts[i].resize(w * w); for(int j = 0; j < w * w; j++) bGhosts[i][j].resize(101); } double elaAv = 0.0; for(int q = min(qNorm, qMin); q <= qMax; q++){ if(!(q == qNorm || (q >= qMin && q <= qMax))) continue; for(int j = 0; j < w * w; j++){ Rect curRoi = Rect(j % w, j / w, img.cols - j % w, img.rows - j / w); vector<int> compParams; vector<uchar> buff; compParams.push_back(CV_IMWRITE_JPEG_QUALITY); compParams.push_back(q); imencode(".jpg", imgG(curRoi), buff, compParams); imgTmp = imdecode(buff, 0); for(int i = 0; i < bCnt; i++){ bGhosts[i][j][q] = calcDiff(imgG(curRoi), imgTmp, bCoordX, bCoordY, bCoordX + bSize, bCoordY + bSize); if(q == qNorm && j == 1) elaAv += bGhosts[i][j][q]; } } fprintf(stderr, "\r%d", q); } elaAv /= bCnt; for(int i = 0; i < bCnt; i++){ vector<double> predictArgsV; predictArgsV.push_back(bCoordX); predictArgsV.push_back(bCoordY); predictArgsV.push_back(elaAv); predictArgsV.push_back(bGhosts[i][1][qNorm]); bPredict[i] = predictF(imgG, predictArgsV); if(bPredict[i] == 1) bCntR--; } for(int i = 0; i < bCnt; i++) for(int j = 0; j < w * w; j++) bGhosts[i][j] = nrm(bGhosts[i][j]); if(1){ for(int i = 0; i < bCnt; i++){ bInv[i].resize(101); if(bPredict[i] == 1) continue; vector<double> m1V(101), m2V(101); for(int q = qMin; q <= qMax; q++){ for(int j = 1; j < w * w; j++) // -- j = 1 m1V[q] += bGhosts[i][j][q]; m1V[q] /= w * w - 1; } for(int q = qMin; q <= qMax; q++){ for(int j = 1; j < w * w; j++) // -- j = 1 m2V[q] += bGhosts[i][j][q] * bGhosts[i][j][q]; m2V[q] = sqrt(m2V[q] / (w * w - 1) - m1V[q] * m1V[q]); } for(int q = qMin; q <= qMax; q++){ double maxD = -1, minD = 2; for(int j = 1; j < w * w; j++){ // -- j = 1 if(bGhosts[i][j][q] < minD) minD = bGhosts[i][j][q]; if(bGhosts[i][j][q] > maxD) maxD = bGhosts[i][j][q]; } double dlt = max((maxD - minD) / 3.0, 0.01); double dlt1 = max((maxD - minD) / 6.0, 0.004); if((bGhosts[i][0][q] < minD - dlt || bGhosts[i][0][q] > maxD + dlt)/* && q <= qMax - 3 && q >= qMin + 3*/){ bInv[i][q].push_back(1); }else bInv[i][q].push_back(0); if((bGhosts[i][0][q] < minD - dlt1 || bGhosts[i][0][q] > maxD + dlt1)/* && q <= qMax - 3 && q >= qMin + 3*/){ bInv[i][q].push_back(1); }else bInv[i][q].push_back(0); } } vector<double> qMask(101); int qMaskCnt = 0; for(int q = qMin; q <= qMax; q++){ for(int i = 0; i < bCnt; i++){ if(bPredict[i] == 1) continue; if(bInv[i][q][0] == 1) qMask[q]++; } if(qMask[q] / bCntR > 0.5){ qMask[q] = 1; qMaskCnt++; }else qMask[q] = 0; cerr << qMask[q]; } cerr << endl; if(qMaskCnt < 3){ //cerr << "don't want to analyse" << endl; //throw "[ghosts] don't want to analyse"; return -1; } for(int i = 0; i < bCnt; i++){ int clr; if(bPredict[i] == 1) clr = 0; else{ int tmpI2 = 0; for(int q = qMin; q <= qMax; q++) if(qMask[q] == 1 && bInv[i][q][1] == 1){ tmpI2++; } if((tmpI2 <= 0 && qMaskCnt >= 3) || (tmpI2 <= 1 && qMaskCnt >= 4) || (tmpI2 <= 2 && qMaskCnt >= 5) || (tmpI2 <= 3 && qMaskCnt >= 8)) tmpI2 = 0; clr = (tmpI2 == 0); } if(clr){ res++; for(int ix = bCoordX; ix < bCoordX + bSize; ix++) for(int iy = bCoordY; iy < bCoordY + bSize; iy++) img.at<Vec3b>(iy, ix)[2] = 255; } } if(outFile) cv_imwrite(outFile, img); } return res; }