[vtkusers] Scale an image.

David Gobbi dgobbi at atamai.com
Wed Mar 29 09:39:13 EST 2006


Hi Ana,

Thanks for the note on the vtkImageBlend error, that is a result of a 
bug that popped up when that class was converted to the new VTK 5 pipeline.

When you SetInformationInput(target_image), vtkImageReslice will 
automatically use the spacing, origin, and extent of the target_image so 
you don't have to set those directly.

Color mapping either before or after the Reslice will work.  Note that 
for the lookup table, after you call SetTableValue(), the 
SetAlphaRange() call has no effect, nor does SetHueRange(), 
SetSaturationRange(), or SetValueRange().  If you build the table with 
SetTableValue(), then all of those others are disabled and only 
SetTableRange() works.

You need to be careful about integer division,  this code is wrong:

   table1->SetTableValue(indice,r/255,g/255,b/255,1.0);

Even if you are currently declaring r, g, and b to be float or double, 
to make the code safe you should divide by 255.0:

  table1->SetTableValue(0,r/255.0, g/255.0 ,b/255.0 ,1.0);

Other than that I can't see any obvious errors in the code that would 
make it stop working after the pipeline is executed for the first time.  
You can try it without the RenderWindowInteractor and only use a 
RenderWindow instead, that way you can see clearly what happens on the 
first render.

 - David


