本文整理汇总了C++中GrayImage::pixel方法的典型用法代码示例。如果您正苦于以下问题:C++ GrayImage::pixel方法的具体用法?C++ GrayImage::pixel怎么用?C++ GrayImage::pixel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GrayImage
的用法示例。
在下文中一共展示了GrayImage::pixel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixel
float ImagePyramid::pixel(int x, int y, int level)
{
GrayImage *img = _levels[level];
if (0 == level) {
return img->pixel(x, y);
}
unsigned int i = 1 << level;
unsigned int sx = x >> level;
unsigned int sy = y >> level;
if (sx >= img->width())
sx = img->width() - 1;
if (sy >= img->height())
sy = img->height() - 1;
// bilinear interpolation
float A = i * (sx + 1) - x;
float B = x - i * sx;
float C = i * (sy + 1) - y;
float D = y - i * sy;
float P1(0), P2(0);
P1 = A * img->pixel(sx, sy);
if (sx < img->width() - 1) {
if (x % i != 0)
P1 += B * img->pixel(sx + 1, sy);
}
else {
P1 += B * img->pixel(sx, sy);
}
if (sy < img->height() - 1) {
if (y % i != 0) {
P2 = A * img->pixel(sx, sy + 1);
if (sx < img->width() - 1) {
if (x % i != 0)
P2 += B * img->pixel(sx + 1, sy + 1);
}
else {
P2 += B * img->pixel(sx, sy + 1);
}
}
}
else {
P2 = P1;
}
return (1.0f / (float)(1 << (2 * level))) * (C * P1 + D * P2);
}
示例2: saveSteerableViewMap
void SteerableViewMap::saveSteerableViewMap() const
{
for (unsigned int i = 0; i <= _nbOrientations; ++i) {
if (_imagesPyramids[i] == 0) {
cerr << "SteerableViewMap warning: orientation " << i <<
" of steerable View Map whas not been computed yet" << endl;
continue;
}
int ow = _imagesPyramids[i]->width(0);
int oh = _imagesPyramids[i]->height(0);
//soc QString base("SteerableViewMap");
string base("SteerableViewMap");
stringstream filename;
for (int j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) { //soc
float coeff = 1.0f; // 1 / 255.0f; // 100 * 255; // * pow(2, j);
//soc QImage qtmp(ow, oh, QImage::Format_RGB32);
ImBuf *ibuf = IMB_allocImBuf(ow, oh, 32, IB_rect);
int rowbytes = ow * 4;
char *pix;
for (int y = 0; y < oh; ++y) { //soc
for (int x = 0; x < ow; ++x) { //soc
int c = (int)(coeff * _imagesPyramids[i]->pixel(x, y, j));
if (c > 255)
c = 255;
//int c = (int)(_imagesPyramids[i]->pixel(x, y, j));
//soc qtmp.setPixel(x, y, qRgb(c, c, c));
pix = (char *)ibuf->rect + y * rowbytes + x * 4;
pix[0] = pix[1] = pix[2] = c;
}
}
//soc qtmp.save(base+QString::number(i)+"-"+QString::number(j)+".png", "PNG");
filename << base;
filename << i << "-" << j << ".png";
ibuf->ftype = PNG;
IMB_saveiff(ibuf, const_cast<char *>(filename.str().c_str()), 0);
}
#if 0
QString base("SteerableViewMap");
for (unsigned j = 0; j < _imagesPyramids[i]->getNumberOfLevels(); ++j) {
GrayImage *img = _imagesPyramids[i]->getLevel(j);
int ow = img->width();
int oh = img->height();
float coeff = 1.0f; // 100 * 255; // * pow(2, j);
QImage qtmp(ow, oh, 32);
for (unsigned int y = 0; y < oh; ++y) {
for (unsigned int x = 0; x < ow; ++x) {
int c = (int)(coeff * img->pixel(x, y));
if (c > 255)
c = 255;
//int c = (int)(_imagesPyramids[i]->pixel(x, y, j));
qtmp.setPixel(x, y, qRgb(c, c, c));
}
}
qtmp.save(base + QString::number(i) + "-" + QString::number(j) + ".png", "PNG");
}
#endif
}
}