本文整理汇总了C++中image::Pointer::GetDimension方法的典型用法代码示例。如果您正苦于以下问题:C++ Pointer::GetDimension方法的具体用法?C++ Pointer::GetDimension怎么用?C++ Pointer::GetDimension使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类image::Pointer
的用法示例。
在下文中一共展示了Pointer::GetDimension方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pixelType
mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode( Image* original, const std::string& organName, const mitk::Color& color )
{
// we NEED a reference image for size etc.
if (!original) return NULL;
// actually create a new empty segmentation
PixelType pixelType(mitk::MakeScalarPixelType<DefaultSegmentationDataType>() );
Image::Pointer segmentation = Image::New();
if (original->GetDimension() == 2)
{
const unsigned int dimensions[] = { original->GetDimension(0), original->GetDimension(1), 1 };
segmentation->Initialize(pixelType, 3, dimensions);
}
else
{
segmentation->Initialize(pixelType, original->GetDimension(), original->GetDimensions());
}
unsigned int byteSize = sizeof(DefaultSegmentationDataType);
if(segmentation->GetDimension() < 4)
{
for (unsigned int dim = 0; dim < segmentation->GetDimension(); ++dim)
{
byteSize *= segmentation->GetDimension(dim);
}
mitk::ImageWriteAccessor writeAccess(segmentation, segmentation->GetVolumeData(0));
memset( writeAccess.GetData(), 0, byteSize );
}
else
{//if we have a time-resolved image we need to set memory to 0 for each time step
for (unsigned int dim = 0; dim < 3; ++dim)
{
byteSize *= segmentation->GetDimension(dim);
}
for( unsigned int volumeNumber = 0; volumeNumber < segmentation->GetDimension(3); volumeNumber++)
{
mitk::ImageWriteAccessor writeAccess(segmentation, segmentation->GetVolumeData(volumeNumber));
memset( writeAccess.GetData(), 0, byteSize );
}
}
if (original->GetTimeGeometry() )
{
TimeGeometry::Pointer originalGeometry = original->GetTimeGeometry()->Clone();
segmentation->SetTimeGeometry( originalGeometry );
}
else
{
Tool::ErrorMessage("Original image does not have a 'Time sliced geometry'! Cannot create a segmentation.");
return NULL;
}
return CreateSegmentationNode( segmentation, organName, color );
}
示例2: workingNode
void mitk::SegTool2D::WriteBackSegmentationResult(std::vector<mitk::SegTool2D::SliceInformation> sliceList, bool writeSliceToVolume)
{
std::vector<mitk::Surface::Pointer> contourList;
contourList.reserve(sliceList.size());
ImageToContourFilter::Pointer contourExtractor = ImageToContourFilter::New();
DataNode* workingNode( m_ToolManager->GetWorkingData(0) );
Image* image = dynamic_cast<Image*>(workingNode->GetData());
mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New();
timeSelector->SetInput( image );
timeSelector->SetTimeNr( 0 );
timeSelector->SetChannelNr( 0 );
timeSelector->Update();
Image::Pointer dimRefImg = timeSelector->GetOutput();
for (unsigned int i = 0; i < sliceList.size(); ++i)
{
SliceInformation currentSliceInfo = sliceList.at(i);
if(writeSliceToVolume)
this->WriteSliceToVolume(currentSliceInfo);
if (m_SurfaceInterpolationEnabled && dimRefImg->GetDimension() == 3)
{
currentSliceInfo.slice->DisconnectPipeline();
contourExtractor->SetInput(currentSliceInfo.slice);
contourExtractor->Update();
mitk::Surface::Pointer contour = contourExtractor->GetOutput();
contour->DisconnectPipeline();
contourList.push_back(contour);
}
}
mitk::SurfaceInterpolationController::GetInstance()->AddNewContours(contourList);
mitk::RenderingManager::GetInstance()->RequestUpdateAll();
}
示例3:
void mitk::SegTool2D::UpdateSurfaceInterpolation(const Image *slice,
const Image *workingImage,
const PlaneGeometry *plane,
bool detectIntersection)
{
if (!m_SurfaceInterpolationEnabled)
return;
ImageToContourFilter::Pointer contourExtractor = ImageToContourFilter::New();
mitk::Surface::Pointer contour;
if (detectIntersection)
{
// Test whether there is something to extract or whether the slice just contains intersections of others
mitk::Image::Pointer slice2 = slice->Clone();
mitk::MorphologicalOperations::Erode(slice2, 2, mitk::MorphologicalOperations::Ball);
contourExtractor->SetInput(slice2);
contourExtractor->Update();
contour = contourExtractor->GetOutput();
if (contour->GetVtkPolyData()->GetNumberOfPoints() == 0)
{
// Remove contour!
mitk::SurfaceInterpolationController::ContourPositionInformation contourInfo;
contourInfo.contourNormal = plane->GetNormal();
contourInfo.contourPoint = plane->GetOrigin();
mitk::SurfaceInterpolationController::GetInstance()->RemoveContour(contourInfo);
return;
}
}
contourExtractor->SetInput(slice);
contourExtractor->Update();
contour = contourExtractor->GetOutput();
mitk::ImageTimeSelector::Pointer timeSelector = mitk::ImageTimeSelector::New();
timeSelector->SetInput(workingImage);
timeSelector->SetTimeNr(0);
timeSelector->SetChannelNr(0);
timeSelector->Update();
Image::Pointer dimRefImg = timeSelector->GetOutput();
if (contour->GetVtkPolyData()->GetNumberOfPoints() != 0 && dimRefImg->GetDimension() == 3)
{
mitk::SurfaceInterpolationController::GetInstance()->AddNewContour(contour);
contour->DisconnectPipeline();
}
else
{
// Remove contour!
mitk::SurfaceInterpolationController::ContourPositionInformation contourInfo;
contourInfo.contourNormal = plane->GetNormal();
contourInfo.contourPoint = plane->GetOrigin();
mitk::SurfaceInterpolationController::GetInstance()->RemoveContour(contourInfo);
}
}
示例4: itkExceptionMacro
void mitk::CorrectorAlgorithm::GenerateData()
{
Image::Pointer inputImage = const_cast<Image*>(ImageToImageFilter::GetInput(0));
if (inputImage.IsNull() || inputImage->GetDimension() != 2)
{
itkExceptionMacro("CorrectorAlgorithm needs a 2D image as input.");
}
if (m_Contour.IsNull())
{
itkExceptionMacro("CorrectorAlgorithm needs a Contour object as input.");
}
// copy the input (since m_WorkingImage will be changed later)
m_WorkingImage = inputImage;
TimeGeometry::Pointer originalGeometry = NULL;
if (inputImage->GetTimeGeometry() )
{
originalGeometry = inputImage->GetTimeGeometry()->Clone();
m_WorkingImage->SetTimeGeometry( originalGeometry );
}
else
{
itkExceptionMacro("Original image does not have a 'Time sliced geometry'! Cannot copy.");
}
Image::Pointer temporarySlice;
// Convert to ipMITKSegmentationTYPE (because TobiasHeimannCorrectionAlgorithm relys on that data type)
{
itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer correctPixelTypeImage;
CastToItkImage( m_WorkingImage, correctPixelTypeImage );
assert (correctPixelTypeImage.IsNotNull() );
// possible bug in CastToItkImage ?
// direction maxtrix is wrong/broken/not working after CastToItkImage, leading to a failed assertion in
// mitk/Core/DataStructures/mitkSlicedGeometry3D.cpp, 479:
// virtual void mitk::SlicedGeometry3D::SetSpacing(const mitk::Vector3D&): Assertion `aSpacing[0]>0 && aSpacing[1]>0 && aSpacing[2]>0' failed
// solution here: we overwrite it with an unity matrix
itk::Image< ipMITKSegmentationTYPE, 2 >::DirectionType imageDirection;
imageDirection.SetIdentity();
//correctPixelTypeImage->SetDirection(imageDirection);
temporarySlice = this->GetOutput();
// temporarySlice = ImportItkImage( correctPixelTypeImage );
m_FillColor = 1;
m_EraseColor = 0;
ImprovedHeimannCorrectionAlgorithm(correctPixelTypeImage);
CastToMitkImage( correctPixelTypeImage, temporarySlice );
}
temporarySlice->SetTimeGeometry(originalGeometry);
}
示例5: pixelType
mitk::DataNode::Pointer mitk::Tool::CreateEmptySegmentationNode( Image* original, const std::string& organName, const mitk::Color& color )
{
// we NEED a reference image for size etc.
if (!original) return NULL;
// actually create a new empty segmentation
PixelType pixelType(mitk::MakeScalarPixelType<DefaultSegmentationDataType>() );
Image::Pointer segmentation = Image::New();
if (original->GetDimension() == 2)
{
const unsigned int dimensions[] = { original->GetDimension(0), original->GetDimension(1), 1 };
segmentation->Initialize(pixelType, 3, dimensions);
}
else
{
segmentation->Initialize(pixelType, original->GetDimension(), original->GetDimensions());
}
unsigned int byteSize = sizeof(DefaultSegmentationDataType);
for (unsigned int dim = 0; dim < segmentation->GetDimension(); ++dim)
{
byteSize *= segmentation->GetDimension(dim);
}
memset( segmentation->GetData(), 0, byteSize );
if (original->GetTimeSlicedGeometry() )
{
AffineGeometryFrame3D::Pointer originalGeometryAGF = original->GetTimeSlicedGeometry()->Clone();
TimeSlicedGeometry::Pointer originalGeometry = dynamic_cast<TimeSlicedGeometry*>( originalGeometryAGF.GetPointer() );
segmentation->SetGeometry( originalGeometry );
}
else
{
Tool::ErrorMessage("Original image does not have a 'Time sliced geometry'! Cannot create a segmentation.");
return NULL;
}
return CreateSegmentationNode( segmentation, organName, color );
}
示例6: ReadPixel
static void ReadPixel(const PixelType&, Image::Pointer image, const itk::Index<3>& index, ScalarType* returnValue)
{
switch (image->GetDimension())
{
case 2:
{
ImagePixelReadAccessor<T, 2> readAccess(image, image->GetSliceData(0));
*returnValue = readAccess.GetPixelByIndex(reinterpret_cast<const itk::Index<2>&>(index));
break;
}
case 3:
{
ImagePixelReadAccessor<T, 3> readAccess(image, image->GetVolumeData(0));
*returnValue = readAccess.GetPixelByIndex(index);
break;
}
default:
*returnValue = 0;
break;
}
}
示例7: ThreadedUpdateFunction
bool ShowSegmentationAsSmoothedSurface::ThreadedUpdateFunction()
{
Image::Pointer image;
GetPointerParameter("Input", image);
float smoothing;
GetParameter("Smoothing", smoothing);
float decimation;
GetParameter("Decimation", decimation);
float closing;
GetParameter("Closing", closing);
int timeNr = 0;
GetParameter("TimeNr", timeNr);
if (image->GetDimension() == 4)
MITK_INFO << "CREATING SMOOTHED POLYGON MODEL (t = " << timeNr << ')';
else
MITK_INFO << "CREATING SMOOTHED POLYGON MODEL";
MITK_INFO << " Smoothing = " << smoothing;
MITK_INFO << " Decimation = " << decimation;
MITK_INFO << " Closing = " << closing;
Geometry3D::Pointer geometry = dynamic_cast<Geometry3D *>(image->GetGeometry()->Clone().GetPointer());
// Make ITK image out of MITK image
typedef itk::Image<unsigned char, 3> CharImageType;
typedef itk::Image<unsigned short, 3> ShortImageType;
typedef itk::Image<float, 3> FloatImageType;
if (image->GetDimension() == 4)
{
ImageTimeSelector::Pointer imageTimeSelector = ImageTimeSelector::New();
imageTimeSelector->SetInput(image);
imageTimeSelector->SetTimeNr(timeNr);
imageTimeSelector->UpdateLargestPossibleRegion();
image = imageTimeSelector->GetOutput(0);
}
ImageToItk<CharImageType>::Pointer imageToItkFilter = ImageToItk<CharImageType>::New();
try
{
imageToItkFilter->SetInput(image);
}
catch (const itk::ExceptionObject &e)
{
// Most probably the input image type is wrong. Binary images are expected to be
// >unsigned< char images.
MITK_ERROR << e.GetDescription() << endl;
return false;
}
imageToItkFilter->Update();
CharImageType::Pointer itkImage = imageToItkFilter->GetOutput();
// Get bounding box and relabel
MITK_INFO << "Extracting VOI...";
int imageLabel = 1;
bool roiFound = false;
CharImageType::IndexType minIndex;
minIndex.Fill(numeric_limits<CharImageType::IndexValueType>::max());
CharImageType::IndexType maxIndex;
maxIndex.Fill(numeric_limits<CharImageType::IndexValueType>::min());
itk::ImageRegionIteratorWithIndex<CharImageType> iter(itkImage, itkImage->GetLargestPossibleRegion());
for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter)
{
if (iter.Get() == imageLabel)
{
roiFound = true;
iter.Set(1);
CharImageType::IndexType currentIndex = iter.GetIndex();
for (unsigned int dim = 0; dim < 3; ++dim)
{
minIndex[dim] = min(currentIndex[dim], minIndex[dim]);
maxIndex[dim] = max(currentIndex[dim], maxIndex[dim]);
}
}
else
{
iter.Set(0);
}
}
if (!roiFound)
{
ProgressBar::GetInstance()->Progress(8);
//.........这里部分代码省略.........
示例8: localeSwitch
std::vector<BaseData::Pointer> ItkImageIO::Read()
{
std::vector<BaseData::Pointer> result;
mitk::LocaleSwitch localeSwitch("C");
Image::Pointer image = Image::New();
const unsigned int MINDIM = 2;
const unsigned int MAXDIM = 4;
const std::string path = this->GetLocalFileName();
MITK_INFO << "loading " << path << " via itk::ImageIOFactory... " << std::endl;
// Check to see if we can read the file given the name or prefix
if (path.empty())
{
mitkThrow() << "Empty filename in mitk::ItkImageIO ";
}
// Got to allocate space for the image. Determine the characteristics of
// the image.
m_ImageIO->SetFileName(path);
m_ImageIO->ReadImageInformation();
unsigned int ndim = m_ImageIO->GetNumberOfDimensions();
if (ndim < MINDIM || ndim > MAXDIM)
{
MITK_WARN << "Sorry, only dimensions 2, 3 and 4 are supported. The given file has " << ndim
<< " dimensions! Reading as 4D.";
ndim = MAXDIM;
}
itk::ImageIORegion ioRegion(ndim);
itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();
itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
unsigned int dimensions[MAXDIM];
dimensions[0] = 0;
dimensions[1] = 0;
dimensions[2] = 0;
dimensions[3] = 0;
ScalarType spacing[MAXDIM];
spacing[0] = 1.0f;
spacing[1] = 1.0f;
spacing[2] = 1.0f;
spacing[3] = 1.0f;
Point3D origin;
origin.Fill(0);
unsigned int i;
for (i = 0; i < ndim; ++i)
{
ioStart[i] = 0;
ioSize[i] = m_ImageIO->GetDimensions(i);
if (i < MAXDIM)
{
dimensions[i] = m_ImageIO->GetDimensions(i);
spacing[i] = m_ImageIO->GetSpacing(i);
if (spacing[i] <= 0)
spacing[i] = 1.0f;
}
if (i < 3)
{
origin[i] = m_ImageIO->GetOrigin(i);
}
}
ioRegion.SetSize(ioSize);
ioRegion.SetIndex(ioStart);
MITK_INFO << "ioRegion: " << ioRegion << std::endl;
m_ImageIO->SetIORegion(ioRegion);
void *buffer = new unsigned char[m_ImageIO->GetImageSizeInBytes()];
m_ImageIO->Read(buffer);
image->Initialize(MakePixelType(m_ImageIO), ndim, dimensions);
image->SetImportChannel(buffer, 0, Image::ManageMemory);
const itk::MetaDataDictionary &dictionary = m_ImageIO->GetMetaDataDictionary();
// access direction of itk::Image and include spacing
mitk::Matrix3D matrix;
matrix.SetIdentity();
unsigned int j, itkDimMax3 = (ndim >= 3 ? 3 : ndim);
for (i = 0; i < itkDimMax3; ++i)
for (j = 0; j < itkDimMax3; ++j)
matrix[i][j] = m_ImageIO->GetDirection(j)[i];
// re-initialize PlaneGeometry with origin and direction
PlaneGeometry *planeGeometry = image->GetSlicedGeometry(0)->GetPlaneGeometry(0);
planeGeometry->SetOrigin(origin);
planeGeometry->GetIndexToWorldTransform()->SetMatrix(matrix);
// re-initialize SlicedGeometry3D
SlicedGeometry3D *slicedGeometry = image->GetSlicedGeometry(0);
slicedGeometry->InitializeEvenlySpaced(planeGeometry, image->GetDimension(2));
slicedGeometry->SetSpacing(spacing);
//.........这里部分代码省略.........
示例9: ThreadedUpdateFunction
bool ShowSegmentationAsSurface::ThreadedUpdateFunction()
{
Image::Pointer image;
GetPointerParameter("Input", image);
bool smooth(true);
GetParameter("Smooth", smooth);
bool applyMedian(true);
GetParameter("Apply median", applyMedian);
bool decimateMesh(true);
GetParameter("Decimate mesh", decimateMesh);
unsigned int medianKernelSize(3);
GetParameter("Median kernel size", medianKernelSize);
float gaussianSD(1.5);
GetParameter("Gaussian SD", gaussianSD);
float reductionRate(0.8);
GetParameter("Decimation rate", reductionRate);
MITK_INFO << "Creating polygon model with smoothing " << smooth << " gaussianSD " << gaussianSD << " median "
<< applyMedian << " median kernel " << medianKernelSize << " mesh reduction " << decimateMesh
<< " reductionRate " << reductionRate;
ManualSegmentationToSurfaceFilter::Pointer surfaceFilter = ManualSegmentationToSurfaceFilter::New();
surfaceFilter->SetInput(image);
surfaceFilter->SetThreshold(0.5); // expects binary image with zeros and ones
surfaceFilter->SetUseGaussianImageSmooth(smooth); // apply gaussian to thresholded image ?
surfaceFilter->SetSmooth(smooth);
if (smooth)
{
surfaceFilter->InterpolationOn();
surfaceFilter->SetGaussianStandardDeviation(gaussianSD);
}
surfaceFilter->SetMedianFilter3D(applyMedian); // apply median to segmentation before marching cubes ?
if (applyMedian)
{
surfaceFilter->SetMedianKernelSize(
medianKernelSize, medianKernelSize, medianKernelSize); // apply median to segmentation before marching cubes
}
// fix to avoid vtk warnings see bug #5390
if (image->GetDimension() > 3)
decimateMesh = false;
if (decimateMesh)
{
surfaceFilter->SetDecimate(ImageToSurfaceFilter::QuadricDecimation);
surfaceFilter->SetTargetReduction(reductionRate);
}
else
{
surfaceFilter->SetDecimate(ImageToSurfaceFilter::NoDecimation);
}
surfaceFilter->UpdateLargestPossibleRegion();
// calculate normals for nicer display
m_Surface = surfaceFilter->GetOutput();
vtkPolyData *polyData = m_Surface->GetVtkPolyData();
if (!polyData)
throw std::logic_error("Could not create polygon model");
polyData->SetVerts(0);
polyData->SetLines(0);
if (smooth || applyMedian || decimateMesh)
{
vtkPolyDataNormals *normalsGen = vtkPolyDataNormals::New();
normalsGen->AutoOrientNormalsOn();
normalsGen->FlipNormalsOff();
normalsGen->SetInputData(polyData);
normalsGen->Update();
m_Surface->SetVtkPolyData(normalsGen->GetOutput());
normalsGen->Delete();
}
else
{
m_Surface->SetVtkPolyData(polyData);
}
return true;
}
示例10: ImageFileReaderException
void mitk::PicFileReader::GenerateData()
{
Image::Pointer output = this->GetOutput();
// Check to see if we can read the file given the name or prefix
//
if ( m_FileName == "" && m_FilePrefix == "" )
{
throw itk::ImageFileReaderException(__FILE__, __LINE__, "One of FileName or FilePrefix must be non-empty");
}
if( m_FileName != "")
{
mitkIpPicDescriptor* outputPic = mitkIpPicNew();
outputPic = CastToIpPicDescriptor(output, outputPic);
mitkIpPicDescriptor* pic=MITKipPicGet(const_cast<char *>(m_FileName.c_str()),
outputPic);
// comes upside-down (in MITK coordinates) from PIC file
ConvertHandedness(pic);
mitkIpPicTSV_t *tsv;
if ( (tsv = mitkIpPicQueryTag( pic, "SOURCE HEADER" )) != NULL)
{
if(tsv->n[0]>1e+06)
{
mitkIpPicTSV_t *tsvSH;
tsvSH = mitkIpPicDelTag( pic, "SOURCE HEADER" );
mitkIpPicFreeTag(tsvSH);
}
}
if ( (tsv = mitkIpPicQueryTag( pic, "ICON80x80" )) != NULL)
{
mitkIpPicTSV_t *tsvSH;
tsvSH = mitkIpPicDelTag( pic, "ICON80x80" );
mitkIpPicFreeTag(tsvSH);
}
if ( (tsv = mitkIpPicQueryTag( pic, "VELOCITY" )) != NULL)
{
mitkIpPicDescriptor* header = mitkIpPicCopyHeader(pic, NULL);
header->data = tsv->value;
ConvertHandedness(header);
output->SetChannel(header->data, 1);
header->data = NULL;
mitkIpPicFree(header);
mitkIpPicDelTag( pic, "VELOCITY" );
}
//slice-wise reading
//currently much too slow.
//else
//{
// int sstart, smax;
// int tstart, tmax;
// sstart=output->GetRequestedRegion().GetIndex(2);
// smax=sstart+output->GetRequestedRegion().GetSize(2);
// tstart=output->GetRequestedRegion().GetIndex(3);
// tmax=tstart+output->GetRequestedRegion().GetSize(3);
// int s,t;
// for(s=sstart; s<smax; ++s)
// {
// for(t=tstart; t<tmax; ++t)
// {
// mitkIpPicDescriptor* pic=mitkIpPicGetSlice(const_cast<char *>(m_FileName.c_str()), NULL, t*smax+s+1);
// output->SetPicSlice(pic,s,t);
// }
// }
//}
}
else
{
int position;
mitkIpPicDescriptor* pic=NULL;
int zDim=(output->GetDimension()>2?output->GetDimensions()[2]:1);
printf("\n zdim is %u \n",zDim);
for (position = 0; position < zDim; ++position)
{
char fullName[1024];
sprintf(fullName, m_FilePattern.c_str(), m_FilePrefix.c_str(), m_StartFileIndex+position);
pic=MITKipPicGet(fullName, pic);
if(pic==NULL)
{
itkDebugMacro("Pic file '" << fullName << "' does not exist.");
}
/* FIXME else
if(output->SetPicSlice(pic, position)==false)
{
itkDebugMacro("Image '" << fullName << "' could not be added to Image.");
}*/
}
if(pic!=NULL)
mitkIpPicFree(pic);
}
}
示例11: ioRegion
std::vector<BaseData::Pointer> LabelSetImageIO::Read()
{
const std::string& locale = "C";
const std::string& currLocale = setlocale( LC_ALL, NULL );
if ( locale.compare(currLocale)!=0 )
{
try
{
setlocale(LC_ALL, locale.c_str());
}
catch(...)
{
mitkThrow() << "Could not set locale.";
}
}
// begin regular image loading, adapted from mitkItkImageIO
itk::NrrdImageIO::Pointer nrrdImageIO = itk::NrrdImageIO::New();
Image::Pointer image = Image::New();
const unsigned int MINDIM = 2;
const unsigned int MAXDIM = 4;
const std::string path = this->GetLocalFileName();
MITK_INFO << "loading " << path << " via itk::ImageIOFactory... " << std::endl;
// Check to see if we can read the file given the name or prefix
if (path.empty())
{
mitkThrow() << "Empty filename in mitk::ItkImageIO ";
}
// Got to allocate space for the image. Determine the characteristics of
// the image.
nrrdImageIO->SetFileName(path);
nrrdImageIO->ReadImageInformation();
unsigned int ndim = nrrdImageIO->GetNumberOfDimensions();
if (ndim < MINDIM || ndim > MAXDIM)
{
MITK_WARN << "Sorry, only dimensions 2, 3 and 4 are supported. The given file has " << ndim << " dimensions! Reading as 4D.";
ndim = MAXDIM;
}
itk::ImageIORegion ioRegion(ndim);
itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();
itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
unsigned int dimensions[MAXDIM];
dimensions[0] = 0;
dimensions[1] = 0;
dimensions[2] = 0;
dimensions[3] = 0;
ScalarType spacing[MAXDIM];
spacing[0] = 1.0f;
spacing[1] = 1.0f;
spacing[2] = 1.0f;
spacing[3] = 1.0f;
Point3D origin;
origin.Fill(0);
unsigned int i;
for (i = 0; i < ndim; ++i)
{
ioStart[i] = 0;
ioSize[i] = nrrdImageIO->GetDimensions(i);
if (i<MAXDIM)
{
dimensions[i] = nrrdImageIO->GetDimensions(i);
spacing[i] = nrrdImageIO->GetSpacing(i);
if (spacing[i] <= 0)
spacing[i] = 1.0f;
}
if (i<3)
{
origin[i] = nrrdImageIO->GetOrigin(i);
}
}
ioRegion.SetSize(ioSize);
ioRegion.SetIndex(ioStart);
MITK_INFO << "ioRegion: " << ioRegion << std::endl;
nrrdImageIO->SetIORegion(ioRegion);
void* buffer = new unsigned char[nrrdImageIO->GetImageSizeInBytes()];
nrrdImageIO->Read(buffer);
image->Initialize(MakePixelType(nrrdImageIO), ndim, dimensions);
image->SetImportChannel(buffer, 0, Image::ManageMemory);
// access direction of itk::Image and include spacing
mitk::Matrix3D matrix;
matrix.SetIdentity();
unsigned int j, itkDimMax3 = (ndim >= 3 ? 3 : ndim);
for (i = 0; i < itkDimMax3; ++i)
for (j = 0; j < itkDimMax3; ++j)
//.........这里部分代码省略.........
示例12: itkExceptionMacro
void mitk::CorrectorAlgorithm::GenerateData()
{
Image::Pointer inputImage = const_cast<Image*>(ImageToImageFilter::GetInput(0));
if (inputImage.IsNull() || inputImage->GetDimension() != 2)
{
itkExceptionMacro("CorrectorAlgorithm needs a 2D image as input.");
}
if (m_Contour.IsNull())
{
itkExceptionMacro("CorrectorAlgorithm needs a Contour object as input.");
}
// copy the input (since m_WorkingImage will be changed later)
m_WorkingImage = Image::New();
m_WorkingImage->Initialize( inputImage );
m_WorkingImage->SetVolume( inputImage.GetPointer()->GetData() );
if (inputImage->GetTimeSlicedGeometry() )
{
AffineGeometryFrame3D::Pointer originalGeometryAGF = inputImage->GetTimeSlicedGeometry()->Clone();
TimeSlicedGeometry::Pointer originalGeometry = dynamic_cast<TimeSlicedGeometry*>( originalGeometryAGF.GetPointer() );
m_WorkingImage->SetGeometry( originalGeometry );
}
else
{
itkExceptionMacro("Original image does not have a 'Time sliced geometry'! Cannot copy.");
}
// Convert to ipMITKSegmentationTYPE (because TobiasHeimannCorrectionAlgorithm relys on that data type)
itk::Image< ipMITKSegmentationTYPE, 2 >::Pointer correctPixelTypeImage;
CastToItkImage( m_WorkingImage, correctPixelTypeImage );
assert (correctPixelTypeImage.IsNotNull() );
// possible bug in CastToItkImage ?
// direction maxtrix is wrong/broken/not working after CastToItkImage, leading to a failed assertion in
// mitk/Core/DataStructures/mitkSlicedGeometry3D.cpp, 479:
// virtual void mitk::SlicedGeometry3D::SetSpacing(const mitk::Vector3D&): Assertion `aSpacing[0]>0 && aSpacing[1]>0 && aSpacing[2]>0' failed
// solution here: we overwrite it with an unity matrix
itk::Image< ipMITKSegmentationTYPE, 2 >::DirectionType imageDirection;
imageDirection.SetIdentity();
correctPixelTypeImage->SetDirection(imageDirection);
Image::Pointer temporarySlice = this->GetOutput();
// temporarySlice = ImportItkImage( correctPixelTypeImage );
CastToMitkImage( correctPixelTypeImage, temporarySlice );
TobiasHeimannCorrectionAlgorithm( temporarySlice->GetSliceData()->GetPicDescriptor() );
// temporarySlice is our return value (user can get it by calling GetOutput() )
CalculateDifferenceImage( temporarySlice, inputImage );
if ( m_DifferenceImage.IsNotNull() && inputImage->GetTimeSlicedGeometry() )
{
AffineGeometryFrame3D::Pointer originalGeometryAGF = inputImage->GetTimeSlicedGeometry()->Clone();
TimeSlicedGeometry::Pointer originalGeometry = dynamic_cast<TimeSlicedGeometry*>( originalGeometryAGF.GetPointer() );
m_DifferenceImage->SetGeometry( originalGeometry );
}
else
{
itkExceptionMacro("Original image does not have a 'Time sliced geometry'! Cannot copy.");
}
}
示例13: FeatureDescriptionPrefix
mitk::GIFVolumetricStatistics::FeatureListType mitk::GIFVolumetricStatistics::CalculateFeatures(const Image::Pointer & image, const Image::Pointer &mask)
{
FeatureListType featureList;
if (image->GetDimension() < 3)
{
return featureList;
}
AccessByItk_3(image, CalculateVolumeStatistic, mask, featureList, FeatureDescriptionPrefix());
AccessByItk_3(mask, CalculateLargestDiameter, image, featureList, FeatureDescriptionPrefix());
vtkSmartPointer<vtkImageMarchingCubes> mesher = vtkSmartPointer<vtkImageMarchingCubes>::New();
vtkSmartPointer<vtkMassProperties> stats = vtkSmartPointer<vtkMassProperties>::New();
mesher->SetInputData(mask->GetVtkImageData());
mesher->SetValue(0, 0.5);
stats->SetInputConnection(mesher->GetOutputPort());
stats->Update();
double pi = vnl_math::pi;
double meshVolume = stats->GetVolume();
double meshSurf = stats->GetSurfaceArea();
double pixelVolume = featureList[1].second;
double pixelSurface = featureList[3].second;
MITK_INFO << "Surface: " << pixelSurface << " Volume: " << pixelVolume;
double compactness1 = pixelVolume / (std::sqrt(pi) * std::pow(meshSurf, 2.0 / 3.0));
double compactness1Pixel = pixelVolume / (std::sqrt(pi) * std::pow(pixelSurface, 2.0 / 3.0));
//This is the definition used by Aertz. However, due to 2/3 this feature is not demensionless. Use compactness3 instead.
double compactness2 = 36 * pi*pixelVolume*pixelVolume / meshSurf / meshSurf / meshSurf;
double compactness2MeshMesh = 36 * pi*meshVolume*meshVolume / meshSurf / meshSurf / meshSurf;
double compactness2Pixel = 36 * pi*pixelVolume*pixelVolume / pixelSurface / pixelSurface / pixelSurface;
double compactness3 = pixelVolume / (std::sqrt(pi) * std::pow(meshSurf, 3.0 / 2.0));
double compactness3MeshMesh = meshVolume / (std::sqrt(pi) * std::pow(meshSurf, 3.0 / 2.0));
double compactness3Pixel = pixelVolume / (std::sqrt(pi) * std::pow(pixelSurface, 3.0 / 2.0));
double sphericity = std::pow(pi, 1 / 3.0) *std::pow(6 * pixelVolume, 2.0 / 3.0) / meshSurf;
double sphericityMesh = std::pow(pi, 1 / 3.0) *std::pow(6 * meshVolume, 2.0 / 3.0) / meshSurf;
double sphericityPixel = std::pow(pi, 1 / 3.0) *std::pow(6 * pixelVolume, 2.0 / 3.0) / pixelSurface;
double surfaceToVolume = meshSurf / meshVolume;
double surfaceToVolumePixel = pixelSurface / pixelVolume;
double sphericalDisproportion = meshSurf / 4 / pi / std::pow(3.0 / 4.0 / pi * pixelVolume, 2.0 / 3.0);
double sphericalDisproportionMesh = meshSurf / 4 / pi / std::pow(3.0 / 4.0 / pi * meshVolume, 2.0 / 3.0);
double sphericalDisproportionPixel = pixelSurface / 4 / pi / std::pow(3.0 / 4.0 / pi * pixelVolume, 2.0 / 3.0);
double asphericity = std::pow(1.0/compactness2, (1.0 / 3.0)) - 1;
double asphericityMesh = std::pow(1.0 / compactness2MeshMesh, (1.0 / 3.0)) - 1;
double asphericityPixel = std::pow(1.0/compactness2Pixel, (1.0 / 3.0)) - 1;
//Calculate center of mass shift
int xx = mask->GetDimensions()[0];
int yy = mask->GetDimensions()[1];
int zz = mask->GetDimensions()[2];
double xd = mask->GetGeometry()->GetSpacing()[0];
double yd = mask->GetGeometry()->GetSpacing()[1];
double zd = mask->GetGeometry()->GetSpacing()[2];
vtkSmartPointer<vtkDoubleArray> dataset1Arr = vtkSmartPointer<vtkDoubleArray>::New();
vtkSmartPointer<vtkDoubleArray> dataset2Arr = vtkSmartPointer<vtkDoubleArray>::New();
vtkSmartPointer<vtkDoubleArray> dataset3Arr = vtkSmartPointer<vtkDoubleArray>::New();
dataset1Arr->SetNumberOfComponents(1);
dataset2Arr->SetNumberOfComponents(1);
dataset3Arr->SetNumberOfComponents(1);
dataset1Arr->SetName("M1");
dataset2Arr->SetName("M2");
dataset3Arr->SetName("M3");
vtkSmartPointer<vtkDoubleArray> dataset1ArrU = vtkSmartPointer<vtkDoubleArray>::New();
vtkSmartPointer<vtkDoubleArray> dataset2ArrU = vtkSmartPointer<vtkDoubleArray>::New();
vtkSmartPointer<vtkDoubleArray> dataset3ArrU = vtkSmartPointer<vtkDoubleArray>::New();
dataset1ArrU->SetNumberOfComponents(1);
dataset2ArrU->SetNumberOfComponents(1);
dataset3ArrU->SetNumberOfComponents(1);
dataset1ArrU->SetName("M1");
dataset2ArrU->SetName("M2");
dataset3ArrU->SetName("M3");
for (int x = 0; x < xx; x++)
{
for (int y = 0; y < yy; y++)
{
for (int z = 0; z < zz; z++)
{
itk::Image<int,3>::IndexType index;
index[0] = x;
index[1] = y;
index[2] = z;
mitk::ScalarType pxImage;
mitk::ScalarType pxMask;
mitkPixelTypeMultiplex5(
mitk::FastSinglePixelAccess,
image->GetChannelDescriptor().GetPixelType(),
image,
image->GetVolumeData(),
//.........这里部分代码省略.........
示例14: ioRegion
std::vector<BaseData::Pointer> ItkImageIO::Read()
{
std::vector<BaseData::Pointer> result;
const std::string& locale = "C";
const std::string& currLocale = setlocale( LC_ALL, NULL );
if ( locale.compare(currLocale)!=0 )
{
try
{
setlocale(LC_ALL, locale.c_str());
}
catch(...)
{
MITK_INFO << "Could not set locale " << locale;
}
}
Image::Pointer image = Image::New();
const unsigned int MINDIM = 2;
const unsigned int MAXDIM = 4;
const std::string path = this->GetLocalFileName();
MITK_INFO << "loading " << path << " via itk::ImageIOFactory... " << std::endl;
// Check to see if we can read the file given the name or prefix
if (path.empty())
{
mitkThrow() << "Empty filename in mitk::ItkImageIO ";
}
// Got to allocate space for the image. Determine the characteristics of
// the image.
m_ImageIO->SetFileName( path );
m_ImageIO->ReadImageInformation();
unsigned int ndim = m_ImageIO->GetNumberOfDimensions();
if ( ndim < MINDIM || ndim > MAXDIM )
{
MITK_WARN << "Sorry, only dimensions 2, 3 and 4 are supported. The given file has " << ndim << " dimensions! Reading as 4D.";
ndim = MAXDIM;
}
itk::ImageIORegion ioRegion( ndim );
itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();
itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
unsigned int dimensions[ MAXDIM ];
dimensions[ 0 ] = 0;
dimensions[ 1 ] = 0;
dimensions[ 2 ] = 0;
dimensions[ 3 ] = 0;
ScalarType spacing[ MAXDIM ];
spacing[ 0 ] = 1.0f;
spacing[ 1 ] = 1.0f;
spacing[ 2 ] = 1.0f;
spacing[ 3 ] = 1.0f;
Point3D origin;
origin.Fill(0);
unsigned int i;
for ( i = 0; i < ndim ; ++i )
{
ioStart[ i ] = 0;
ioSize[ i ] = m_ImageIO->GetDimensions( i );
if(i<MAXDIM)
{
dimensions[ i ] = m_ImageIO->GetDimensions( i );
spacing[ i ] = m_ImageIO->GetSpacing( i );
if(spacing[ i ] <= 0)
spacing[ i ] = 1.0f;
}
if(i<3)
{
origin[ i ] = m_ImageIO->GetOrigin( i );
}
}
ioRegion.SetSize( ioSize );
ioRegion.SetIndex( ioStart );
MITK_INFO << "ioRegion: " << ioRegion << std::endl;
m_ImageIO->SetIORegion( ioRegion );
void* buffer = new unsigned char[m_ImageIO->GetImageSizeInBytes()];
m_ImageIO->Read( buffer );
image->Initialize( MakePixelType(m_ImageIO), ndim, dimensions );
image->SetImportChannel( buffer, 0, Image::ManageMemory );
// access direction of itk::Image and include spacing
mitk::Matrix3D matrix;
matrix.SetIdentity();
unsigned int j, itkDimMax3 = (ndim >= 3? 3 : ndim);
for ( i=0; i < itkDimMax3; ++i)
for( j=0; j < itkDimMax3; ++j )
//.........这里部分代码省略.........