本文整理汇总了C++中imagetype::Pointer::Allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::Allocate方法的具体用法?C++ Pointer::Allocate怎么用?C++ Pointer::Allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagetype::Pointer
的用法示例。
在下文中一共展示了Pointer::Allocate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildOutput
// ------------------------------------------------------------------------
void buildOutput(const SeriesTransform::List &series, ImageType::Pointer &outputImage,
ImageType::Pointer &outputLabel, const unsigned int & timestep)
{
// get the output parameters
unsigned int slices = series.size();
unsigned int timeSteps = series.front().images.size();
ImageType::Pointer ref = series.front().images.front();
ImageType::SpacingType spacing = ref->GetSpacing();
spacing[2] = series.front().sliceThickness;
ImageType::DirectionType direction = ref->GetDirection();
ImageType::PointType origin = ref->GetOrigin();
ImageType::RegionType region = ref->GetLargestPossibleRegion();
region.SetSize(2,slices);
// create the outputs
outputImage->SetSpacing(spacing);
outputImage->SetDirection(direction);
outputImage->SetOrigin(origin);
outputImage->SetRegions(region);
outputImage->Allocate();
outputLabel->SetSpacing(spacing);
outputLabel->SetDirection(direction);
outputLabel->SetOrigin(origin);
outputLabel->SetRegions(region);
outputLabel->Allocate();
itk::ImageRegionIterator<ImageType> outLIt(outputLabel, outputLabel->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> outImIt(outputImage, outputImage->GetLargestPossibleRegion());
// loop through the slices
for(unsigned int i = 0; i < slices; i++)
{
ImageType::Pointer im = series[i].images[timestep];
ImageType::Pointer label = series[i].labelImages[timestep];
itk::ImageRegionConstIterator<ImageType> imIt(im, im->GetLargestPossibleRegion());
itk::ImageRegionConstIterator<ImageType> lIt(label, label->GetLargestPossibleRegion());
while(!imIt.IsAtEnd())
{
outLIt.Set(lIt.Get());
outImIt.Set(imIt.Get());
++imIt; ++lIt;
++outLIt; ++outImIt;
}
}
}
示例2: TestIsClosedLoop
bool TestIsClosedLoop()
{
std::cout << "TestIsClosedLoop()" << std::endl;
// Open loop
{
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{100,100}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(itk::Index<2>::IndexValueType i = 20; i < 30; ++i)
{
itk::Index<2> pixel = {{i, 50}};
image->SetPixel(pixel, 255);
}
itk::Index<2> start = {{25, 50}};
bool isClosedLoop = ITKHelpers::IsClosedLoop(image.GetPointer(), start);
std::cout << "Is closed loop? " << isClosedLoop << std::endl;
}
// Closed loop
{
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{100,100}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
itk::Index<2> corner0 = {{10,10}};
itk::Index<2> corner1 = {{30,30}};
ITKHelpers::DrawRectangle(image.GetPointer(), 255,
corner0, corner1);
itk::Index<2> start = {{10, 10}};
bool isClosedLoop = ITKHelpers::IsClosedLoop(image.GetPointer(), start);
std::cout << "Is closed loop? " << isClosedLoop << std::endl;
}
return true;
}
示例3: TestGetOpenContourOrdering
void TestGetOpenContourOrdering()
{
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{100,100}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(unsigned int i = 20; i < 30; ++i)
{
itk::Index<2> pixel = {{i, 50}};
image->SetPixel(pixel, 255);
}
itk::Index<2> start = {{25, 50}};
std::vector<itk::Index<2> > contourOrdering = ITKHelpers::GetOpenContourOrdering(image.GetPointer(), start);
for(unsigned int i = 0; i < contourOrdering.size(); ++i)
{
//std::cout << breadthFirstOrdering[i] << " ";
std::cout << contourOrdering[i] << std::endl;
}
std::cout << std::endl;
}
示例4: main
int main()
{
std::string votesfilename = "../../half_vessel_votes2.txt";
std::string outputfilename = "half_vessel_votes2.tif";
FILE * fp = fopen(votesfilename.c_str(), "r");
int x,y,z,v;
int maxx = -1,maxy = -1, maxz = -1;
while(fscanf(fp,"%d %d %d %d",&x,&y,&z,&v)>0)
{
maxx = MAX(maxx, x);
maxy = MAX(maxy, y);
maxz = MAX(maxz, z);
}
printf("maxx = %d maxy = %d maxz = %d\n",maxx,maxy,maxz);
fclose(fp);
fp = fopen(votesfilename.c_str(), "r");
ImageType::Pointer im = ImageType::New();
ImageType::SizeType size;
ImageType::IndexType index;
ImageType::RegionType region;
size[0] = maxx+1;
size[1] = maxy+1;
size[2] = maxz+1;
index[0] = index[1] = index[2] = 0;
region.SetIndex(index);
region.SetSize(size);
im->SetRegions(region);
im->Allocate();
while(fscanf(fp,"%d %d %d %d",&x,&y,&z,&v)>0)
{
index[0] = x;
index[1] = y;
index[2] = z;
im->SetPixel(index,v);
}
// scanf("%*d");
fclose(fp);
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName(outputfilename.c_str());
writer->SetInput(im);
writer->Update();
return 0;
}
示例5: TestBreadthFirstOrderingNonZeroPixels
bool TestBreadthFirstOrderingNonZeroPixels()
{
std::cout << "TestBreadthFirstOrderingNonZeroPixels()" << std::endl;
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{100,100}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
for(itk::Index<2>::IndexValueType i = 20; i < 30; ++i)
{
itk::Index<2> pixel = {{i, 50}};
image->SetPixel(pixel, 255);
}
itk::Index<2> start = {{25, 50}};
std::vector<itk::Index<2> > breadthFirstOrdering =
ITKHelpers::BreadthFirstOrderingNonZeroPixels(image.GetPointer(), start);
for(unsigned int i = 0; i < breadthFirstOrdering.size(); ++i)
{
//std::cout << breadthFirstOrdering[i] << " ";
std::cout << breadthFirstOrdering[i] << std::endl;
}
std::cout << std::endl;
return true;
}
示例6: main
int main()
{
typedef itk::Image<itk::CovariantVector<float, 2>, 2> ImageType;
ImageType::Pointer image = ImageType::New();
ImageType::IndexType corner = {{0,0}};
ImageType::SizeType size = {{100,100}};
ImageType::RegionType region(corner, size);
image->SetRegions(region);
image->Allocate();
typedef ImageType::PixelType::RealValueType ScalarType;
typedef itk::NormImageAdaptor<ImageType, ScalarType>
NormImageAdaptorType;
typename NormImageAdaptorType::Pointer imageAdaptor = NormImageAdaptorType::New();
imageAdaptor->SetImage(image);
ScalarType rangeMin = 0;
ScalarType rangeMax = 255;
unsigned int numberOfBins = 10;
typedef int BinValueType;
typedef HistogramGenerator<BinValueType> HistogramGeneratorType;
typedef HistogramGeneratorType::HistogramType HistogramType;
HistogramType histogram =
HistogramGeneratorType::ComputeImageHistogram1D(imageAdaptor.GetPointer(),
imageAdaptor->GetLargestPossibleRegion(),
numberOfBins, rangeMin, rangeMax);
histogram.Print();
std::cout << std::endl;
return 0;
}
示例7: TestGetClosedContourOrdering
void TestGetClosedContourOrdering()
{
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{100,100}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
itk::Index<2> corner0 = {{10,10}};
itk::Index<2> corner1 = {{30,30}};
ITKHelpers::DrawRectangle(image.GetPointer(), 255,
corner0, corner1);
itk::Index<2> start = {{10, 10}};
std::vector<itk::Index<2> > ordering = ITKHelpers::GetClosedContourOrdering(image.GetPointer(), start);
for(unsigned int i = 0; i < ordering.size(); ++i)
{
std::cout << ordering[i] << std::endl;
}
std::cout << std::endl;
}
示例8: toItkImage
ImageType::Pointer TDimImage::toItkImage( const unsigned int &channel ) const {
int sample = std::min<int>( this->samples()-1, channel);
int bitdepth = sizeof(PixelType);
D_DataFormat pf = D_FMT_UNSIGNED;
if (!std::numeric_limits<PixelType>::is_integer)
pf = D_FMT_FLOAT;
else
if (std::numeric_limits<PixelType>::is_signed)
pf = D_FMT_SIGNED;
TDimImage img;
if (this->depth()!=bitdepth || this->pixelType()!=pf) {
img = this->ensureTypedDepth();
img = img.convertToDepth( bitdepth, DimLut::ltLinearDataRange, pf );
} else
img = *this;
//------------------------------------------------------------------
// Create Itk Image and copy data
//------------------------------------------------------------------
ImageType::Pointer image = ImageType::New();
ImageType::SizeType size;
size[0] = nx;
size[1] = ny;
ImageType::IndexType start;
start[0] = 0;
start[1] = 0;
ImageType::RegionType region;
region.SetSize( size );
region.SetIndex( start );
image->SetRegions( region );
image->Allocate();
double spacing[2];
spacing[0] = 1.0;
spacing[1] = 1.0;
image->SetSpacing( spacing );
double origin[2];
origin[0] = 0.0;
origin[1] = 0.0;
image->SetOrigin( origin );
typedef itk::ImageRegionIterator< ImageType > IteratorType;
IteratorType it( image, region );
it.GoToBegin();
// copy data
PixelType *data = (PixelType *) img.sampleBits(sample);
while( ! it.IsAtEnd() ) {
it.Set( *data );
++it;
++data;
}
return image;
}
示例9: main
int main(int, char* [] )
{
typedef itk::Image<unsigned char, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner={{0,0}};
itk::Size<2> size = {{10,10}};
itk::ImageRegion<2> region(corner,size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
unsigned char searchValue = 255; // This value does not appear in the image, so both functions
// will have to search the entire image.
int counter = 0;
for(unsigned int i = 0; i < 1e7; ++i)
{
// counter += HasValue(image.GetPointer(), searchValue); // About 3 seconds
counter += HasValueConditional(image.GetPointer(), searchValue); // About 3.3 seconds
}
std::cout << "counter " << counter << std::endl;
return 0;
}
示例10: setup_snapshot_image
void setup_snapshot_image(string basename, ImageType::Pointer model)
{
ImageType::SpacingType spacing = model->GetSpacing();
spacing[0] /= constants::SnapshotImageZoom;
spacing[1] /= constants::SnapshotImageZoom;
spacing[2] /= constants::SnapshotImageZoom;
g_snapshot_image = ImageType::New();
g_snapshot_image->SetSpacing( spacing );
g_snapshot_image->SetOrigin( model->GetOrigin() );
ImageType::RegionType const& region = model->GetLargestPossibleRegion();
ImageType::RegionType::SizeType size = region.GetSize();
// size is in pixels
ImageType::SizeType doubled_size(size);
doubled_size[0] *= constants::SnapshotImageZoom;
doubled_size[1] *= constants::SnapshotImageZoom;
doubled_size[2] *= constants::SnapshotImageZoom;
g_snapshot_image->SetRegions( doubled_size );
g_snapshot_image->Allocate();
s_snapshot_basename = basename;
}
示例11: ITKImage
void ITKImage()
{
typedef itk::Image<float, 2> ImageType;
ImageType::Pointer image = ImageType::New();
itk::Index<2> corner = {{0,0}};
itk::Size<2> size = {{20, 20}};
itk::ImageRegion<2> region(corner, size);
image->SetRegions(region);
image->Allocate();
itk::ImageRegionIterator<ImageType> imageIterator(image, region);
itk::TimeProbe clock1;
clock1.Start();
while(!imageIterator.IsAtEnd())
{
float a = imageIterator.Get() - imageIterator.Get();
++imageIterator;
}
clock1.Stop();
std::cout << "Total: " << clock1.GetTotal() << std::endl;
}
示例12: saveNRRDFile
void NRRDTools::saveNRRDFile(const cleaver::FloatField *field, const std::string &name) {
auto dims = field->dataBounds().size;
ImageType::Pointer img = ImageType::New();
itk::Index<3> start; start.Fill(0);
ImageType::SizeType size;
size[0] = static_cast<size_t>(dims[0]);
size[1] = static_cast<size_t>(dims[1]);
size[2] = static_cast<size_t>(dims[2]);
ImageType::RegionType region(start, size);
img->SetRegions(region);
img->Allocate();
img->FillBuffer(0);
for (size_t i = 0; i < dims[0]; i++) {
for (size_t j = 0; j < dims[1]; j++) {
for (size_t k = 0; k < dims[2]; k++) {
ImageType::IndexType pixelIndex;
pixelIndex[0] = i;
pixelIndex[1] = j;
pixelIndex[2] = k;
auto data = ((cleaver::FloatField*)field)->data();
img->SetPixel(pixelIndex, data[i + size[0] * j + size[0] * size[1] * k]);
}
}
}
WriterType::Pointer write = WriterType::New();
write->SetFileName(name + ((name.find_first_of(".nrrd") == std::string::npos) ? ".nrrd" : ""));
write->SetInput(img);
write->Update();
}
示例13: CreateKernel
void CreateKernel(ImageType::Pointer kernel, unsigned int width)
{
ImageType::IndexType start;
start.Fill(0);
ImageType::SizeType size;
size.Fill(width);
ImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
kernel->SetRegions(region);
kernel->Allocate();
itk::ImageRegionIterator<ImageType> imageIterator(kernel, region);
while(!imageIterator.IsAtEnd())
{
//imageIterator.Set(255);
imageIterator.Set(1);
++imageIterator;
}
}
示例14: PixelvalueBasedTest
/*
* random a voxel. define plane through this voxel. reslice at the plane. compare the pixel vaues of the voxel
* in the volume with the pixel value in the resliced image.
* there are some indice shifting problems which causes the test to fail for oblique planes. seems like the chosen
* worldcoordinate is not corrresponding to the index in the 2D image. and so the pixel values are not the same as
* expected.
*/
static void PixelvalueBasedTest()
{
/* setup itk image */
typedef itk::Image<unsigned short, 3> ImageType;
typedef itk::ImageRegionConstIterator< ImageType > ImageIterator;
ImageType::Pointer image = ImageType::New();
ImageType::IndexType start;
start[0] = start[1] = start[2] = 0;
ImageType::SizeType size;
size[0] = size[1] = size[2] = 32;
ImageType::RegionType imgRegion;
imgRegion.SetSize(size);
imgRegion.SetIndex(start);
image->SetRegions(imgRegion);
image->SetSpacing(1.0);
image->Allocate();
ImageIterator imageIterator( image, image->GetLargestPossibleRegion() );
imageIterator.GoToBegin();
unsigned short pixelValue = 0;
//fill the image with distinct values
while ( !imageIterator.IsAtEnd() )
{
image->SetPixel(imageIterator.GetIndex(), pixelValue);
++imageIterator;
++pixelValue;
}
/* end setup itk image */
mitk::Image::Pointer imageInMitk;
CastToMitkImage(image, imageInMitk);
/*mitk::ImageWriter::Pointer writer = mitk::ImageWriter::New();
writer->SetInput(imageInMitk);
std::string file = "C:\\Users\\schroedt\\Desktop\\cube.nrrd";
writer->SetFileName(file);
writer->Update();*/
PixelvalueBasedTestByPlane(imageInMitk, mitk::PlaneGeometry::Frontal);
PixelvalueBasedTestByPlane(imageInMitk, mitk::PlaneGeometry::Sagittal);
PixelvalueBasedTestByPlane(imageInMitk, mitk::PlaneGeometry::Axial);
}
示例15: main
int main(int argc, char *argv[])
{
// Verify arguments
if(argc < 6)
{
std::cerr << "Required: outputFilename sizeX sizeY components value" << std::endl;
return EXIT_FAILURE;
}
// Parse arguments
std::string outputFilename = argv[1];
std::stringstream ss;
ss << argv[2] << " " << argv[3] << " " << argv[4];
itk::Size<2> size = {{0,0}};
unsigned int components = 0;
float value = 0.0f;
ss >> size[0] >> size[1] >> components >> value;
// Output arguments
std::cout << "outputFilename " << outputFilename << std::endl;
std::cout << "size " << size << std::endl;
std::cout << "value " << value << std::endl;
ImageType::Pointer image = ImageType::New();
itk::Index<2> index = {{0,0}};
itk::ImageRegion<2> region(index, size);
image->SetRegions(region);
image->SetNumberOfComponentsPerPixel(components);
image->Allocate();
typename itk::ImageRegionIterator<ImageType> imageIterator(image, image->GetLargestPossibleRegion());
ImageType::PixelType pixel;
pixel.SetSize(components);
pixel.Fill(value);
while(!imageIterator.IsAtEnd())
{
imageIterator.Set(pixel);
++imageIterator;
}
// Write the result
typedef itk::ImageFileWriter<ImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outputFilename);
writer->SetInput(image);
writer->Update();
return EXIT_SUCCESS;
}