[Insight-users] Simple Problem
Julien Jomier
jjomier at cs.unc.edu
Mon Feb 7 22:15:29 EST 2005
Hi Vishal,
If you want a binary image representing the edges of a cube you can use
the itkAddImageFilter and add two binary cubes with opposite intentity
values.
Something like:
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkImageRegionIterator.h"
#include "itkAddImageFilter.h"
int main()
{
typedef char PixelType;
typedef itk::Image<PixelType,3> ImageType;
unsigned int sizeCube = 30;
ImageType::Pointer cube1 = ImageType::New();
ImageType::RegionType bufferedRegion;
ImageType::RegionType largestRegion;
ImageType::SizeType sizeBuffered;
sizeBuffered.Fill(sizeCube);
ImageType::IndexType index = {sizeCube/2,sizeCube/2,sizeCube/2};
bufferedRegion.SetIndex(index);
bufferedRegion.SetSize(sizeBuffered);
ImageType::SizeType sizeLargest;
sizeLargest.Fill(sizeCube*2);
largestRegion.SetSize(sizeLargest);
cube1->SetRegions(largestRegion);
cube1->Allocate();
cube1->FillBuffer(0);
typedef itk::ImageRegionIterator<ImageType> IteratorType;
IteratorType it(cube1,bufferedRegion);
it.GoToBegin();
while(!it.IsAtEnd())
{
it.Set(120);
++it;
}
ImageType::Pointer cube2 = ImageType::New();
sizeBuffered.Fill(sizeCube-2);
index[0] = sizeCube/2+1;
index[1] = sizeCube/2+1;
index[2] = sizeCube/2+1;
bufferedRegion.SetIndex(index);
bufferedRegion.SetSize(sizeBuffered);
cube2->SetRegions(largestRegion);
cube2->Allocate();
cube2->FillBuffer(0);
IteratorType it2(cube2,bufferedRegion);
it2.GoToBegin();
while(!it2.IsAtEnd())
{
it2.Set(-120);
++it2;
}
typedef itk::AddImageFilter<ImageType,ImageType,ImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
filter->SetInput1(cube1);
filter->SetInput2(cube2);
filter->Update();
itk::ImageFileWriter<ImageType>::Pointer writer;
writer = itk::ImageFileWriter<ImageType>::New();
writer->SetInput( filter->GetOutput() );
writer->SetFileName("cube.mha");
writer->Update();
return 0;
}
Hope that helps,
Julien
Vishal Majithia wrote:
> I need to generate a 3d cube, preferably of only
> surfaces. I've been trying for 2 weeks with no
> success. Does anyone know how to do this? They need to
> be stored as binaries, so that I can then register
> them later.
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list