本文整理汇总了C++中GrayImage类的典型用法代码示例。如果您正苦于以下问题:C++ GrayImage类的具体用法?C++ GrayImage怎么用?C++ GrayImage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GrayImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NoDataException
void CharFeatureCollection::calculateOutputDataMatrix(std::vector<ImageChar*> &imageChars)
{
// check if there are features:
if (mImageCharFeatureVec.empty()) {
std::cout << "Exception in CharFeatureCollection::calculateOutputDataMatrix(std::vector<ImageChar> &imageChars): no feature vector list!" << std::endl;
throw NoDataException("No features specified for feature vector calculation!");
}
// calc. size of one column:
int nCols = 0;
for (int i=0; i<mImageCharFeatureVec.size(); ++i) {
nCols += mImageCharFeatureVec[i]->vectorSize();
}
// resize output matrix:
const int nRows = imageChars.size();
std::cout << "2 matrix dimensions are: " << nRows << " x " << nCols << std::endl;
mDataMatrix.resize(nRows, nCols);
#if 1 // take preprocessed image from pointer in ImageChar
#pragma omp parallel for
for (int i=0; i<nRows; ++i) {
#if 0
if (imageChars[i]->mPreprocessingResults.isEmpty()) {
imageChars[i]->mPreprocessingResults
}
#else
// GrayImage<> *pPreprImage = imageChars[i]->pPreprImage;
GrayImage<> *pPreprImage = imageChars[i]->mPreprocessingResults.mpProcessedImage;
if (!pPreprImage) {
std::cerr << "Preprocessing image not available while computing features!" << std::endl;
throw NoDataException("Preprocessing image not available while computing features!");
}
#endif
this->calculateOutputDataRow(*pPreprImage, i, mDataMatrix);
std::cout << "2Computed feature " << i+1 << " of " << nRows << std::endl;
// store reference to feature vector in ImageChar of mpImageCharsVec:
imageChars[i]->setFeatureData(&mDataMatrix, i);
} // end for all rows i
#else // extract bounding box image from ImageChar
for (int i=0; i<nRows; ++i) {
GrayImage<> *pImage = imageChars[i]->pImage;
BoundingBox bbox = imageChars[i]->bBox;
pImage->setRoi(bbox);
GrayImage<> charImage;
pImage->computeRoiImage(charImage);
pImage->releaseRoi();
// std::cout << "current row: " << i << std::endl;
this->calculateOutputDataRow(charImage, i, mDataMatrix);
// store reference to feature vector in ImageChar of mpImageCharsVec:
imageChars[i]->setFeatureData(&mDataMatrix, i);
} // end for all rows i
#endif
return;
} // end calculateOutputDataMatrix
示例2: downscaled_size
GrayImage
TextLineTracer::downscale(GrayImage const& input, Dpi const& dpi)
{
// Downscale to 200 DPI.
QSize downscaled_size(input.size());
if (dpi.horizontal() < 180 || dpi.horizontal() > 220 || dpi.vertical() < 180 || dpi.vertical() > 220) {
downscaled_size.setWidth(std::max<int>(1, input.width() * 200 / dpi.horizontal()));
downscaled_size.setHeight(std::max<int>(1, input.height() * 200 / dpi.vertical()));
}
return scaleToGray(input, downscaled_size);
}
示例3: process_slice
void process_slice( const boost::filesystem::path &folderPath, uint z, Z3i::DigitalSet &set3d ) {
boost::filesystem::path filePath = folderPath ;
filePath /= QString("slice-%1.pgm").arg( z, 0, 10 ).toStdString() ;
GrayImage image = PNMReader<GrayImage>::importPGM( filePath.string() );
Z2i::DigitalSet *objpts = newDigitalSet2DFromBinaryImage( image ) ;
if ( !objpts->empty() ) {
VertexPolygon convexhull ;
Z2i::Object4_8 obj( Z2i::dt4_8, *objpts) ;
Z2i::Object4_8 boundary = obj.border() ;
if ( boundary.size() <= 3 )
{
trace.info()<<"Warning : boundary is ";
for ( Z2i::DigitalSet::ConstIterator pt = boundary.pointSet().begin() ; pt != boundary.pointSet().end() ; pt++ )
trace.info()<<(*pt)<<" " ;
trace.info()<<std::endl;
}
Geom2D::ConvexHull( boundary.pointSet(), convexhull ) ;
EdgePolygon segs ;
init_edges_polygon( segs, convexhull ) ;
uint new3Dpts = 0 ;
if ( segs.size() >= 3 )
for ( Z2i::Domain::ConstIterator pt = image.domain().begin() ; pt != image.domain().end() ; pt++ )
{
if ( image( *pt ) == (unsigned char) 255 ) continue ;
bool bInside = true ;
for ( uint iSeg = 0 ; iSeg != segs.size() && bInside; iSeg++ )
if ( segs[iSeg].signedDistance( *pt ) < 0 ) bInside = false ;
if ( !bInside ) continue ;
set3d.insertNew( Z3i::Point( (*pt).at(0),(*pt).at(1), z ) ) ;
new3Dpts++ ;
}
Z2i::Point UL, BR ;
boundary.pointSet().computeBoundingBox( UL, BR ) ;
std::cerr<<QString( "Slice %1").arg( z,10,10,QLatin1Char('0')).toStdString() ;
std::cerr<<setw(6)<<objpts->size()<<" "
<<setw(6)<<boundary.size()<<" "
<<setw(6)<<new3Dpts<<" "
<<setw(4)<<UL.at(0)<<","
<<setw(4)<<UL.at(1)<<" - "
<<setw(4)<<BR.at(0)<<","
<<setw(4)<<BR.at(1)<<std::endl;
}
delete objpts ;
}
示例4: gaussBlur
GrayImage gaussBlur(GrayImage const& src, float h_sigma, float v_sigma)
{
using namespace boost::lambda;
if (src.isNull()) {
return src;
}
GrayImage dst(src.size());
gaussBlurGeneric(
src.size(), h_sigma, v_sigma,
src.data(), src.stride(), StaticCastValueConv<float>(),
dst.data(), dst.stride(), _1 = bind<uint8_t>(RoundAndClipValueConv<uint8_t>(), _2)
);
return dst;
}
示例5: gf
void GaussianPyramid::BuildPyramid(GrayImage *level0, unsigned nbLevels)
{
GrayImage *pLevel = level0;
_levels.push_back(pLevel);
GaussianFilter gf(_sigma);
// build the nbLevels:
unsigned w = pLevel->width();
unsigned h = pLevel->height();
if (nbLevels != 0) {
for (unsigned int i = 0; i < nbLevels; ++i) { //soc
w = pLevel->width() >> 1;
h = pLevel->height() >> 1;
GrayImage *img = new GrayImage(w, h);
for (unsigned int y = 0; y < h; ++y) {
for (unsigned int x = 0; x < w; ++x) {
float v = gf.getSmoothedPixel<GrayImage>(pLevel, 2 * x, 2 * y);
img->setPixel(x, y, v);
}
}
_levels.push_back(img);
pLevel = img;
}
}
else {
while ((w > 1) && (h > 1)) {
示例6: checkScale
static bool checkScale(GrayImage const& img, QSize const& new_size)
{
GrayImage const scaled1(scaleToGray(img, new_size));
GrayImage const scaled2(img.toQImage().scaled(
new_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation
));
return fuzzyCompare(scaled1, scaled2);
}
示例7: computeOtherPreprocessings
/*static*/
void PreprocessingResults::computeOtherPreprocessings(
const GrayImage<> &preprocessedImage, GrayImage<float> &intInvImage, GrayImage<float> &distTransformImage)
{
#if 1
// 2nd: compute integral invariant image:
int radius = 2; bool oddSize = true;
Kernel<> mask; Kernel<>::createSphereKernel( mask, radius, oddSize );
// std::cout << mask << std::endl;
ImageIntegralInvariant::calcIntegralInvariantImage( mask, preprocessedImage, intInvImage );
#endif
#if 1
// 3rd: compute distance transform of inverted(!) glyph:
GrayImage<> invPreprocessedGlyphImage = preprocessedImage;
invPreprocessedGlyphImage.invert();
ImageFilter::distTransform(invPreprocessedGlyphImage, distTransformImage);
#endif
return;
}
示例8: calcScale
void
PolynomialSurface::prepareEquationsAndDataPoints(
GrayImage const& image, BinaryImage const& mask,
std::vector<double>& equations,
std::vector<double>& data_points) const
{
int const width = image.width();
int const height = image.height();
double const xscale = calcScale(width);
double const yscale = calcScale(height);
uint8_t const* image_line = image.data();
int const image_bpl = image.stride();
uint32_t const* mask_line = mask.data();
int const mask_wpl = mask.wordsPerLine();
int const last_word_idx = (width - 1) >> 5;
int const last_word_mask = ~uint32_t(0) << (31 - ((width - 1) & 31));
for (int y = 0; y < height; ++y) {
double const y_adjusted = y * yscale;
int idx = 0;
// Full words.
for (; idx < last_word_idx; ++idx) {
processMaskWord(
image_line, mask_line[idx], idx, y,
y_adjusted, xscale, equations, data_points
);
}
// Last word.
processMaskWord(
image_line, mask_line[idx] & last_word_mask,
idx, y, y_adjusted, xscale, equations, data_points
);
image_line += image_bpl;
mask_line += mask_wpl;
}
}
示例9: dilateMask
// Dilate (a standard image processing operation) a hands mask
void dilateMask(GrayImage &img, int amount) {
static GrayImage tmp;
img.CopyTo(tmp);
for (int y = amount; y < img.rows - amount; y++) {
for (int x = amount; x < img.cols - amount; x++) {
// Examine neighboring pixels
for (int dy = -amount; dy <= amount; dy++) {
for (int dx = -amount; dx <= amount; dx++) {
if (img.data[y+dy][x+dx] != kMaskUnoccupied) {
tmp.data[y][x] = img.data[y+dy][x+dx];
goto donePixel;
}
}
}
donePixel:;
}
}
tmp.CopyTo(img);
}
示例10: erode
// Erode (a standard image processing operation) a grayscale image
void erode(GrayImage &img, int amount) {
static GrayImage tmp;
img.CopyTo(tmp);
// Two-dimensional kernel
for (int y = 0; y < img.rows; y++) {
for (int x = 0; x < img.cols; x++) {
// Examine neighboring pixels
int min = 255;
for (int dy = -amount; dy <= amount; dy++) {
for (int dx = -amount; dx <= amount; dx++) {
if (img.data[y+dy][x+dx] < min)
min = img.data[y+dy][x+dx];
}
}
tmp.data[y][x] = min;
}
}
tmp.CopyTo(img);
}
示例11: computePreprocessings
void PreprocessingResults::computePreprocessings( const PreprocessingParameters parameters,
const GrayImage<> &glyphImage)
{
this->clear();
// 1st: preprocess glyph image:
mpProcessedImage = new GrayImage<>();
PreprocessingResults::preprocessGlyph(parameters, glyphImage, *mpProcessedImage, &isWhiteSpace);
// pImageChar->pPreprImage = mpProcessedImage;
// std::cout << "finished processing image " << i << std::endl;
// std::cout << mProcessedImagesVec[i] << std::endl;
if (isWhiteSpace) { // jump out as this is a whitespace character
return;
}
#if 1
// 2nd: compute integral invariant image:
int radius = 2; bool oddSize = true;
Kernel<> mask;
Kernel<>::createSphereKernel( mask, radius, oddSize );
// std::cout << mask << std::endl;
mpIntInvImage = new GrayImage<float>();
ImageIntegralInvariant::calcIntegralInvariantImage( mask, *mpProcessedImage, *mpIntInvImage );
#endif
#if 1
// 3rd: compute distance transform of inverted(!) glyph:
GrayImage<> invPreprocessedGlyphImage = *mpProcessedImage;
invPreprocessedGlyphImage.invert();
mpDistTransformImage = new GrayImage<float>();
ImageFilter::distTransform(invPreprocessedGlyphImage, *mpDistTransformImage);
#endif
return;
}
示例12: boxBlur
// Box blur using summed area tables - constant time with respect to kernel size.
// Based off http://www.openprocessing.org/sketch/2934
void boxBlur(GrayImage &img, int size) {
static GrayImage tmp;
static int sum[480][640];
img.CopyTo(tmp);
// Top row and left column
sum[0][0] = img.data[0][0];
for (int x = 1; x < img.cols; ++x) {
sum[0][x] = sum[0][x-1] + img.data[0][x];
}
for (int y = 1; y < img.rows; ++y) {
sum[y][0] = sum[y-1][0] + img.data[y][0];
}
// Rest of summed area table
for (int y = 1; y < img.rows; y++) {
for (int x = 1; x < img.cols; x++) {
sum[y][x] = tmp.data[y][x] + sum[y][x-1] + sum[y-1][x] - sum[y-1][x-1];
}
}
int denom = 1.0f / (float)(((2*size) + 1) * ((2*size) + 1));
for (int y = 0; y < img.rows; y++) {
for (int x = 0; x < img.cols; x++) {
const int xKernSize = std::min(x, size);
const int yKernSize = std::min(y, size);
const int xMin = x - xKernSize;
const int yMin = y - yKernSize;
const int pSum = sum[y][x] - sum[yMin][x] - sum[y][xMin] + sum[yMin][xMin];
const int avg = pSum / std::max(xKernSize * yKernSize, 1);
tmp.data[y][x] = avg;
}
}
tmp.CopyTo(img);
}
示例13: scene_dimensions
Z3i::Domain scene_dimensions( const boost::filesystem::path &folderPath ) {
uint depth = 0 ;
boost::filesystem::path filePath;
do {
filePath = folderPath ;
filePath /= QString("slice-%1.pgm").arg( depth, 0, 10 ).toStdString() ;
depth++ ;
} while ( boost::filesystem::exists( filePath ) ) ;
depth-- ;
if ( depth == 0 ) return Z3i::Domain( Z3i::Point(0,0,0), Z3i::Point(0,0,0) ) ;
filePath = folderPath ;
filePath /= QString("slice-%1.pgm").arg( depth/2, 0, 10 ).toStdString() ; /** "slice-0.pgm" ;*/
GrayImage image = PNMReader<GrayImage>::importPGM( filePath.string() );
#if 0
Z2i::DigitalSet *pts = newDigitalSet2DFromBinaryImage( image ) ;
Board2D board ;
board << image.domain()<<*pts ;
board.saveSVG( "cropcheck.svg");
trace.info()<<"Get "<<pts->size()<<" points on slide "<<filePath.string()<<std::endl;
delete pts ;
#endif
return Z3i::Domain( Z3i::Point(0,0,0), Z3i::Point( image.domain().upperBound().at(0),image.domain().upperBound().at(1),depth) ) ;
}
示例14: applyEffect
void MotionBlur::applyEffect(ColorImage& image, KinectData& kinectData, const GrayImage& handsMask, int timeElapsed) {
for (int y = 0; y < image.rows; y++) {
for (int x = 0; x < image.cols; x++) {
// Leave the area where hand currently is alone
if (handsMask.data[y][x] != kMaskUnoccupied)
continue;
unsigned int blendRed = 0;
unsigned int blendGreen = 0;
unsigned int blendBlue = 0;
unsigned int blendSamplesUsed = 0;
// Blend from each buffer
for (int buf = 0; buf < historyLength; buf++) {
// Include only pixels where hand was
if (maskHistory[buf].data[y][x] != kMaskUnoccupied) {
blendRed += imgHistory[buf].data[y][x].red;
blendGreen += imgHistory[buf].data[y][x].green;
blendBlue += imgHistory[buf].data[y][x].blue;
blendSamplesUsed++;
}
}
// If any blending to be done, average the current pixel and the old ones.
// Current frame makes up half the contribution, with the other half coming from all the other frames combined.
if (blendSamplesUsed > 0) {
blendRed /= blendSamplesUsed;
blendGreen /= blendSamplesUsed;
blendBlue /= blendSamplesUsed;
image.data[y][x].red = (image.data[y][x].red + blendRed) / 2;
image.data[y][x].green = (image.data[y][x].green + blendGreen) / 2;
image.data[y][x].blue = (image.data[y][x].blue + blendBlue) / 2;
}
}
}
// Store current frame in buffers and increment position in ring
image.CopyTo(imgHistory[curBuffer]);
handsMask.CopyTo(maskHistory[curBuffer]);
curBuffer++;
curBuffer = curBuffer % historyLength;
}
示例15: readDepthPixels
void AppCanvas::readDepthPixels(int x, int y, int w, int h, GrayImage& oImage) const
{
float *z = new float[w * h];
memset(z, 0, sizeof(float) * w * h);
int xsch = width();
int ysch = height();
if (_pass_z.buf) {
int xmin = border().getMin().x();
int ymin = border().getMin().y();
int xmax = border().getMax().x();
int ymax = border().getMax().y();
int rectx = _pass_z.width;
int recty = _pass_z.height;
float xfac = ((float)rectx) / ((float)(xmax - xmin));
float yfac = ((float)recty) / ((float)(ymax - ymin));
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
printf("readDepthPixels %d x %d @ (%d, %d) in %d x %d [%d x %d] -- %d x %d @ %d%%\n", w, h, x, y,
xsch, ysch, xmax - xmin, ymax - ymin, rectx, recty, (int)(xfac * 100.0f));
}
#endif
int ii, jj;
for (int j = 0; j < h; j++) {
jj = (int)((y - ymin + j) * yfac);
if (jj < 0 || jj >= recty)
continue;
for (int i = 0; i < w; i++) {
ii = (int)((x - xmin + i) * xfac);
if (ii < 0 || ii >= rectx)
continue;
z[w * j + i] = _pass_z.buf[rectx * jj + ii];
}
}
}
oImage.setArray(z, xsch, ysch, w, h, x, y, false);
}