[Insight-users] Using ImportFilter and PasteImageFilter
Quent
quentin.bezsilko at gmail.com
Thu May 6 03:30:13 EDT 2010
Hi all,
I'm trying to write a plugin for Osirix using ITK as well. I would like to
create a filter on an importFilter. The problem is I can't use the Update()
function for my filter without making the Osirix software crash. I already
tried to create an importFilter with the date taken from Osirix but while
writing it, I get an exception. It seems that the importFilter is not
correct. Is it possible that the number of slices used is too big (over
200)? Here is my source code and the exception message :
ViewerController * new2DViewer = [self duplicateCurrent2DViewerWindow];
id waitWindow = [viewerController startWaitWindow:@"Essai modification de
l'image"];
typedef itk::Image <float, 3> ImageType;
ImageType::Pointer image = ImageType::New();
ImageType::RegionType region;
ImageType::SizeType size;
double spacing[3];
typedef itk::Image <float, 3> InputImageType;
typedef itk::Image <float, 3> OutputImageType;
typedef itk::ImageFileReader <InputImageType> ReaderType;
typedef itk::ImageFileWriter <OutputImageType> WriterType;
WriterType::Pointer writer = WriterType::New();
ReaderType::Pointer reader = ReaderType::New();
typedef itk::ImportImageFilter <float, 3> ImportFilterType;
ImportFilterType::Pointer importFilter = ImportFilterType::New();
NSArray * pixList = [new2DViewer pixList];
DCMPix * curPix = [pixList objectAtIndex:0];
int height = [curPix pheight];
int width = [curPix pwidth];
int depth = [pixList count];
size[0] = height; size[1] = width; size[2] = depth;
region.SetSize(size);
ImageType::IndexType start;
start.Fill(0);
region.SetIndex(start);
const unsigned int numberOfPixels = height * width * depth;
double spaceX = [curPix pixelSpacingX];
double spaceY = [curPix pixelSpacingY];
double spaceZ = [curPix sliceInterval];
if(spaceZ == 0){
spaceZ = [curPix sliceThickness];
}
spacing[0] = (double)spaceX; spacing[1] = (double)spaceY; spacing[2] =
(double)spaceZ;
double ox = [curPix originX];
double oy = [curPix originY];
double oz = [curPix originZ];
double origin[3];
origin[0] = ox; origin[1] = oy; origin[2] = oz;
float * localBuffer = (float*)malloc(numberOfPixels*sizeof(float));
unsigned int cptLocalBuffer = 0;
unsigned long i, x;
float * fImage;
pixList = [new2DViewer pixList];
for(i=0;i<[pixList count]; i++){
curPix = [pixList objectAtIndex:i];
x = height * width;
fImage = [curPix fImage];
while(x>0){
*localBuffer = *fImage;
localBuffer++;
cptLocalBuffer++;
fImage++;
x--;
}
}
/*unsigned long i, x;
float * fImage;
pixList = [new2DViewer pixList];
for(i=0;i<[pixList count]; i++){
curPix = [pixList objectAtIndex:i];
x = height * width;
fImage = [curPix fImage];
for(int j = 0;j<height; j++) {
for(int k=0;k<width; k++){
localBuffer[i+j*i+i*j*k] = fImage[j+j*k];
}
}
}
NSRunCriticalAlertPanel(@"CptLocalBuffer", [NSString
stringWithFormat:@"Valeur de cptLocalBuffer : %d ", cptLocalBuffer], nil,
nil, nil);
NSRunCriticalAlertPanel(@"Nombre de pixels", [NSString
stringWithFormat:@"Valeur de numberOfPixels : %d ", numberOfPixels], nil,
nil, nil);
localBuffer -= cptLocalBuffer;
importFilter->SetRegion(region);
importFilter->SetSpacing(spacing);
importFilter->SetOrigin(origin);
importFilter->SetImportPointer(localBuffer, numberOfPixels, true);
// Affichage des caractéristiques de l'importFilter
std::ofstream out("/Users/u703inserm/Desktop/fichier2.txt");
image = importFilter->GetOutput();
importFilter->Print(out);
writer->SetFileName("image.dcm");
writer->SetInput(image);
try{
writer->Update();
NSRunCriticalAlertPanel(@"writer->Update()", @"OK", nil, nil, nil);
}
catch(itk::ExceptionObject & err){
FILE * fichier = fopen("/Users/u703inserm/Desktop/fichier.txt", "w");
if(fichier != NULL){
fputs(err.GetDescription(), fichier);
}
}
const double * tableau = importFilter->GetSpacing();
NSRunCriticalAlertPanel(@"Espacement de l'importFilter", [NSString
stringWithFormat:@"Valeur de l'espacement : %lf %lf %lf",
tableau[0],tableau[1],tableau[2]], nil, nil, nil);
const double * tableau2 = importFilter->GetOrigin();
NSRunCriticalAlertPanel(@"Origine de l'importFilter", [NSString
stringWithFormat:@"Valeur de l'origine : %lf %lf %lf",
tableau2[0],tableau2[1],tableau2[2]], nil, nil, nil);
const ImageType::RegionType reg = importFilter->GetRegion();
NSRunCriticalAlertPanel(@"Index de l'importFilter", [NSString
stringWithFormat:@"Valeur de l'index : %d %d %d",
reg.GetIndex(0),reg.GetIndex(1),reg.GetIndex(2)], nil, nil, nil);
ImageType::SizeType s = reg.GetSize();
NSRunCriticalAlertPanel(@"Taille de l'importFilter", [NSString
stringWithFormat:@"Valeur de la taille : %d %d %d", s[0],s[1],s[2]], nil,
nil, nil);
typedef itk::MeanImageFilter<ImageType, ImageType> FilterType;
FilterType::Pointer filter = FilterType::New();
filter->GetOutput()->SetRegions(region);
filter->GetOutput()->SetOrigin(origin);
filter->GetOutput()->SetSpacing(spacing);
filter->GetOutput()->Allocate();
try{
filter->Update();
//NSRunCriticalAlertPanel(@"image->Update()", @"OK", nil, nil, nil);
}
catch(itk::ExceptionObject & err){
FILE * fichier = fopen("/Users/u703inserm/Desktop/fichier.txt", "w");
if(fichier != NULL){
fputs(err.GetDescription(), fichier);
}
}
[new2DViewer endWaitWindow:waitWindow];
[new2DViewer needsDisplayUpdate];
Maybe you could have a look at it bios5 since you were able to do it.
Thanks for your help in advance.
Quentin
--
View this message in context: http://old.nabble.com/Using-ITK-with-XCode-tp6529684p28470202.html
Sent from the ITK - Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list