Ana Sandro wrote:
> Hi David,
>
>   Thank you very much for your response.I've been trying this way but 
> I have some roblems and I'm really confused.
>
> When I introduce this part to my pipeline the program shows the scaled 
> image only for less than a second and then it disappeares,only the 
> target_image remains on the screen.I have no time to observe if the 
> scaled one is well magnified and I don't get any error message. Is it 
> possible that vtkImageReslice interfere with any other object of my 
> progam?.I've tried calling 
> vtkImageReslice->SetOutputExtent(),reslice->SetOutputOrigin() and 
> reslice->SetOutputSpacing() too because i read at old posts it's 
> necessary to later correct use of vtkImageBlend but the result doesn't 
> change.
>
> On the other hand if I try to reslice one 2D image to the size of 
> another and only visualize the scaled one there's no problem.Then I've 
> to use the vtkTransform to Translate and Scale the image in order to 
> it appears inside of the visualization area of the 
> RenderWindow.(Another question is how to calculate the values to these 
> methods,I don't know,I examined several values till I got 
> right).Whereas If I use vtkTransform in my pipeline the scaled image 
> directly doesn't appear neither for that first second,maybe because I 
> don't find right values to tranlate it?.
>
> I know I've a lot of doubts,I hope not to sound tedious and express 
> myself clearly.I add my code in case it helps to understand me.I'd 
> apreciate any clue.
> Thank you .
>
> //I obtain target_image at connector1
> typedef signed short InputPixelType;
> typedef unsigned short OutputPixelType;
> typedef itk::Image< InputPixelType, 3 > InputImageType;
> typedef itk::Image< OutputPixelType, 3 > OutputImageType;
> typedef itk::RescaleIntensityImageFilter< InputImageType, 
> OutputImageType > RescaleFilterType;
> RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
> typedef itk::Image<signed short,3> ImageType1;
> typedef itk::ImageFileReader<ImageType1> ReaderType1;
> typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType1;
> ReaderType1::Pointer reader1= ReaderType1::New();
> ConnectorType1::Pointer connector1= ConnectorType1::New();
> reader1->SetFileName("D:\\ana\\Imagenes\\03091536\\serieCT\\serieCT.img"); 
>
> rescaleFilter->SetInput( reader1->GetOutput() );
> rescaleFilter->SetOutputMinimum( 0 );
> rescaleFilter->SetOutputMaximum( 4000 );
> rescaleFilter->Update();
> connector1->SetInput( rescaleFilter->GetOutput() );
>
> //I obtain image to scale at connector
> typedef itk::Image<unsigned short,3> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
> ReaderType::Pointer reader= ReaderType::New();
> ConnectorType::Pointer connector= ConnectorType::New();
> reader->SetFileName("D:\\ana\\Imagenes\\03091536\\seriePET\\seriePET.img"); 
>
> connector->SetInput( reader->GetOutput() );
>
> //***Here I try to reslice.I've tried after map to colors too but no 
> change***
>   //vtkTransform* transform= vtkTransform::New();
>   //transform->Identity();
>   //transform->Scale(1.4,1.4,1);
>   //transform->Translate(-200,200,0);
> vtkImageReslice *reslice = vtkImageReslice::New();
> reslice->SetInput(connector->GetOutput());
>   //reslice->SetResliceTransform(transform);
> reslice->SetInformationInput(connector1->GetOutput());
> reslice->SetInterpolationModeToLinear();
>   //reslice->SetOutputExtent(0,511,0,511,0,0);
>   //reslice->SetOutputOrigin(0,0,0);
>   //reslice->SetOutputSpacing(1,1,1);
>
> //Make lookupTable to map target_image by gray scale.
> vtkLookupTable* table1 = vtkLookupTable::New();
> table1->SetNumberOfTableValues(256);
> table1->Build();
> table1->SetTableValue(0,r/255,g/255,b/255,1.0);
> for(i=1;i<256;i++) {
>
>     r++;
>     g++;
>     b++;
>     indice=i;
>     table1->SetTableValue(indice,r/255,g/255,b/255,1.0);
> }
> table1->SetTableRange(0,4000);
> table1->SetAlphaRange(1.0,1.0);
>
> //MakeLookupTable to map scaled image with color.
> vtkLookupTable* table = vtkLookupTable::New();
> r=0;
> g=0;
> b=254;
> table->SetNumberOfTableValues(256);
> table->Build();
> table->SetTableValue(0,r/255,g/255,b/255,1.0);
> for(i=1;i<128;i++) {
>
>     g=(g+2);
>     b=(b-2);
>     indice=i;
>     table->SetTableValue(indice,r/255,g/255,b/255,1.0);
> }
> table->SetTableValue(128,r/255,g/255,b/255,1.0);
> for (i=129;i<256;i++) {
>
>     r=(r+2);
>     g=(g-2);
>     indice=i;
>     table->SetTableValue(indice,r/255,g/255,b/255,1.0);
> }
> table->SetTableRange(0,2500);
> table->SetAlphaRange(1.0,1.0);
>
> //map both images with their color scale.
> vtkImageMapToColors* mapper = vtkImageMapToColors::New();
> mapper->SetInput(reslice->GetOutput());
> mapper->SetLookupTable(table);
> vtkImageMapToColors* mapper1 = vtkImageMapToColors::New();
> mapper1->SetInput(connector1->GetOutput());
> mapper1->SetLookupTable(table1);
>
> //blend both images
> vtkImageBlend* blend = vtkImageBlend::New();
> blend->SetOpacity(0, 0.5);
> blend->SetOpacity(1, 0.5);
> //I had to put AddInmput(0,---) instead 
> SetInput(0,---),SetInput(1,---) to solve this error:
> //ERROR: In 
> D:\ana\Programas\VTK-5.0.0\Filtering\vtkDemandDrivenPipeline.cxx,
> //line 774
> //vtkStreamingDemandDrivenPipeline (0x02A79170): Input for connection 
> index 0
> //on input port index 1 for algorithm vtkImageBlend(0x02A76480) is of 
> type
> //vtkImageData, but a vtkImageStencilData is required.
>
> blend->AddInput(0,mapper1->GetOutput());
> blend->AddInput(0,mapper->GetOutput());
>
> //Finally I visualize one 2D orthogonal plane of the volume image.
> vtkImageViewer2* viewer= vtkImageViewer2::New();
> vtkRenderWindowInteractor* 
> renderWindowInteractor=vtkRenderWindowInteractor::New();
> viewer->SetupInteractor( renderWindowInteractor);
> viewer->SetInput( blend->GetOutput() );
> orientacion=atoi(argv[1]);
> viewer->SetSliceOrientation(orientacion);
> slice=atoi(argv[2]);
> viewer->vtkImageViewer2::SetSlice(slice);
> viewer->Render();
> viewer->SetColorWindow(255);
> viewer->SetColorLevel(128);
> renderWindowInteractor->Start();
> return 0;
>
>
>
>
>
>> From: David Gobbi <dgobbi at atamai.com>
>> To: Ana Sandro <garufa7000 at hotmail.com>
>> CC: vtkusers at vtk.org
>> Subject: Re: [vtkusers] Scale an image.
>> Date: Thu, 23 Mar 2006 10:56:52 -0500
>>
>> Hi Ana,
>>
>> You can use vtkImageReslice to resample the first image so that it 
>> matches the second:
>>
>> vtkImageReslice *reslice = vtkImageReslice::New();
>> reslice->SetInput(image_to_scale);
>> reslice->SetResliceTransform(transform);
>> reslice->SetInformationInput(target_image);
>> reslice->SetInterpolationModeToLinear();
>>
>> blend->SetInput(0, target_image);
>> blend->SetInput(1, reslice->GetOutput());
>>
>> The "transform" can be used to control the position and scale of the 
>> first image with
>> respect to the second image, and vtkImageReslice makes sure that the 
>> one image is
>> resampled to match the other (and possibly cropped or padded, 
>> depending on how
>> much the transform magnifies or shrinks the image).
>>
>> - David
>>
>>
>> Ana Sandro wrote:
>>> Hello everybody,
>>>
>>>    My question is how to make an image bigger or smaller without 
>>> using an actor?.
>>> I use vtkImageviewer2 to visualize the final image and what I put 
>>> into it is this image blendeed with another one.So, I need to sclae 
>>> one of them in order to they both have the same size before to put 
>>> them into vtkImageBlend.I have problems to apply 
>>> vtkTransform.Someone could help me?I'd be so gatefull.
>>> Thank you to all.
>>>
>>> _________________________________________________________________
>>> Dale rienda suelta a tu tiempo libre. Mil ideas para exprimir tu 
>>> ocio con MSN Entretenimiento. http://entretenimiento.msn.es/
>>>
>>> _______________________________________________
>>> This is the private VTK discussion list. Please keep messages 
>>> on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>
> _________________________________________________________________
> Acepta el reto MSN Premium: Correos más divertidos con fotos y textos 
> increíbles en MSN Premium. Descárgalo y pruébalo 2 meses gratis. 
> http://join.msn.com?XAPID=1697&DI=1055&HL=Footer_mailsenviados_correosmasdivertidos 
>
>
>




More information about the vtkusers mailing list