本文整理汇总了C++中Image2类的典型用法代码示例。如果您正苦于以下问题:C++ Image2类的具体用法?C++ Image2怎么用?C++ Image2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image2类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: temp
//----------------------------------------------------------------------------
void ImageUtility2::Open4(Image2<int> const& input, bool zeroExterior,
Image2<int>& output)
{
Image2<int> temp(input.GetDimension(0), input.GetDimension(1));
Erode4(input, zeroExterior, temp);
Dilate4(temp, output);
}
示例2: image
//----------------------------------------------------------------------------
bool ImageUtility2::ClearInteriorAdjacent(Image2<int>& image, int value)
{
int const dim0 = image.GetDimension(0);
int const dim1 = image.GetDimension(1);
bool noRemoval = true;
for (int y = 0; y < dim1; ++y)
{
for (int x = 0; x < dim0; ++x)
{
if (image(x, y) == 1)
{
bool interiorAdjacent =
image(x-1, y-1) == value ||
image(x , y-1) == value ||
image(x+1, y-1) == value ||
image(x+1, y ) == value ||
image(x+1, y+1) == value ||
image(x , y+1) == value ||
image(x-1, y+1) == value ||
image(x-1, y ) == value;
if (interiorAdjacent && !IsArticulation(image, x, y))
{
image(x, y) = 0;
noRemoval = false;
}
}
}
}
return noRemoval;
}
示例3: LogAssert
//----------------------------------------------------------------------------
void ImageUtility2::Dilate(Image2<int> const& input, int numNeighbors,
std::array<int, 2> const* neighbors, Image2<int>& output)
{
// If the assertion is triggered, the function will run but the output
// will not be correct.
LogAssert(&output != &input, "Input and output must be different.");
output = input;
// If the pixel at (x,y) is 1, then the pixels at (x+dx,y+dy) are set to 1
// where (dx,dy) is in the 'neighbors' array. Boundary testing is used to
// avoid accessing out-of-range pixels.
int const dim0 = input.GetDimension(0);
int const dim1 = input.GetDimension(1);
for (int y = 0; y < dim1; ++y)
{
for (int x = 0; x < dim0; ++x)
{
if (input(x, y) == 1)
{
for (int j = 0; j < numNeighbors; ++j)
{
int xNbr = x + neighbors[j][0];
int yNbr = y + neighbors[j][1];
if (0 <= xNbr && xNbr < dim0 && 0 <= yNbr && yNbr < dim1)
{
output(xNbr, yNbr) = 1;
}
}
}
}
}
}
示例4: Erode
//----------------------------------------------------------------------------
void ImageUtility2::Erode8(Image2<int> const& input, bool zeroExterior,
Image2<int>& output)
{
std::array<std::array<int, 2>, 8> neighbors;
input.GetNeighborhood(neighbors);
Erode(input, zeroExterior, 8, &neighbors[0], output);
}
示例5: GetComponents
//----------------------------------------------------------------------------
void ImageUtility2::GetComponents8(Image2<int>& image,
std::vector<std::vector<size_t>>& components)
{
std::array<int, 8> neighbors;
image.GetNeighborhood(neighbors);
GetComponents(8, &neighbors[0], image, components);
}
示例6: bool
//----------------------------------------------------------------------------
bool ImageUtility2::MarkInterior(Image2<int>& image, int value,
bool (*function)(Image2<int>&,int,int))
{
int const dim0 = image.GetDimension(0);
int const dim1 = image.GetDimension(1);
bool noInterior = true;
for (int y = 0; y < dim1; ++y)
{
for (int x = 0; x < dim0; ++x)
{
if (image(x, y) > 0)
{
if (function(image, x, y))
{
image(x, y) = value;
noInterior = false;
}
else
{
image(x, y) = 1;
}
}
}
}
return noInterior;
}
示例7: main
int main(int argc, char* argv[])
{
// check if all required arguments are present
if (argc < 7)
{
cerr << "Usage: " << argv[0] << " xMin xMax yMin yMax xRes yRes" << endl;
return 1;
}
// 1:xMin 2:xMax 3:yMin 4:yMax 5:xRes 6:yRes
Bitmap canvas( atof(argv[1]), atof(argv[2]), atof(argv[3]), atof(argv[4]) \
, atoi(argv[5]), atoi(argv[6]) );
// parse drawing commands from standard input
Image2 *image = parse_image(cin);
// for each polyline
for (Image2::iterator it1 = image->begin();
it1 != image->end();
it1++)
{
if ((*it1)->begin() == (*it1)->end())
continue;
Vec2 *v = (*it1)->front();
// for each vertex i, 2 <= i <= N
for (Polygon2::iterator it2 = ++((*it1)->begin());
it2 != (*it1)->end();
it2++)
{
// draw a line between vertex i-1 and vertex i
PixelCoord xy1 = canvas.ndc_to_pixel( (*v)[0], (*v)[1] );
v = (*it2);
PixelCoord xy2 = canvas.ndc_to_pixel( (*v)[0], (*v)[1] );
canvas.draw_pixel(bresenham(xy1,xy2));
}
}
canvas.print_ppm(cout);
return 0;
}
示例8: if
//----------------------------------------------------------------------------
void ImageUtility2::Erode(Image2<int> const& input, bool zeroExterior,
int numNeighbors, std::array<int, 2> const* neighbors,
Image2<int>& output)
{
// If the assertion is triggered, the function will run but the output
// will not be correct.
LogAssert(&output != &input, "Input and output must be different.");
output = input;
// If the pixel at (x,y) is 1, it is changed to 0 when at least one
// neighbor (x+dx,y+dy) is 0, where (dx,dy) is in the 'neighbors'
// array.
int const dim0 = input.GetDimension(0);
int const dim1 = input.GetDimension(1);
for (int y = 0; y < dim1; ++y)
{
for (int x = 0; x < dim0; ++x)
{
if (input(x, y) == 1)
{
for (int j = 0; j < numNeighbors; ++j)
{
int xNbr = x + neighbors[j][0];
int yNbr = y + neighbors[j][1];
if (0 <= xNbr && xNbr < dim0 && 0 <= yNbr && yNbr < dim1)
{
if (input(xNbr, yNbr) == 0)
{
output(x, y) = 0;
break;
}
}
else if (zeroExterior)
{
output(x, y) = 0;
break;
}
}
}
}
}
}
示例9: xNear
//----------------------------------------------------------------------------
void ImageUtility2::L2Check(int x, int y, int dx, int dy, Image2<int>& xNear,
Image2<int>& yNear, Image2<int>& dist)
{
int const dim0 = dist.GetDimension(0);
int const dim1 = dist.GetDimension(1);
int xp = x + dx, yp = y + dy;
if (0 <= xp && xp < dim0 && 0 <= yp && yp < dim1)
{
if (dist(xp, yp) < dist(x, y))
{
int dx0 = xNear(xp, yp) - x;
int dy0 = yNear(xp, yp) - y;
int newDist = dx0*dx0 + dy0*dy0;
if (newDist < dist(x, y))
{
xNear(x, y) = xNear(xp, yp);
yNear(x, y) = yNear(xp, yp);
dist(x, y) = newDist;
}
}
}
}
示例10: while
//----------------------------------------------------------------------------
void ImageUtility2::GetComponents(int numNeighbors, int const* delta,
Image2<int>& image, std::vector<std::vector<size_t>>& components)
{
size_t const numPixels = image.GetNumPixels();
int* numElements = new int[numPixels];
size_t* vstack = new size_t[numPixels];
size_t i, numComponents = 0;
int label = 2;
for (i = 0; i < numPixels; ++i)
{
if (image[i] == 1)
{
int top = -1;
vstack[++top] = i;
int& count = numElements[numComponents + 1];
count = 0;
while (top >= 0)
{
size_t v = vstack[top];
image[v] = -1;
int j;
for (j = 0; j < numNeighbors; ++j)
{
size_t adj = v + delta[j];
if (image[adj] == 1)
{
vstack[++top] = adj;
break;
}
}
if (j == numNeighbors)
{
image[v] = label;
++count;
--top;
}
}
++numComponents;
++label;
}
}
delete[] vstack;
if (numComponents > 0)
{
components.resize(numComponents + 1);
for (i = 1; i <= numComponents; ++i)
{
components[i].resize(numElements[i]);
numElements[i] = 0;
}
for (i = 0; i < numPixels; ++i)
{
int value = image[i];
if (value != 0)
{
// Labels started at 2 to support the depth-first search,
// so they need to be decremented for the correct labels.
image[i] = --value;
components[value][numElements[value]] = i;
++numElements[value];
}
}
}
delete[] numElements;
}
示例11: testComparison
bool testComparison(int size, int area, double dist)
{
static const DGtal::Dimension dimension = dim;
//Domain
typedef HyperRectDomain< SpaceND<dimension, int> > Domain;
typedef typename Domain::Point Point;
Domain d(Point::diagonal(-size), Point::diagonal(size));
DomainPredicate<Domain> dp(d);
//Image and set for FMM
typedef ImageContainerBySTLVector<Domain, long> Image;
Image map( d );
map.setValue( Point::diagonal(0), 0.0 );
typedef DigitalSetBySTLSet<Domain> Set;
Set set( d );
set.insert( Point::diagonal(0) );
//Image for separable DT
typedef Image Image2;
Image2 image ( d );
typename Domain::Iterator dit = d.begin();
typename Domain::Iterator ditEnd = d.end();
for ( ; dit != ditEnd; ++dit)
{
image.setValue(*dit, 128);
}
image.setValue(Point::diagonal(0), 0);
//computation
trace.beginBlock ( " FMM computation " );
typedef typename DistanceTraits<Image,Set,norm>::Distance Distance;
typedef FMM<Image, Set, DomainPredicate<Domain>, Distance > FMM;
Distance distance(map, set);
FMM fmm( map, set, dp, area, dist, distance );
fmm.compute();
trace.info() << fmm << std::endl;
trace.endBlock();
trace.beginBlock ( " DT computation " );
typedef SimpleThresholdForegroundPredicate<Image> Predicate;
Predicate aPredicate(image,0);
typedef ExactPredicateLpSeparableMetric<SpaceND<dimension,int>, norm> LNorm;
typedef DistanceTransformation<SpaceND<dimension,int>, Predicate, LNorm> DT;
LNorm lnorm;
DT dt(&d,&aPredicate, &lnorm);
trace.info() << dt << std::endl;
trace.endBlock();
bool flagIsOk = true;
trace.beginBlock ( " Comparison " );
//all points of result must be in map and have the same distance
typename Domain::ConstIterator it = d.begin();
typename Domain::ConstIterator itEnd = d.end();
for ( ; ( (it != itEnd)&&(flagIsOk) ); ++it)
{
if (set.find(*it) == set.end())
flagIsOk = false;
else
{
if (dt(*it) != map(*it))
flagIsOk = false;
}
}
trace.endBlock();
return flagIsOk;
}
示例12: Dilate
//----------------------------------------------------------------------------
void ImageUtility2::Dilate8(Image2<int> const& input, Image2<int>& output)
{
std::array<std::array<int, 2>, 8> neighbors;
input.GetNeighborhood(neighbors);
Dilate(input, 8, &neighbors[0], output);
}
示例13: SaveBMP32
//----------------------------------------------------------------------------
bool SaveBMP32 (const std::string& name, const Image2<PixelBGRA8>& image)
{
FILE* outFile = fopen(name.c_str(), "wb");
if (!outFile)
{
assertion(false, "Cannot open file '%s' for write.\n", name.c_str());
return false;
}
const int numPixels = image.GetNumPixels();
const int numBytes = 4*image.GetNumPixels();
const int size = sizeOfBitMapFileHeader + sizeOfBitMapInfoHeader;
PrivateBitMapFileHeader fileHeader;
fileHeader.bfType = 0x4d42;
fileHeader.bfSize = size + numBytes;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = size;
size_t numWritten = fwrite(&fileHeader.bfType, sizeof(unsigned short),
1, outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (bfType).\n");
fclose(outFile);
return false;
}
numWritten = fwrite(&fileHeader.bfSize, sizeof(unsigned long), 1,
outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (bfSize).\n");
fclose(outFile);
return false;
}
numWritten = fwrite(&fileHeader.bfReserved1, sizeof(unsigned short), 1,
outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (bfReserved1).\n");
fclose(outFile);
return false;
}
numWritten = fwrite(&fileHeader.bfReserved2, sizeof(unsigned short), 1,
outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (bfReserved2).\n");
fclose(outFile);
return false;
}
numWritten = fwrite(&fileHeader.bfOffBits, sizeof(unsigned long), 1,
outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (bfOffBits).\n");
fclose(outFile);
return false;
}
PrivateBitMapInfoHeader infoHeader;
infoHeader.biSize = sizeOfBitMapInfoHeader;
infoHeader.biWidth = image.GetDimension(0);
infoHeader.biHeight = image.GetDimension(1);
infoHeader.biPlanes = 1;
infoHeader.biBitCount = 32;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = 0;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;
numWritten = fwrite(&infoHeader, sizeOfBitMapInfoHeader, 1, outFile);
if (numWritten != 1)
{
assertion(false, "Failed to write (infoHeader).\n");
fclose(outFile);
return false;
}
PixelBGRA8* source = image.GetPixels1D();
numWritten = fwrite(source, sizeof(PixelBGRA8), numPixels, outFile);
if (numWritten != (size_t)numPixels)
{
assertion(false, "Failed to write (source).\n");
fclose(outFile);
return false;
}
fclose(outFile);
return true;
}