[vtkusers] Combination of two images

Adrien Marion adrien.marion at creatis.insa-lyon.fr
Wed Apr 13 09:54:18 EDT 2011


I added the correct lines below:

opac = vtkImageThreshold();
opac.SetInput(readerMask.GetOutput());
opac.ThresholdByUpper(1);
opac.ReplaceInOn();
opac.ReplaceOutOn();
opac.SetInValue(255);
opac.SetOutValue(0);
opac.Update();

// Here opac is a binary image (0 or 255).

app = vtkImageAppend();
app.SetInput(readerMask.GetOutput());
app.SetInput(opac.GetOutput());
app.Update();

blend = vtkImageBlend();
blend.SetInput(readerImage.GetOutput());
blend.SetInput(app.GetOutput());
blend.Update();

// blend is the same as opac, i.e. equal to 0 or 255

Another tip or mistake to avoid ?

Adrien

Le 13/04/2011 15:45, David Gobbi a écrit :
> Oops, one other thing!
>
> When blending, the image with alpha comes second, not first:
> blend.SetInput(currentImage);
> blend.AddInput(app.GetOutput());
>
>   - David
>
>
> On Wed, Apr 13, 2011 at 7:42 AM, David Gobbi<david.gobbi at gmail.com>  wrote:
>> Hi Adrien,
>>
>> The alpha mask should have values of 0 and 255:
>> opac.ReplaceInOn();
>> opac.ReplaceOutOn();
>> opac.SetInValue(255);
>> opac.SetOutValue(0);
>>
>>   - David
>>
>>
>> On Wed, Apr 13, 2011 at 7:33 AM, Adrien Marion
>> <adrien.marion at creatis.insa-lyon.fr>  wrote:
>>> Thank you David.
>>> vtkImageStencil is not OK adding
>>>
>>> IS.SetInput(img);
>>>
>>> So I tried your second solution doing (test with python):
>>>
>>> opac = vtkImageThreshold();
>>> opac.SetInput(img);
>>> opac.ThresholdByUpper(1);
>>> opac.SetInValue(1);
>>> opac.Update();    // Thresholded image with 2 levels (0 and 1)
>>>
>>> app = vtkImageAppend();
>>> app.SetInput(img);
>>> app.SetInput(opac.GetOutput());
>>> app.Update();    // Image with 2 components, the initial one (img) and the
>>> associated binary mask
>>>
>>> blend = vtkImageBlend();
>>> blend.SetInput(app.GetOutput());
>>> blend.SetInput(currentImage);
>>> blend.Update();
>>>
>>> However, It does not provide the good combination. Did I wrote mistakes ?
>>> I do not understand how to say that the blend must take the second component
>>> of app (i.e. the binary mask) to decide if pixels have to be replaced.
>>>
>>> Adrien
>>>
>>> Le 13/04/2011 14:59, David Gobbi a écrit :
>>>> Hi Pat,
>>>>
>>>> The vtkImageStencil filter can take two image inputs, try adding this:
>>>>
>>>>
>>>>
>>>> You can also combine the images without using stencils.  To do this,
>>>> you would use vtkImageThreshold to generate your mask image, and then
>>>> vtkImageAppend to append this mask to img as an alpha channel.  Then
>>>> vtkImageBlend can be used to combine the images, it will use the alpha
>>>> channel to decide which pixels to replace.  This method doesn't have
>>>> any advantage compared to using stencils, it's just a different way of
>>>> doing the same thing.
>>>>
>>>>   - David
>>>>
>>>> On Wed, Apr 13, 2011 at 6:42 AM, Adrien Marion
>>>> <adrien.marion at creatis.insa-lyon.fr>    wrote:
>>>>> Hi,
>>>>> I have two vtkImageData (called currentImage and img), each containing
>>>>> values from 0 to 250.
>>>>> I would like to combine these images to obtain a resulting image
>>>>> (resImage)
>>>>> doing for each pixel:
>>>>> - if Mask == 0, resImage = currentImage
>>>>> - else resImage = Mask
>>>>>
>>>>> I currently work with VTK wrapped version in Java and I cannot afford a
>>>>> triple loop with getScalarAsDoubleComponent to do that.
>>>>>
>>>>> Does someone have a simple solution to do that ?
>>>>>
>>>>> I already tried with vtkImageStencil but It does not give the good
>>>>> solution:
>>>>>
>>>>>         vtkImageToImageStencil IIS = new vtkImageToImageStencil();
>>>>>         IIS.SetInput(img);
>>>>>         vtkImageStencil IS = new vtkImageStencil();
>>>>>         IS.SetStencil(IIS.GetOutput());
>>>>>         IS.SetInput(currentImage);
>>>>>         IS.Update();
>>>>>         result = IS.GetOutput();
>>>>>
>>>>> I think I did not understand how vtkImageStencil works.
>>>>>
>>>>> Thank you in advance for your help,
>>>>> Adrien
>>>>>
>>>>> --
>>>>> Adrien MARION, Docteur/PhD
>>>>> Chercheur post-doctorant (ANR VIP)
>>>>> Laboratoire CREATIS, INSA de Lyon
>>>>> CNRS UMR 5220, INSERM U1044
>>>>> Bâtiment Blaise Pascal, 4ème étage
>>>>> 7, avenue Jean Capelle
>>>>> 69621 Villeurbanne cedex FRANCE
>>>>> Tel : (+33) 4 72 43 87 86
>>>>> Fax:  (+33) 4 72 43 85 26
>>>>> e-mail : adrien.marion at creatis.insa-lyon.fr
>>>>> http://www.creatis.insa-lyon.fr/~amarion
>>> --
>>> Adrien MARION, Docteur/PhD
>>> Chercheur post-doctorant (ANR VIP)
>>> Laboratoire CREATIS, INSA de Lyon
>>> CNRS UMR 5220, INSERM U1044
>>> Bâtiment Blaise Pascal, 4ème étage
>>> 7, avenue Jean Capelle
>>> 69621 Villeurbanne cedex FRANCE
>>> Tel : (+33) 4 72 43 87 86
>>> Fax:  (+33) 4 72 43 85 26
>>> e-mail : adrien.marion at creatis.insa-lyon.fr
>>> http://www.creatis.insa-lyon.fr/~amarion

-- 
Adrien MARION, Docteur/PhD
Chercheur post-doctorant (ANR VIP)
Laboratoire CREATIS, INSA de Lyon
CNRS UMR 5220, INSERM U1044
Bâtiment Blaise Pascal, 4ème étage
7, avenue Jean Capelle
69621 Villeurbanne cedex FRANCE
Tel : (+33) 4 72 43 87 86
Fax:  (+33) 4 72 43 85 26
e-mail : adrien.marion at creatis.insa-lyon.fr
http://www.creatis.insa-lyon.fr/~amarion




More information about the vtkusers mailing list