Beispiel #1
0
int main(int argc, char ** argv)
{
	// Load up the image
	//
	//
	//
	ImageFileReader::Pointer reader = ImageFileReader::New();
	ImageIOType::Pointer imageIO = ImageIOType::New();
	reader->SetImageIO(imageIO);
	reader->SetFileName(argv[1]);
	reader->Update();



	typedef itk::BinaryNeighbourhoodImageFilter<ImageType, ImageType> BNFilter;
	BNFilter::Pointer bnFilter = BNFilter::New();



	QuickView viewer;
	//viewer.AddImage(reader->GetOutput());



	return 0;
}
void FindImageRunnable::GDCImageIORead(const std::vector<std::string>& files)
{
	using std::string;
	using std::vector;
	using itk::GDCMImageIO;
	typedef itk::ImageFileReader<itk::Image<unsigned short, 2>> ImageFileReader;

	string _file = files[0];
	string patientName = "/";
	string modality = "/";
	string seriesDescription = "/";
	string slice = "/";
	string date = "/";
	string seriesUID = "/";
	string format = "/";

	try {
		GDCMImageIO::Pointer dicomIO = GDCMImageIO::New();

		ImageFileReader::Pointer imageFilerReader = ImageFileReader::New();
		imageFilerReader->SetNumberOfThreads(4);
		imageFilerReader->SetImageIO(dicomIO);
		imageFilerReader->SetFileName(_file);
		imageFilerReader->Update();

		if (!dicomIO->GetValueFromTag(("0010|0010"), patientName)) {
			//patientName = "/";
		}
		if (!dicomIO->GetValueFromTag("0008|0060", modality)) {
			//modality = "/";
		}
		if (!dicomIO->GetValueFromTag("0008|103e", seriesDescription)) {
			//seriesDescription = "/";
		}

		if (!dicomIO->GetValueFromTag("0020|1002", slice)) {
			//slice = "/";
			slice = std::to_string(files.size());
		}
		if (!dicomIO->GetValueFromTag("0008|0020", date)) {
			//date = "/";
		}
		if (!dicomIO->GetValueFromTag("0020|0052", seriesUID)) {
			//seriesUID = "/";
		}
	}
	catch (itk::ExceptionObject& e) {
		patientName = QFileInfo(QString::fromStdString(_file)).baseName().toStdString();
		qDebug() << "Input are not DICOM images.";
		qDebug() << "Input are assumed to be NIFTI.";
		qDebug() << e.what();

	}
	
	QString _emitString;
	_emitString += QString::fromStdString(patientName) + '\t';
	_emitString += QString::fromStdString(modality) + '\t';
	_emitString += QString::fromStdString(seriesDescription) + '\t';
	_emitString += QString::fromStdString(slice) + '\t';
	_emitString += QString::fromStdString(date) + '\t';
	_emitString += QString::fromStdString(seriesUID) + '\t';
	_emitString += QString::fromStdString(format) + '\t';
	for (vector<string>::const_iterator cit = files.cbegin();
		cit != files.cend(); ++cit) {
		_emitString += QString::fromStdString(*cit);
		_emitString += ';';
	}
	_emitString += QString::fromStdString(_file);

	emit addTreeWidgetItem(_emitString);
}
void ConclusionPage::initializePage()
{
	using itk::GDCMImageIO;
	using itk::MetaDataDictionary;
	using std::string;
	typedef itk::ImageFileReader<itk::Image<unsigned short, 2>> ImageFileReader;
	using itk::MetaDataObjectBase;
	typedef itk::MetaDataObject<string> MetaDataString;


	tabWidget->clear();
	

	for (int i = 0; i < m_tableWidgets.size(); ++i) {

		QString fieldStringImageSet;
		fieldStringImageSet += "image.set";
		fieldStringImageSet += QString::number(i);

		QString imageSet = field(fieldStringImageSet).toString();

		if (imageSet.isEmpty()) {
			continue;
		}

		if (m_tableWidgets[i] == nullptr) {
			m_tableWidgets[i] = new QTableWidget(this);
		}
		tabWidget->addTab(m_tableWidgets[i], imageSet);
		//m_tableWidgets[i]->clear();
		m_tableWidgets[i]->setEditTriggers(QTableWidget::NoEditTriggers);
		m_tableWidgets[i]->setColumnCount(3);
		m_tableWidgets[i]->setRowCount(0);
		m_tableWidgets[i]->setHorizontalHeaderLabels(QStringList()
			<< "Tag" << "Label" << "Description");
		m_tableWidgets[i]->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
		m_tableWidgets[i]->verticalHeader()->setVisible(false);

		try {
			GDCMImageIO::Pointer dicomIO = GDCMImageIO::New();
			ImageFileReader::Pointer reader = ImageFileReader::New();

			QString fieldStringImagePath;
			fieldStringImagePath += "image.path";
			fieldStringImagePath += QString::number(i);

			QStringList imagePaths = field(fieldStringImagePath).toString().split(';');
			if (imagePaths[0].isEmpty()) {
				continue;
			}

			reader->SetFileName(imagePaths[0].toStdString());
			qDebug() << imagePaths;
			reader->SetImageIO(dicomIO);
			reader->Update();

			const MetaDataDictionary& dictionary = dicomIO->GetMetaDataDictionary();
			for (MetaDataDictionary::ConstIterator cit = dictionary.Begin();
				cit != dictionary.End(); ++cit) {

				MetaDataObjectBase::Pointer entry = cit->second;
				MetaDataString::Pointer entryValue = static_cast<MetaDataString*>(
					entry.GetPointer());

				if (entryValue) {
					m_tableWidgets[i]->insertRow(m_tableWidgets[i]->rowCount());
					string tag = cit->first;
					string label;
					string value = entryValue->GetMetaDataObjectValue();
					m_tableWidgets[i]->setItem(m_tableWidgets[i]->rowCount() - 1, 2,
						new QTableWidgetItem(QString::fromStdString(value)));
					m_tableWidgets[i]->setItem(m_tableWidgets[i]->rowCount() - 1, 0,
						new QTableWidgetItem(QString::fromStdString(tag)));
					if (GDCMImageIO::GetLabelFromTag(tag, label)) {
						m_tableWidgets[i]->setItem(m_tableWidgets[i]->rowCount() - 1, 1,
							new QTableWidgetItem(QString::fromStdString(label)));
					}
					else {
						m_tableWidgets[i]->setItem(m_tableWidgets[i]->rowCount() - 1, 1,
							new QTableWidgetItem(tr("Unknown")));
					}

				}
			}
		}
		catch (itk::ExceptionObject& e) {
			qDebug() << "Inputs are not DICOM images.";
			qDebug() << e.what();
		}

		//if (!(*m_DICOMHeaders)[i].isNull()) {
		//	int tableRow = 0;
		//	m_tableWidgets[i]->setRowCount((*m_DICOMHeaders).size());
		//	m_tableWidgets[i]->setColumnCount(2);
		//	for (QMap<QString, QString>::const_iterator cit = (*m_DICOMHeaders)[i]->constBegin();
		//		cit != (*m_DICOMHeaders)[i]->constEnd(); ++cit) {

		//		qDebug() << cit.key();
		//		qDebug() << cit.value();
		//		m_tableWidgets[i]->setItem(tableRow, 0, new QTableWidgetItem(cit.key()));
		//		m_tableWidgets[i]->setItem(tableRow, 1, new QTableWidgetItem(cit.value()));
		//		++tableRow;
		//	}
		//}

	}

}