[Insight-users] Problems using ITK under linux

Maximilien Renard iixamaxii at gmail.com
Tue Jan 19 03:56:50 EST 2010


Dear ITK users,

I've been using ITK in one of my project for a while. As long as I
remember, I've been stuck with a problem while trying to open DICOM
images generated by a CT-Scan.

I've always used ITK-3.8 both under linux ubuntu and windows. While
everything would work fine under Windows, something would always go
wrong under linux. I could not get the spacings of my images (in none
of the directions). It was bothering but for developpment purpose, I
could cope with it.

I've tried to update to ITK-3.16 today. The result is even worse.
While it still works under Windows, I cannot even open the images
anymore under linux. Instead I have these error messages popping up in
the konsole.

Starting /home/ixm/Documents/Code/C++/LightCTScannerAnalysis/LightCTScannerAnalysis...

itk::ExceptionObject (0x89fd728)

Location: "void
itk::ImageBase<VImageDimension>::ComputeIndexToPhysicalPointMatrices()
[with unsigned int VImageDimension = 3u]"

File: /usr/local/include/InsightToolkit/Common/itkImageBase.txx

Line: 191

Description: itk::ERROR: Image(0x89fd360): Bad direction, determinant
is 0. Direction is 0 0 0

0 1 0

0 0 0

QPainter::begin: Cannot paint on a null pixmap

QPainter::end: Painter not active, aborted

itk::ExceptionObject (0x88849a8)

Location: "void
itk::ImageBase<VImageDimension>::ComputeIndexToPhysicalPointMatrices()
[with unsigned int VImageDimension = 3u]"

File: /usr/local/include/InsightToolkit/Common/itkImageBase.txx

Line: 191

Description: itk::ERROR: Image(0x87c7878): Bad direction, determinant
is 0. Direction is -0 0 0

0 1 0

0 0 -0

QPainter::begin: Cannot paint on a null pixmap

QPainter::end: Painter not active, aborted

The program has unexpectedly finished.

/home/ixm/Documents/Code/C++/LightCTScannerAnalysis/LightCTScannerAnalysis
exited with code 0

Some time ago, I've had a little chat with Bill Lorensen who told me
my images weren't series or so. Well, these images have been given to
me by a belgian orthopaedics clinic and they were able to use them
(like me under windows) so I guess, it's rather a platform dependend
issue (maybe the problem is that it should not even work on Windows
:P).

So my question is, what could cause that ? What would need to be able
to help me (even just a little ?). Anyway, I'll paste my opening code
below.

Thank you very much for your help.

Best regards,

Maximilien Renard

ULB - MA1 Ingénieur Civil Biomédical
maxrenard at ulb.ac.be
+32 476 63 68 92

P.S. Here it is :

CMainView * CVolumeDataReadWrite::OpenFiles(QString FilePath) {
	QString Dir;
	QFileInfo FileInfo(FilePath);
	Dir = FileInfo.absolutePath();

	typedef itk::ImageSeriesReader<ITK3DImageType> ReaderType;
	ReaderType::Pointer reader = ReaderType::New();

	typedef itk::GDCMImageIO ImageIOType;
	ImageIOType::Pointer dicomIO = ImageIOType::New();

	reader->SetImageIO(dicomIO);

	typedef itk::GDCMSeriesFileNames NamesGeneratorType;
	NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();

	nameGenerator->SetUseSeriesDetails(true);

	nameGenerator->SetDirectory(Dir.toUtf8().constData());

	typedef std::vector<std::string> SeriesIdContainer;

	const SeriesIdContainer & seriesUID = nameGenerator->GetSeriesUIDs();

	QStringList FileList;

	SeriesIdContainer::const_iterator seriesItr = seriesUID.begin();
	SeriesIdContainer::const_iterator seriesEnd = seriesUID.end();
	while(seriesItr != seriesEnd) {
		QString TempName = seriesItr->c_str();
		TempName += " ("+
QString::number(nameGenerator->GetFileNames(seriesItr->c_str()).size())
+")";

		FileList << TempName;
		seriesItr++;
	}

	CDialogSeries * dlg = new CDialogSeries(FileList);

	int SelectedSeries = dlg->exec();

	//qDebug() << SelectedSeries;

	if(SelectedSeries < 0)
		return NULL;

	unsigned int MainViewID;
	CMainView * CurMainView = NULL;

	if(GetWindow()->GetNbMainViews() > 0) {
		CDialogMainViewAsParent * DialogMainViewAsParent = new
CDialogMainViewAsParent(GetWindow()->GetMainViewsNames(), "DICOM");

		MainViewID = DialogMainViewAsParent->exec();

		if(MainViewID < GetWindow()->GetNbMainViews()) {
			CurMainView = GetWindow()->GetMainView(MainViewID);
		} else {
			CurMainView = NULL;
		}
	}

	if(CurMainView == NULL) {
		MainViewID = GetWindow()->AddNewMainView();
		CurMainView = GetWindow()->GetMainView(MainViewID);
	}

	typedef std::vector<std::string> FileNamesContainer;
	FileNamesContainer fileNames;

	QString Ser = FileList.at(SelectedSeries);
	int Index = Ser.indexOf(' ');
	Ser = Ser.left(Index);

	fileNames = nameGenerator->GetFileNames(Ser.toUtf8().constData());

	reader->SetFileNames(fileNames);

	try {
		reader->Update();
	}
	catch(itk::ExceptionObject &ex) {
		std::cout << ex << std::endl;
	}

	CVolumeData * pVD = new CVolumeData(CurMainView);

	ITK3DImageType::SpacingType spacings = reader->GetOutput()->GetSpacing();

	//qDebug() << spacings[0] << spacings[1] << spacings[2];

	pVD->SetITK3DImage(reader->GetOutput());

	unsigned int DimX, DimY, DimZ;
	pVD->GetDimensions(DimX, DimY, DimZ);

	//qDebug() << DimX << DimY << DimZ;

	float SpacingX, SpacingY, SpacingZ;
	pVD->GetSpacings(SpacingX, SpacingY, SpacingZ);

	/*if(Dir.contains(QString("DICOM-PATIENT-1"), Qt::CaseInsensitive))
		pVD->SetSpacings(0.15, 0.15, 0.60);
	else if(Dir.contains(QString("DICOM-PATIENT-2"), Qt::CaseInsensitive))
		pVD->SetSpacings(0.15, 0.15, 0.33);*/

	//qDebug() << SpacingX << SpacingY << SpacingZ;

	//qDebug() << dicomIO->GetSpacing(0) << dicomIO->GetSpacing(1) <<
dicomIO->GetSpacing(2);

	double RescaleIntercept, RescaleSlope;
	RescaleIntercept = dicomIO->GetRescaleIntercept();
	RescaleSlope = dicomIO->GetRescaleSlope();
	pVD->SetRescaleInformation(RescaleSlope, RescaleIntercept);

	unsigned short *ptr;
	float Value;
	ptr = pVD->GetITK3DImage()->GetBufferPointer();


	for (unsigned int i = 0; i < DimX * DimY * DimZ; i++) {
		Value = (signed short)(ptr[i]);
		Value = (Value - RescaleIntercept) / RescaleSlope;
			ptr[i] = (unsigned short)Value;
	}

	CurMainView->SetVolumeData(pVD);

	return CurMainView;
}


More information about the Insight-users mailing list