int main(int argc, char *argv[])
{
	// load the data
	typedef utils::MatrixReader MatReader;
	MatReader::Pointer reader = MatReader::New();
	reader->SetFilename(argv[1]);
	reader->Read();

	utils::MatrixDataSet::Pointer data = reader->GetOutput();

	typedef manifold::DiffusionMap DiffMap;
	DiffMap::Pointer diffMap = DiffMap::New();
	diffMap->Fit(data->doubleData["swiss"].transpose());

	DiffMap::MatrixType E;
	diffMap->GetEmbedding(E);


	utils::MatrixDataSet::Pointer output = utils::MatrixDataSet::New();
	output->AddData("E",E);



	typedef utils::MatrixWriter Writer;
	Writer::Pointer writer = Writer::New();
	writer->SetInput(output);
	writer->SetFilename("E.mat");
	writer->Write();

	

	return 0;
}
Exemplo n.º 2
0
void output_mosaic_image(const IPF_Ptr& ipf, int layerIndex, int width, int height)
{
	typedef itk::Image<unsigned char,2> Image;
	Image::Pointer image = layerIndex > 0 ?
		make_mosaic_image_with_boundaries(ipf, layerIndex, width, height) :
		make_mosaic_image(ipf, layerIndex, width, height);

	typedef itk::ImageFileWriter<Image> Writer;
	Writer::Pointer writer = Writer::New();
	writer->SetInput(image);
	writer->SetFileName(OSSWrapper() << "../resources/partition" << layerIndex << ".bmp");
	writer->Update();
}
Exemplo n.º 3
0
void real_image_test()
{
	typedef itk::Image<unsigned char,2> UCImage;
	typedef itk::ImageFileReader<UCImage> UCReader;

	// Read in the image (when debugging in VC++, it may be necessary to set the working directory to "$(TargetDir)").
	UCReader::Pointer reader = UCReader::New();
	reader->SetFileName("../resources/test.bmp");
	reader->Update();
	UCImage::Pointer windowedImage = reader->GetOutput();

	// Cast the windowed image to make a dummy Hounsfield image.
	typedef itk::Image<int,2> IntImage;
	typedef itk::CastImageFilter<UCImage,IntImage> UC2IntCastFilter;
	UC2IntCastFilter::Pointer uc2intCastFilter = UC2IntCastFilter::New();
	uc2intCastFilter->SetInput(windowedImage);
	uc2intCastFilter->Update();
	IntImage::Pointer hounsfieldImage = uc2intCastFilter->GetOutput();

	// Cast the windowed image to make its pixels real-valued.
	typedef itk::Image<float,2> RealImage;
	typedef itk::CastImageFilter<UCImage,RealImage> UC2RealCastFilter;
	UC2RealCastFilter::Pointer uc2realCastFilter = UC2RealCastFilter::New();
	uc2realCastFilter->SetInput(windowedImage);

	// Smooth this real image using anisotropic diffusion.
	typedef itk::GradientAnisotropicDiffusionImageFilter<RealImage,RealImage> AnisotropicDiffusionFilter;
	AnisotropicDiffusionFilter::Pointer adFilter = AnisotropicDiffusionFilter::New();
	adFilter->SetInput(uc2realCastFilter->GetOutput());
	adFilter->SetConductanceParameter(1.0);
	adFilter->SetNumberOfIterations(5);		// a typical value (see the ITK software guide)
	adFilter->SetTimeStep(0.125);

	// Calculate the gradient magnitude of the smoothed image.
	typedef itk::Image<short,2> GradientMagnitudeImage;
	typedef itk::GradientMagnitudeImageFilter<RealImage,GradientMagnitudeImage> GradientMagnitudeFilter;
	GradientMagnitudeFilter::Pointer gradientMagnitudeFilter = GradientMagnitudeFilter::New();
	gradientMagnitudeFilter->SetInput(adFilter->GetOutput());
	gradientMagnitudeFilter->SetUseImageSpacingOff();
	gradientMagnitudeFilter->Update();
	GradientMagnitudeImage::Pointer gradientMagnitudeImage = gradientMagnitudeFilter->GetOutput();

	// Run the watershed algorithm on the gradient magnitude image.
	typedef MeijsterRoerdinkWatershed<GradientMagnitudeImage::PixelType,2> WS;
	WS ws(gradientMagnitudeImage, ITKImageUtil::make_4_connected_offsets());

	std::cout << "Label Count: " << ws.label_count() << '\n';

	// Convert the watershed label image to a colour RGB image.
	typedef itk::RGBPixel<unsigned char> RGBPixelType;
	typedef itk::Image<RGBPixelType,2> RGBImage;
	typedef itk::Functor::ScalarToRGBPixelFunctor<long> ColourMapFunctorType;
	typedef itk::UnaryFunctorImageFilter<WS::LabelImage, RGBImage, ColourMapFunctorType> ColourMapFilter;
	ColourMapFilter::Pointer colourMapper = ColourMapFilter::New();
	colourMapper->SetInput(ws.labels());

	// Output the result to a file.
	typedef itk::ImageFileWriter<RGBImage> Writer;
	Writer::Pointer writer = Writer::New();
	writer->SetInput(colourMapper->GetOutput());
	writer->SetFileName("../resources/output.bmp");
	writer->Update();

	// Create the initial partition forest.
	typedef PartitionForest<CTImageLeafLayer,CTImageBranchLayer> IPF;
	typedef shared_ptr<IPF> IPF_Ptr;
	shared_ptr<CTImageLeafLayer> leafLayer(new CTImageLeafLayer(hounsfieldImage, windowedImage, gradientMagnitudeImage));
	shared_ptr<CTImageBranchLayer> lowestBranchLayer = IPF::make_lowest_branch_layer(leafLayer, ws.calculate_groups());
	IPF_Ptr ipf(new IPF(leafLayer, lowestBranchLayer));
}