[vtkusers] updating image grabs from a video source

Mark E Roberts mroberts at andrew.cmu.edu
Mon Aug 13 13:56:27 EDT 2007


Dear All,

I am grabbing screenshots from an ultrasound machine and using successive images to create a 3D image with vtkImageReslice and vtkImageMathematics. At this point, the code is written to combine 15 images in a row along the z-axis. The images are, in fact, one image used 15 times. What I would like to expand the code to do is take 15 snapshots from the video source and combine those. Unfortunately, I am grabbing one snapshot and then using that 15 times.  I am looking for help in identifying a solution to how I can update my pipeline to use the new snapshots. I've included part of my code to illustrate what I am trying to accomplish.

Any and all help is much appreciated.

Sincerely,
Mark Roberts

int frame = 0;

	for(int i = 0; i<15; i++){

		PP1->Delete();
		change->Delete();
		full->Delete();
		add->Delete();		
		transform->Delete();

		//
		//Image is grabbed
		//If the ultrasound machine is hooked up, the image is grabbed through ->Grab()
		//if it is not, then a random picture is used and it is sent through the vtkJPEGReader
		//and vtkImageToStructuredPoints part of the pipeline to creat a similar data
		//

		grabber->Grab();
		frame = grabber->GetFrameCount();
		
		cout<<"Frame count = "<<frame<<endl;

		PP1 = vtkImageToStructuredPoints::New();
		PP1->SetInput(grabber->GetOutput());
		PP1->Update();
	
	
		change = vtkImageChangeInformation::New();
		change->SetInput( PP1->GetOutput() );
		change->Update();


		cout<<i<<" slice grabbed"<<endl;


		//
		//vtkTransform can modify the orientation and position of the picture as if it were
		//a 4x4 homogeneous matrix (there is a class that can do that) but the rotations and translations are 
		//easier to input and all the calculations are taken care of automatically.
		//For this transformation, we are moving the picture horizontally along the z-axis by one pixel
		//
		
		transform = vtkTransform::New();
		transform->Translate(0., 0., -1.0*i);

		//
		//The picture is transformed and placed into the 3D volume that we have created. This puts the picture into 
		//world coordinates and allows for easy manipulation and comparison between pictures.
		//The picture, set as the input, is added to the background, which is the ->SetInformationInput
		//
		add = vtkImageReslice::New();
		add->SetInput(change->GetOutput());
		add->SetInformationInput(vol);
		add->SetOutputDimensionality(3);
		add->SetResliceTransform(transform);
	
		
		cout<<"New Image Reslice"<<endl;

		//
		//vtkImageMathematics is a simple function that compares two sets of structured points
		//In the pictures, black has a scalar value of zero and white has a value of one
		//ImageMathematics compares the two voxels and takes the higher voxel values and then discards the two 
		//pictures and creates a new one. 
		//

		full = vtkImageMathematics::New();
		full->SetInput1(add->GetOutput());
		full->SetInput2(temp->GetOutput());
		full->SetOperationToMax();
		
		//
		//Delete the old temp so that a new one can be made for the next iteration
		//
		
		temp->Delete();

		temp = vtkImageReslice::New();
		temp->SetInput(full->GetOutput());
		
		
		
		cout<<"Recopy the new picture"<<endl<<endl;

	
	}

		pic->Delete();
		full->Delete();
		add->Delete();
		transform->Delete();


	cout<<"Done"<<endl;





-- 
Mark Roberts
Masters of Science, Project Student
CER Lab
Carnegie Mellon University

301-806-6529

MRoberts at andrew.cmu.edu
MeerkyJ at gmail.com




More information about the vtkusers mailing list