Setting a vtkImageBlend base layer to Transparent

Hello everyone,

Is it possible for the vtkimageBlend initial layerthe one SetInputConnection(…) to have a transparency of 0.0. From what I understand I've not been able to set its alpha to 0.0 and have it render properly.

What I mean is if I have
01-actual

and the triangle which is on the first layer gets turned off (by setting the opacity of the ImageBlend to 0.0) I expect to see
02-desired

but instead I see
03-undesiredimages

Is there a way to achieve the above desired effect?

Hi Seun,

Something doesn’t quite make sense with your description.

For “Normal” alpha blending (i.e. SetBlendModeToNormal(), which is the default), the “alpha” coefficient is only applied to the overlay planes. It is not applied to the base.

The math for alpha blending can be described as follows:

We start with an exact copy of the base image. Call this “C”.
Then for each overlay “O” and that overlay’s alpha, we modify “C”:
C’ = (1 - alpha)C + alphaO

So the only way to “turn off” the base is to make the overlay fully opaque.
The alpha of the base is, in fact, unused.

The blending could have been implemented differently. There could have been an “implicit” base image that had a solid color, settable with a SetBackgroundColor() method, so that a person could e.g. call SetBackgroundColor(0, 0, 0, 0) and then the first input image would be blended into that. But that’s not how vtkImageBlend was implemented. To achieve the same effect, you’d have to insert a fully transparent image as the base.

I hope this helps explain things.

David

Hi David,

`Thanks a lot for the expeditious response. To be honest I’m a bit uncertain about it myself, perhaps that’s why I couldn’t quite communicate the issue correctly, apologies for that.

It seems to be making sense to me now. I do wonder, if I make the base overlay fully opaque but I really don’t want to see it I’m thinking it will render that image completely visible occluding the other possible overlays I have in the pipeline (well unless like you suggested the base overlay is a transparent image).`

The grey you are seeing could well be because in the past I couldn’t get the transparency of the base layer to work so I was clamping the min & max range of the lookup table I am using in my pipeline.

Not to confuse you any further, the pipeline is basically like below, perhaps I can adjust something somewhere in it to address the transparency issue

pipeline

I’m still not quite sure if I understand. The base image cannot occlude an overlay image, since the overlays are by definition “over” the base. The order in which images are added to the blender is crucial, since later images will occlude earlier images, but never vice-versa.

Hi David,

You are right about the behaviour you described, I believe what I was trying to convey unsuccessfully was that, if I rendered a mesh (M) whose structure is from a Data (lets call that Base-Image (BI)) and initial colour also from (BI) and then I have an Overlay (O) pasted over M.

1 - So In essence, the Mesh will be rendered structurally from BI,
2 - the Mesh will have its original colour from the BI
3 - the Overlay O will be pasted over the result of the last step above

so the idea is to somehow turn off step 2, by turning off the alpha of BI but retain only the colour of step 3 over the Mesh without getting the non-overlapping part of the Mesh with Step-3 coloured.
I guess actually writing this out to you makes it more clear to me this may well be an impossible task.

  • for whatever it’s worth: the results from the blender (which contains, BI & O) is fed through a vtkImageProbeFilter and applied over the Mesh.

I suspect that what you are doing is possible. But I still don’t quite understand your explanations. These are the phrases that I don’t understand. Can you clarify them?

  • “a mesh whose structure is from a Data” - what kind of data?
  • “the Mesh will be rendered structurally” - I don’t know what “rendered structurally” means.

As I mentioned in my previous message, I think you can achieve what you want by setting the first input to vtkImageBlend to a blank RGBA image, and then add all your other images (including the “old” base image) as overlays.

You can create a blank RGBA image by passing one of the other images through a lookup table that maps all input values to (0.0, 0.0, 0.0, 0.0).

Now that I think about it a little more, my suggestion of using a blank RGBA image as the base will not work. The ‘A’ component of the RGBA pixels/voxels of the base image is simply copied to the output. So the end result would always be a fully transparent image.

But if you had a preferred colour that you want to use for the mesh in places where there was no “image” that overlapped it, you could still use my idea to create a solid-coloured base image for vtkImageBlend, and then have your old base image and overlay on top of that. E.g. use solid (0.5, 0.5, 0.5, 1.0) if you want the base colour of the mesh to be gray.

Hi David,

pardon the late response, yesterday was hectic. Just for clarification purposes, excuse my poor choice of word. what I meant by structurally is I have a vtkImageData (from a dataset) that I convert to a vtkPolyData which is then rendered. The vtkImageData (dataset) is also the one I referred to as being the base.

However, after reading your messages above, it’s clear that I am mistaking several things. I believe I can do what you said “I think you can achieve what you want by setting the first input to vtkImageBlend to a blank RGBA image, and then add all your other images (including the “old” base image) as overlays.”

Huge thanks for the clarifications and your patience. I believe I have a better idea of the issue now.