[vtkusers] how ti binarize a volume?

Kacper Pluta kacper.pluta at gmail.com
Sun Dec 25 17:11:47 EST 2011


Dnia niedziela, 25 grudnia 2011 13:45:52 rimaS pisze:
> Hi all,
>  Merry christmas for all the vtk users :)
> I have a volume got from a .OBJ file, i just want to make it binary, and
> i've any idea about this :(
> Does someone know how can i do it, please?
> thank you in advance.
> Rima
> 
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/how-ti-binarize-a-volume-tp5100666p5100666
> .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
> 
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers

Hi!

Try to use vtkImageCast, and set output data type to U_CHAR == BYTE


vtkImageCast *imgCast = vtkImageCast::New();
imgCast->SetOutputScalarTypeToUnsignedChar();
imgCast->SetInput(volume);
imgCast->Update();

If you have something outside of 0 and 1 in the values ​​of voxels:

binImage = vtkImageData::New();
binImage->SetSpacing(raw->GetSpacing());
binImage->SetDimensions(raw->GetDimensions());
binImage->SetExtent(raw->GetExtent());
binImage->SetOrigin(raw->GetOrigin());
binImage->SetScalarTypeToUnsignedChar();
binImage->AllocateScalars();
  
int dims[3];
raw->GetDimensions(dims);  
for (int z = 0; z < dims[2]; z++)
{
 for (int y = 0; y < dims[1]; y++)
 {
  for (int x = 0; x < dims[0]; x++)
  {
    if(raw->GetScalarComponentAsDouble(x,y,z,0) > 0)
      binImage->SetScalarComponentFromDouble(x,y,z,0,255);
    else
      binImage->SetScalarComponentFromDouble(x,y,z,0,0);
  }
 }
}

-- 
"If you build your empire on money, it'll fall like a house of cards, if you 
build it on love, you've built Taj Mahal!" - Mark Hartmaier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111225/e8f5199d/attachment.htm>


More information about the vtkusers mailing list