PIC_INLINE void FilterGuided::Process3Channel(Image *I, Image *p, Image *q, BBox *box) { float *a_b_mean = new float[img_a_b->channels]; int shift = I->channels + 1; for(int j = box->y0; j < box->y1; j++) { for(int i = box->x0; i < box->x1; i++) { float *tmpQ = (*q)(i, j); float *tmpI = (*I)(i, j); BBox tmpBox(i - radius, i + radius, j - radius, j + radius); img_a_b->getMeanVal(&tmpBox, a_b_mean); for(int c = 0; c < p->channels; c++) { int index = c * shift; float *a = &a_b_mean[index]; float b = a_b_mean[index + I->channels]; float a_dot_I = Array<float>::dot(a, tmpI, I->channels); tmpQ[c] = a_dot_I + b; } } } delete[] a_b_mean; }
void GOpenGLBoard::GrabFrameBuffer(const GAABox2& LogicBox, GLGrabbedRect& Shot) { GLDisableShaders(); GReal left, right, bottom, top; Projection(left, right, bottom, top); if (LogicBox.Min()[G_X] > left) left = LogicBox.Min()[G_X]; if (LogicBox.Max()[G_X] < right) right = LogicBox.Max()[G_X]; if (LogicBox.Min()[G_Y] > bottom) bottom = LogicBox.Min()[G_Y]; if (LogicBox.Max()[G_Y] < top) top = LogicBox.Max()[G_Y]; GAABox2 tmpBox(GPoint2(left, bottom), GPoint2(right, top)); GPoint<GInt32, 2> p0 = LogicalToPhysicalInt(tmpBox.Min()); GPoint<GInt32, 2> p1 = LogicalToPhysicalInt(tmpBox.Max()); p0[G_X] -= 1; p0[G_Y] -= 1; p1[G_X] += 1; p1[G_Y] += 1; GGenericAABox<GInt32, 2> intBox(p0, p1); GUInt32 width = (GUInt32)GMath::Abs(p1[G_X] - p0[G_X]); GUInt32 height = (GUInt32)GMath::Abs(p1[G_Y] - p0[G_Y]); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); UpdateGrabBuffer(width, height, Shot); G_ASSERT(Shot.TexName > 0); G_ASSERT(Shot.TexWidth > 0 && Shot.TexHeight > 0); G_ASSERT(Shot.TexWidth >= width && Shot.TexHeight >= height); SELECT_AND_DISABLE_TUNIT(1) SELECT_AND_DISABLE_TUNIT(0) glEnable(Shot.Target); glBindTexture(Shot.Target, Shot.TexName); glCopyTexSubImage2D(Shot.Target, 0, 0, 0, (GLint)intBox.Min()[G_X], (GLint)intBox.Min()[G_Y], (GLsizei)width, (GLsizei)height); Shot.Width = width; Shot.Height = height; Shot.IsEmpty = G_FALSE; Shot.gNotExpandedLogicBox = tmpBox; GPoint2 q0 = PhysicalToLogical(p0); GPoint2 q1 = PhysicalToLogical(p1); Shot.gExpandedLogicBox.SetMinMax(q0, q1); SELECT_AND_DISABLE_TUNIT(0) glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); }
void InternalRStarTreeWrapper::insert(int objId, std::vector<double> & minBounds, std::vector<double> & maxBounds) { assert(_dimensions == minBounds.size()); assert(_dimensions == maxBounds.size()); Box tmpBox(_dimensions); for(unsigned int i = 0; i < _dimensions; i++) { tmpBox.setBounds(i, minBounds[i], maxBounds[i]); } _tree->insert(tmpBox, objId); }
PIC_INLINE void FilterGuidedAB::Process1Channel(Image *I, Image *p, Image *q, BBox *box) { float I_mean, I_var; float *p_mean = new float [p->channels]; for(int j = box->y0; j < box->y1; j++) { for(int i = box->x0; i < box->x1; i++) { float *tmpQ = (*q)(i, j); BBox tmpBox(i - radius, i + radius, j - radius, j + radius); I->getMeanVal(&tmpBox, &I_mean); I->getVarianceVal(&I_mean, &tmpBox, &I_var); p->getMeanVal(&tmpBox, p_mean); for(int c = 0; c < p->channels; c++) { float I_mean_p_mean = I_mean * p_mean[c]; float a = 0.0f; for(int k = -radius; k < radius; k++) { for(int l = -radius; l < radius; l++) { float *I_i = (*I)(i + l, j + k); float *p_i = (*p)(i + l, j + k); a += I_i[0] * p_i[c] - I_mean_p_mean; } } a /= (nPixels * (I_var + e_regularization)); float b = p_mean[c] - a * I_mean; int index = c << 1; tmpQ[index] = a; tmpQ[index + 1] = b; } } } delete[] p_mean; }
PIC_INLINE void FilterGuided::Process1Channel(Image *I, Image *p, Image *q, BBox *box) { float *a_b_mean = new float[img_a_b->channels]; for(int j = box->y0; j < box->y1; j++) { for(int i = box->x0; i < box->x1; i++) { float *tmpQ = (*q)(i, j); float *tmpI = (*I)(i, j); BBox tmpBox(i - radius, i + radius, j - radius, j + radius); img_a_b->getMeanVal(&tmpBox, a_b_mean); for(int c = 0; c < p->channels; c++) { int index = c << 1; float a = a_b_mean[index]; float b = a_b_mean[index + 1]; tmpQ[c] = a * tmpI[0] + b; } } } delete[] a_b_mean; }
PIC_INLINE void FilterGuidedAB::Process3Channel(Image *I, Image *p, Image *q, BBox *box) { float *I_mean = new float[I->channels]; float *p_mean = new float[p->channels]; float *a = new float[I->channels]; float *tmp_A = new float[I->channels]; Matrix3x3 cov, inv; for(int j = box->y0; j < box->y1; j++) { for(int i = box->x0; i < box->x1; i++) { float *tmpQ = (*q)(i, j); BBox tmpBox(i - radius, i + radius, j - radius, j + radius); I->getMeanVal(&tmpBox, I_mean); I->getCovMtxVal(I_mean, &tmpBox, cov.data); //regularization cov.add(e_regularization); //invert matrix cov.inverse(&inv); p->getMeanVal(&tmpBox, p_mean); int index = 0; for(int c = 0; c < p->channels; c++) { Array<float>::assign(0.0f, tmp_A, I->channels); for(int k = -radius; k < radius; k++) { for(int l = -radius; l < radius; l++) { float *I_i = (*I)(i + l, j + k); float *p_i = (*p)(i + l, j + k); for(int n = 0; n < I->channels; n++) { tmp_A[n] += I_i[n] * p_i[c] - I_mean[n] * p_mean[c]; } } } Array<float>::div(tmp_A, I->channels, nPixels); //multiply for inverted matrix a = inv.mul(tmp_A, a); float a_dot_I_mean = Array<float>::dot(a, I_mean, I->channels); //float a_dot_I = Array<float>::dot(a, tmpI, channels); for(int n = 0; n < I->channels; n++) { tmpQ[index] = a[n]; index++; } //b tmpQ[index] = p_mean[c] - a_dot_I_mean; index++; } } } }