[vtkusers] existing filter to perform replace value on vtkImage

Dominik Szczerba dominik at itis.ethz.ch
Tue Feb 16 17:53:01 EST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Of course you can march the image by foot:

       for(int k=ext[4]; k<=ext[5]; k++)
                for(int j=ext[2]; j<=ext[3]; j++)
                        for(int i=ext[0]; i<=ext[1]; i++)
                const unsigned char* ptr = (unsigned
char*)image->GetScalarPointer(i,j,k);

unsigned char* ptr2 = (unsigned char*)image2->GetScalarPointer(i,j,k);

if(*ptr<200) *ptr2 = 0;

Dominik

Dominik Szczerba wrote:
> Below some snippets how I use it.
> 
> 
> 
> calculator->SetResultArrayType(VTK_DOUBLE);
> 
> calculator->SetInput(viewer->image);
> 
> string function = "if("+scalarName+"=13,1,0)";
> calculator->AddScalarArrayName(scalarName.c_str());
> calculator->SetFunction(function.c_str());
> calculator->SetResultArrayName(scalarName.c_str());
> 
> 
> 
> I operate on image data and filter out any pixels not falling into
> explicit values. Modification for your purpose is straight forward.
> 
> Dominik
> 
> Michael Jackson wrote:
>> On Feb 16, 2010, at 11:47 AM, David Doria wrote:
> 
>>> On Tue, Feb 16, 2010 at 1:59 PM, Michael Jackson
>>> <mike.jackson at bluequartz.net> wrote:
>>>> Is there an existing filter where I can replace a value in the  
>>>> image if the
>>>> value does not meet some criteria? Something like:
>>>>
>>>> if (value < 255 ) value = 0;
>>>>
>>>> Thanks
>>>> _________________________________________________________
>>>> Mike Jackson                  mike.jackson at bluequartz.net
>>> Two things come to mind -
>>>
>>> 1) You can identify those regions with vtkImageThreshold:
>>> http://www.vtk.org/Wiki/VTK/Examples/Images/ImageThreshold
>>> http://www.vtk.org/doc/nightly/html/classvtkImageThreshold.html
>>>
>>> 2) Maybe you can set all the pixels found in (1) to some specific
>>> value, and then you can use
>>> vtkImageMathematics::SetOperationToReplaceCByK to replace that
>>> specific value with 0 (as your original question suggested you want to
>>> do).
>>>
>>> Hope that helps,
>>>
>>> David
>>>
>> Thanks. I Took a look at those filters but did not really understand  
>> what I was supposed to set any to? Basically I have a tiff file that  
>> was supposed to be either black or white. Turns out there are also  
>> intermediate values in there probably from some anti-aliasing or  
>> something. So basically, if the value is NOT 255, replace it with 0. I  
>> was thinking the Array Calculator but my simple mind couldn't really  
>> come up with an equation that would give me what I want.
> 
>> _________________________________________________________
>> Mike Jackson                  mike.jackson at bluequartz.net
>> BlueQuartz Software                    www.bluequartz.net
>> Principal Software Engineer                  Dayton, Ohio
> 
> 
>> _______________________________________________
>> 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
> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.vtk.org/mailman/listinfo/vtkusers
> 
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkt7IcwACgkQ/EBMh9bUuzK7VgCaAiqGp3rNLOPhQIGrsS1SqYmo
0yEAniF0RStpDKVv8fFe1YORS90TKqXn
=Wz4r
-----END PGP SIGNATURE-----



More information about the vtkusers mailing list