コード例 #1
0
// ------------------------------------------------------------------------
std::string InitialTransformExtractor::GetReferenceImageFilename()
{
    FilenamesType targetFilenames;
    for(unsigned int i = 0; i < m_Filenames.size(); i++)
    {
        const char * fname = m_Filenames[i].c_str();
        if(m_Mapping.count(fname) == 0) continue;

        // extract the image information
        std::string descriptionStr = m_Mapping[fname][seriesDescription];
        std::string instanceNumberStr = m_Mapping[fname][instanceNumber];
        QString description = QString::fromStdString(descriptionStr);
        unsigned int instanceNumber = QString::fromStdString(instanceNumberStr).toInt();

        // check that the description is a short axis one and is instance 1
        if(instanceNumber == 1 && description.contains("sa", Qt::CaseInsensitive))
        {
            targetFilenames.push_back(m_Filenames[i]);
        }
    }

    // find the slice with the smallest slice position
    double smallest = 1000000.0;
    int smallestIndex;
    for(unsigned int i = 0; i < targetFilenames.size(); i++)
    {
        const char * fname = targetFilenames[i].c_str();
        std::string slicePosition = m_Mapping[fname][sliceLocation];
        double pos = QString::fromStdString(slicePosition).toDouble();

        if(pos < smallest)
        {
            smallest = pos;
            smallestIndex = i;
        }
    }

    return targetFilenames[smallestIndex];
}
コード例 #2
0
// ------------------------------------------------------------------------
void readFilenames(const std::string &inputDirectory, FilenamesType &imageFilenames)
{
	QDir dir(QString::fromStdString(inputDirectory));
	QStringList filters;
	filters << "label*";
	QStringList filenames = dir.entryList(filters);

	for(int i = 0; i < filenames.size(); i++)
	{
		QString fname = dir.absoluteFilePath(filenames[i]);
		imageFilenames.push_back(fname.toStdString());
	}
}
コード例 #3
0
int main(int argc, char ** argv)
{
	// load the line data
	typedef utils::Directory::FilenamesType FilenamesType;
	FilenamesType filenames = utils::Directory::GetFiles(argv[1], ".json");

	for(unsigned int i = 0; i < filenames.size(); i++)
	{
		std::string filename = filenames[i];		
		std::cout << filename << std::endl;

		QString inFilename = QString::fromStdString(filename);
		inFilename = inFilename.replace(QString::fromStdString(argv[1]),"");
		inFilename = inFilename.replace("/","");
		inFilename = inFilename.replace(".json","");
		//std::cout << inFilename.toStdString() << std::endl;


		vt::JsonReader::Pointer reader = vt::JsonReader::New();
		reader->SetFilename(filename);
		typedef vt::JsonReader::LineSet LineSet;
		LineSet data = reader->Read();
		
		std::string partName = inFilename.toStdString();

		LineSet::iterator lineIt = data.begin();
		while(lineIt != data.end())
		{
			QString type = QString::fromStdString(lineIt->first);
			type = type.replace(":","-");

			QString output = QString::fromStdString(argv[2]);
			QDir outputDir(output);

			QString outputPath = outputDir.absoluteFilePath(type);
			//std::cout << outputPath.toStdString() << std::endl;

			if(!outputDir.exists(outputPath))
				outputDir.mkdir(outputPath);
			

			QString fileName = QDir(outputPath).absoluteFilePath(QString::fromStdString(partName));



			vt::JsonConverter::Pointer converter = vt::JsonConverter::New();
			converter->SetInput(lineIt->second);
			converter->Convert();

			vt::ValveSequenceWriter<3>::Pointer writer = vt::ValveSequenceWriter<3>::New();
			writer->SetInput(converter->GetOutput());
			writer->SetFileName(fileName.toStdString());
			writer->Write();

			std::cout << fileName.toStdString() << " " << converter->GetOutput()->GetNumberOfLines() << std::endl;


			++lineIt;
		}	






	}


	return 0;

}
コード例 #4
0
ファイル: MainWindow.cpp プロジェクト: oferoze/MyLib
void MainWindow::getFilenamesFromBrowser(FilenamesType filenames)
{

	/////////////////////////////////////////////////////
	// Try and load the images that have been selected
	/////////////////////////////////////////////////////
	mitk::DataNode::Pointer ds = mitk::DataNode::New();
	ds = mitk::DicomSeriesReader::LoadDicomSeries(filenames,true, true);

	/////////////////////////////////////////////////////
	// Get some information about the images to display
	/////////////////////////////////////////////////////
	mitk::Image::Pointer image = dynamic_cast<mitk::Image*>(ds->GetData());

	// now we check to see if it is a time series
	int numTimeSteps = ds->GetData()->GetTimeSteps();
	if(numTimeSteps > 1) {

		// now the trouble starts....
		mitk::Image::Pointer sortedImage = mitk::Image::New();
		mitk::Vector3D vec = image->GetGeometry(0)->GetFloatSpacing();

		sortedImage->Initialize(image);
		vec[2] = 8.0;
		sortedImage->GetGeometry(0)->SetSpacing(vec);
		sortedImage->GetGeometry(0)->Modified();
		sortedImage->Modified();

		// now we are loading the images one by one and putting them in
		for(unsigned int i = 0; i < filenames.size(); i++)
		{
			mitk::ItkImageFileReader::Pointer reader = mitk::ItkImageFileReader::New();
			reader->SetFileName(filenames[i]);

			reader->Update();

			reader->GetOutput()->GetGeometry(0)->SetSpacing(vec);
			reader->GetOutput()->GetGeometry(0)->Modified();

			sortedImage->SetVolume(reader->GetOutput()->GetData(), i);
		}



		ds->SetData(sortedImage);
		ds->Modified();

	}


	this->m_DataStorage->Add(ds);





	// build the name of the image sequence
	std::string nameProperty;
	ds->GetStringProperty("dicom.series.SeriesDescription", nameProperty);

	std::string seriesNumProperty;
	ds->GetStringProperty("dicom.series.SeriesNumber", seriesNumProperty);
	ds->SetName(nameProperty + " " + seriesNumProperty);



	// disconnet the browser slot
	disconnect(browser, SIGNAL(okButtonSignal(FilenamesType)), this, SLOT(getFilenamesFromBrowser(FilenamesType)));

}
コード例 #5
0
int main(int, char ** argv)
{
	std::string inputFolder = argv[1];
	std::string outputFolder = argv[2];
	std::string lookupFilename = argv[3];


	// load the lookup file and read the image filenames
	LookupMap lookup;
	FilenamesType imageFilenames;
	readFilenames(inputFolder, imageFilenames);
	loadLookupFile(lookupFilename, lookup);

	// looop through the list of images
	for(unsigned int i = 0; i < imageFilenames.size(); i++)
	{
		std::string fname = imageFilenames[i];
		QFileInfo finfo(QString::fromStdString(fname));
		std::string basename = finfo.completeBaseName().toStdString() + ".nrrd";
		FilenamesType dicomFilenames = lookup[basename];

		// slice up the input image to recreate the output
		typedef utils::ImageVolume ImageType;
		ImageType::Pointer input = utils::ImageVolumeIO::Read(fname);

		const unsigned int slices = input->GetLargestPossibleRegion().GetSize()[2];

		for(unsigned int slice = 0; slice < slices; slice++)
		{
			typedef itk::RegionOfInterestImageFilter<ImageType, ImageType> ROIFilter;
			ROIFilter::Pointer roiFilter = ROIFilter::New();
			roiFilter->SetInput(input);

			ImageType::RegionType roi = input->GetLargestPossibleRegion();
			ImageType::IndexType roiIndex = roi.GetIndex();
			ImageType::SizeType roiSize = roi.GetSize();

			roiIndex[2] = slice;
			roiSize[2] = 1;
			roi.SetSize(roiSize);
			roi.SetIndex(roiIndex);

			roiFilter->SetRegionOfInterest(roi);
			roiFilter->Update();

			ImageType::Pointer imSlice = roiFilter->GetOutput();


			// load the dicom file
			std::string dicomFilename = dicomFilenames[slice];
			DcmFileFormat fileFormat;
			fileFormat.loadFile(dicomFilename.c_str());

			unsigned int numberOfPixels = imSlice->GetLargestPossibleRegion().GetNumberOfPixels();
			unsigned short * buffer = new unsigned short[numberOfPixels];
			fileFormat.getDataset()->putAndInsertUint16Array(DCM_PixelData, buffer, imSlice->GetLargestPossibleRegion().GetNumberOfPixels());

			// reset the pixel values
			itk::ImageRegionConstIterator<ImageType> it(imSlice, imSlice->GetLargestPossibleRegion());
			unsigned int count = 0;
			while(!it.IsAtEnd())
			{
				buffer[count] = it.Get();
				++it; ++count;
			}
			
			fileFormat.getDataset()->putAndInsertUint16Array(DCM_PixelData, buffer, imSlice->GetLargestPossibleRegion().GetNumberOfPixels());
			// create the output filename 
			std::stringstream ss;
			ss << outputFolder << "/dicom_" << i << "_" << slice << ".dcm";


			fileFormat.saveFile(ss.str().c_str());
		}
	}

	return 0;
}