[vtkusers] A question about displaying Image using VTK

Cory Quammen cory.quammen at kitware.com
Thu Jul 16 11:11:11 EDT 2015


Hi,

Thank you for including your code. That makes it much easier to help.

In your code, your opacity function has value 1200 at data value 0. The
opacities between data value 0 and data value 1200 are linear interpolated,
and I think having that high opacity at data value 0 made most of the
opacities > 1.0 for values between 0 and 1200.

Try changing this line

opacityTransferFunction->AddPoint(0,1200);

to

opacityTransferFunction->AddPoint(0,0);

This should solve your problem. It does on tests on my system.

Best regards,
Cory


On Fri, Jul 10, 2015 at 2:55 AM, 15891495523 at 126.com <15891495523 at 126.com>
wrote:

> Dear Cory
>
>        I am sorry, but those code doesn't work.
>
>        And the complete code is :
> void main()
> {
>
> vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
>
> reader->SetDirectoryName("G:\\Perfusion Project\\Perfusion_MIP\\MIP\\TimePhase\\Time2");
>   reader->SetDataByteOrderToBigEndian();
>   reader->Update();
>
>
>
> vtkSmartPointer<vtkImageShiftScale> shift = vtkSmartPointer<vtkImageShiftScale>::New();
> shift->SetInputConnection(reader->GetOutputPort());
> shift->SetOutputScalarTypeToUnsignedShort();
> shift->Update();
>
>
> vtkSmartPointer<vtkImageReslice> reslice = vtkSmartPointer<vtkImageReslice>::New();
> reslice->SetInputData(shift->GetOutput());
> reslice->SetOutputDimensionality(3);
> reslice->Update();
>
> vtkSmartPointer<vtkImageData> image = vtkSmartPointer<vtkImageData>::New();
> image=reslice->GetOutput();
>
>
> vtkSmartPointer<vtkImageWriter> writer = vtkSmartPointer<vtkImageWriter>::New();
> writer->SetInputData(image);
> writer->SetFileName("C:\\Users\\zhq\\Desktop\\VolumeData.vtk");
> writer->Update();
>
> vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
>
> vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
>
> vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
>
> vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
>
> renWin->AddRenderer(ren);
> renWin->SetInteractor(iren);
> iren->SetInteractorStyle(style);
>
>
> vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction = vtkSmartPointer<vtkPiecewiseFunction>::New();
> opacityTransferFunction->AddPoint(0,1200);
> opacityTransferFunction->AddPoint(1200,0.4);
> opacityTransferFunction->AddPoint(2000,0.2);
>
>
> /*vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
> colorTransferFunction->AddRGBPoint(0,0,0.5,0);
> colorTransferFunction->AddRGBPoint(60,1,0,0);
> colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);*/
>
>
> vtkSmartPointer<vtkDiscretizableColorTransferFunction > colorTransferFunction = vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New();
> colorTransferFunction->AddRGBPoint(0,0,0.5,0);
> colorTransferFunction->AddRGBPoint(60,1,0,0);
> colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);
> colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);
> colorTransferFunction->EnableOpacityMappingOn();
>
>
> vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();
> volumeProperty->SetColor(colorTransferFunction);
> volumeProperty->SetScalarOpacity(opacityTransferFunction);
> volumeProperty->ShadeOn();
> volumeProperty->SetInterpolationTypeToLinear();
> volumeProperty->SetAmbient(0.2);
>
>
> vtkSmartPointer<vtkVolumeRayCastMIPFunction> mipRayCastFunction = vtkSmartPointer<vtkVolumeRayCastMIPFunction>::New();
>
> vtkSmartPointer<vtkVolumeRayCastCompositeFunction> compositeFunction = vtkSmartPointer<vtkVolumeRayCastCompositeFunction>::New();
>
> vtkSmartPointer<vtkVolumeRayCastMapper> volumeMapper = vtkSmartPointer<vtkVolumeRayCastMapper>::New();
>
> volumeMapper->SetVolumeRayCastFunction(compositeFunction);
> volumeMapper->SetInputData(image);
>
> vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New();
> volume->SetMapper(volumeMapper);
> volume->SetProperty(volumeProperty);
>
> ren->AddVolume(volume);
> ren->SetBackground(1,1,1);
> renWin->Render();
> iren->Initialize();
> iren->Start();
> }
>
>         Thank you very much!
>
> ZhangQiang
>
> ------------------------------
>
>
> *From:* Cory Quammen <cory.quammen at kitware.com>
> *Date:* 2015-07-10 00:42
> *To:* 15891495523 at 126.com
> *CC:* vtkusers <vtkusers at vtk.org>
> *Subject:* Re: [vtkusers] A question about displaying Image using VTK
> Instead of using a vtkColorTransferFunction, try using
> a vtkDiscretizableColorTransferFunction and setting the opacity function
> via SetScalarOpacityFunction(), e.g.
>
> vtkSmartPointer<vtkDiscretizableColorTransferFunction >
> colorTransferFunction =
> vtkSmartPointer<vtkDiscretizableColorTransferFunction >::New();
> colorTransferFunction->AddRGBPoint(0,0,0.5,0);
> colorTransferFunction->AddRGBPoint(60,1,0,0);
> colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);
> colorTransferFunction->SetScalarOpacityFunction(opacityTransferFunction);
>
> then enable opacity mapping with
>
> colorTransferFunction->EnableOpacityMappingOn();
>
> HTH,
> Cory
>
> On Thu, Jul 9, 2015 at 9:51 AM, 15891495523 at 126.com <15891495523 at 126.com>
> wrote:
>
>> Dear all
>>
>>     I feel confused when display a CT image using VTK. How can I make
>> those black and gray part in the following picture invisible ?
>>     The key part of my code is :
>>
>> vtkSmartPointer<vtkPiecewiseFunction> opacityTransferFunction =
>> vtkSmartPointer<vtkPiecewiseFunction>::New();
>>         opacityTransferFunction->AddPoint(0,1200);
>>         opacityTransferFunction->AddPoint(1200,0.4);
>>         opacityTransferFunction->AddPoint(2000,0.2);
>>
>>         vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
>> vtkSmartPointer<vtkColorTransferFunction>::New();
>>         colorTransferFunction->AddRGBPoint(0,0,0.5,0);
>>         colorTransferFunction->AddRGBPoint(60,1,0,0);
>>         colorTransferFunction->AddRGBPoint(255,0.8,0.8,0.8);
>>
>>
>> Thank you in advanced!
>>
>> ZhangQiang
>>
>>
>> ------------------------------
>>
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>>
>
>
> --
> Cory Quammen
> R&D Engineer
> Kitware, Inc.
>  [image: 提示图标] 邮件带有附件预览链接,若您转发或回复此邮件时不希望对方预览附件,建议您手动删除链接。
> 共有 *1* 个附件
>  InsertPic_.jpg(99K) 极速下载
> <http://preview.mail.126.com/xdownload?filename=InsertPic_.jpg&mid=1tbi5RkySFUw0mtsvwAAsJ&part=3&sign=fb3a712652d3c40c438e729aae49e4be&time=1436460555&uid=15891495523%40126.com>
> 在线预览
> <http://preview.mail.126.com/preview?mid=1tbi5RkySFUw0mtsvwAAsJ&part=3&sign=fb3a712652d3c40c438e729aae49e4be&time=1436460555&uid=15891495523%40126.com>
>
>


-- 
Cory Quammen
R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ccc9f863/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InsertPic_(07-10-14-55-37).jpg
Type: image/jpeg
Size: 22021 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ccc9f863/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: InsertPic_(07-10(07-10-14-55-37).jpg
Type: image/jpeg
Size: 100667 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150716/ccc9f863/attachment-0003.jpg>


More information about the vtkusers mailing list