Trouble blending two 3d images

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Trouble blending two 3d images

Andaharoo
I have two 3d images that I'd like to blend and then display in imageViewer2. Here's the code:
// Create the mask image based off input
maskImage = vtkSmartPointer<vtkImageData>::New();
maskImage->SetDimensions(inputImage->GetDimensions());
maskImage->SetSpacing(inputImage->GetSpacing());
maskImage->SetOrigin(inputImage->GetOrigin());
maskImage->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
int* dim = maskImage->GetDimensions();
// Get pointer to beginning of image
unsigned char* ptr = static_cast<unsigned char*>(maskImage->GetScalarPointer(0, 0, 0));
for (int i = 0; i < dim[0] * dim[1] * dim[2]; i++)
{
        // Set and advance the pixel
        *ptr++ = 255;
        *ptr++ = 0;
        *ptr++ = 0;
}
blendFilter = vtkSmartPointer<vtkImageBlend>::New();
blendFilter->AddInputData(inputImage);
blendFilter->AddInputData(maskImage);
blendFilter->SetOpacity(0, 1.0);
blendFilter->SetOpacity(1, 0.5);
blendFilter->Update();

Unfortunately my program just freezes and pulls up the vtkOutputWindow with nothing in it.

Also does type matter when using these? I'm trying to blend a grayscale (single float image) with an rgb image (uchar).
Reply | Threaded
Open this post in threaded view
|

Re: Trouble blending two 3d images

kenichiro yoshimi
Hi Andaharoo,

How about compiling with debug and using DebugOn member function on
the blendFilter?
  blendFilter->DebugOn();
It may display additional information related to the problem.

Regards,
yoshimi

2017-08-13 17:28 GMT+09:00 Andaharoo <[hidden email]>:

> I have two 3d images that I'd like to blend and then display in imageViewer2.
> Here's the code:
> // Create the mask image based off input
> maskImage = vtkSmartPointer<vtkImageData>::New();
> maskImage->SetDimensions(inputImage->GetDimensions());
> maskImage->SetSpacing(inputImage->GetSpacing());
> maskImage->SetOrigin(inputImage->GetOrigin());
> maskImage->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
> int* dim = maskImage->GetDimensions();
> // Get pointer to beginning of image
> unsigned char* ptr = static_cast<unsigned
> char*>(maskImage->GetScalarPointer(0, 0, 0));
> for (int i = 0; i < dim[0] * dim[1] * dim[2]; i++)
> {
>         // Set and advance the pixel
>         *ptr++ = 255;
>         *ptr++ = 0;
>         *ptr++ = 0;
> }
> blendFilter = vtkSmartPointer<vtkImageBlend>::New();
> blendFilter->AddInputData(inputImage);
> blendFilter->AddInputData(maskImage);
> blendFilter->SetOpacity(0, 1.0);
> blendFilter->SetOpacity(1, 0.5);
> blendFilter->Update();
>
> Unfortunately my program just freezes and pulls up the vtkOutputWindow with
> nothing in it.
>
> Also does type matter when using these? I'm trying to blend a grayscale
> (single float image) with an rgb image (uchar).
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Trouble-blending-two-3d-images-tp5744385.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Trouble blending two 3d images

Bill Lorensen
Please provide a small compilable example that illustrates the problem.

On Mon, Aug 14, 2017 at 10:43 AM kenichiro yoshimi <[hidden email]> wrote:
Hi Andaharoo,

How about compiling with debug and using DebugOn member function on
the blendFilter?
  blendFilter->DebugOn();
It may display additional information related to the problem.

Regards,
yoshimi

2017-08-13 17:28 GMT+09:00 Andaharoo <[hidden email]>:
> I have two 3d images that I'd like to blend and then display in imageViewer2.
> Here's the code:
> // Create the mask image based off input
> maskImage = vtkSmartPointer<vtkImageData>::New();
> maskImage->SetDimensions(inputImage->GetDimensions());
> maskImage->SetSpacing(inputImage->GetSpacing());
> maskImage->SetOrigin(inputImage->GetOrigin());
> maskImage->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
> int* dim = maskImage->GetDimensions();
> // Get pointer to beginning of image
> unsigned char* ptr = static_cast<unsigned
> char*>(maskImage->GetScalarPointer(0, 0, 0));
> for (int i = 0; i < dim[0] * dim[1] * dim[2]; i++)
> {
>         // Set and advance the pixel
>         *ptr++ = 255;
>         *ptr++ = 0;
>         *ptr++ = 0;
> }
> blendFilter = vtkSmartPointer<vtkImageBlend>::New();
> blendFilter->AddInputData(inputImage);
> blendFilter->AddInputData(maskImage);
> blendFilter->SetOpacity(0, 1.0);
> blendFilter->SetOpacity(1, 0.5);
> blendFilter->Update();
>
> Unfortunately my program just freezes and pulls up the vtkOutputWindow with
> nothing in it.
>
> Also does type matter when using these? I'm trying to blend a grayscale
> (single float image) with an rgb image (uchar).
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/Trouble-blending-two-3d-images-tp5744385.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
_______________________________________________
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
--
Unpaid intern in BillsBasement at noware dot com

_______________________________________________
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
Reply | Threaded
Open this post in threaded view
|

Re: Trouble blending two 3d images

Andaharoo
In reply to this post by kenichiro yoshimi
Thanks, I wasn't aware there was a DebugOn function. It seems you can't blend a greyscale and rgb image. It's strange this error message isn't thrown to the vtkOutputWindow without DebugOn though. Instead just blankly doing nothing. Color mapping the rgb image to r=g=b and then blending worked. This works:
// Creates a blank image to edit and overlay over the input
> maskImage = vtkSmartPointer<vtkImageData>::New();
> maskImage->SetDimensions(inputImage->GetDimensions());
> maskImage->SetSpacing(inputImage->GetSpacing());
> maskImage->SetOrigin(inputImage->GetOrigin());
> maskImage->AllocateScalars(VTK_UNSIGNED_CHAR, 3);
> int* dim = maskImage->GetDimensions();
> // Get pointer to beginning of image
> unsigned char* ptr = static_cast<unsigned
> char*>(maskImage->GetScalarPointer(0, 0, 0));
> for (int i = 0; i < dim[0] * dim[1] * dim[2]; i++)
> {
>         // Set and advance the pixel. Initially make the mask red for testing.
>         *ptr++ = 255;
>         *ptr++ = 0;
>         *ptr++ = 0;
> }
blendFilter = vtkSmartPointer<vtkImageBlend>::New();
// Convert greyscale input to rgb
rgbConverter = vtkSmartPointer<vtkImageMapToColors>::New();
rgbConverter->SetInputData(input);
rgbMap = vtkSmartPointer<vtkScalarsToColors>::New();
rgbConverter->SetLookupTable(rgbMap);
rgbConverter->Update();
blendFilter->AddInputData(rgbConverter->GetOutput());
blendFilter->AddInputData(maskImage);
blendFilter->SetOpacity(0, 1.0);
blendFilter->SetOpacity(1, 0.5);
blendFilter->Update();