Hi again.
I've an image with 3 time channels (0,1 and 2). So my vectors are
saved. Now I want to create a new image node with color informations.
So i try to save for every voxel a color in RGBA in my mitk-Image.
normalized x -> red
normalized y -> green
normalized z -> blue
1 -> alpha (first, later length of vector)
Has mitk function to set a voxel a specific color like
mitkImage->SetVoxelColor(x,y,z,r,g,b,a) ?
I tried it like my code down here. But in the new ImageNode are no
color informations and the values are not set or very high (displayed
is everything in black).
thanks for help
Frank
MITK_INFO << "Performing image processing.";
//ToDo
//Erstelle Farbwerte aus den normalen der Zeiten für X Y Z
//Erstelle neues MITK Bild und schreibe werte hinein
//Erstelle neue MITK DataNode für DataManager der ExtApp
//Image dimensions
unsigned int *dimensionImage = image->GetDimensions();
unsigned int dimensions[3];
dimensions[0] = dimensionImage[0];
dimensions[1] = dimensionImage[1];
dimensions[2] = dimensionImage[2];
//Number of voxels in image
int voxel = dimensions[0] * dimensions[1] * dimensions[2];
//number of all RGBA color values
unsigned char* RGBABuffer = new unsigned char[4*voxel];
double red,green,blue,tmp = 0;
int bufferIndex = 0;
double alpha = 1;
//Voxel-coordinates to get color value from image.
mitk::Index3D position;
// typedef double PixelType;
// static const unsigned int Dimension = 3;
// typedef itk::Image <PixelType,Dimension> ImageType;
// ImageType::IndexType index;//Voxel-coordinates to save
new color values in new image. (Needet for projection on axis.)
//or other order for X Y Z <--> Z Y X ?
for(int i=0; i<dimensions[2];i++)
{
position[2]=i;
for(int j=0; j<dimensions[1];j++)
{
position[1]=j;
for(int k=0; k<dimensions[0];k++)
{
position[0]=k;
//In image are also negative values, so we
need absolute numbers.
red = image->GetPixelValueByIndex(position,0);
red = abs(red);
green = image->GetPixelValueByIndex(position,1) ;
green = abs(green);
blue = image->GetPixelValueByIndex(position,2) ;
blue = abs(blue);
//Normalize colors.
tmp = sqrt(pow(red,2) + pow(green,2) + pow(blue,2));
red /= tmp;
green /= tmp;
blue /= tmp;
//fill RGBABuffer
//bufferIndex=0
//Voxel 1 -> RGBABuffer ( t*4+0 t*4+1 t*4+2
t*4+2 t*4+3 ;)
//bufferIndex++
//voxel 2 -> RGBABuffer ( t*4+0 t*4+1 t*4+2
t*4+2 t*4+3 ;)
// RGBABuffer[bufferIndex*4+0] =
*reinterpret_cast<char**>(&red);//red
RGBABuffer[bufferIndex*4+0] = (unsigned char)red;
RGBABuffer[bufferIndex*4+1] = (unsigned char)green;
RGBABuffer[bufferIndex*4+2] = (unsigned char)blue;
RGBABuffer[bufferIndex*4+3] = (unsigned char)alpha;
bufferIndex++;
}
}
}
//Create the new Image
mitk::Image::Pointer coloredMitkImage = mitk::Image::New();
//missing geometry informations, so that it will have the
same size like original image
typedef itk::RGBAPixel <unsigned char> RGBAPixel;
mitk::PixelType pixelType( typeid(RGBAPixel), 1,
itk::ImageIOBase::RGBA );
coloredMitkImage->Initialize(pixelType, 3, dimensions);
coloredMitkImage->SetImportChannel(RGBABuffer, 0,
mitk::Image::ManageMemory);
//Create new DataNode
mitk::DataNode::Pointer nodeMitkImage = mitk::DataNode::New();
nodeMitkImage->SetData(coloredMitkImage);
nodeMitkImage->SetName(node->GetName() + "_ColoredMitkImage");
//nodeMitkImage->SetProperty ( "TransferFunction",
mitk::TransferFunctionProperty::New(tfX.GetPointer()));
this->GetDefaultDataStorage()->Add(nodeMitkImage);//Will
add as child.(doesn't work)
//ToDo unmark shown-property for parent image
> Fri, 10 Sep 2010 13:10:59 +0200 - Frank Blaschke
> <[email protected]>:
> [mitk-users] MITK Plugin different color for timeNr
> Hi,
>
> I have a diffusion image in *.nii format. It include value from -1
> until 1. X-values are in time 0, Y-values in time 1 and Z-values in
> time 2.
> I wanna turn X-values red, Y green and Z in blue. But when I use the
> code here, all values in X,Y and Z time will be colored.
>
> Thanks for help
>
> Frank
>
> <code>
>
> MITK_INFO << "Performing diffusion image coloring.";
>
> //turn X redr, Y green and Z blue
> //transfer function from 0 till 1 of [r,g,b] = [0,0,0]
> until [1,0,0] etc
> //create new node,, hide the old one
>
> //Create new DataNode
> mitk::DataNode::Pointer dataNode = mitk::DataNode::New();
> dataNode->SetData(image);
> dataNode->SetName(node->GetName() + "_DiffusionColor");
>
> //TimeSelector to get singe images x,y,z
> mitk::ImageTimeSelector::Pointer selector =
> mitk::ImageTimeSelector::New();
> selector->SetInput(image);
>
> //X-image from time 0
> selector->SetTimeNr(0);//X
> selector->Update();
> mitk::Image::Pointer selectedImageX = mitk::Image::New();
> selectedImageX->Initialize(selector->GetPic());
> selectedImageX->SetPicVolume(selector->GetPic());
>
> //selectedImageX->SetGeometry(selector->GetGeometry());//doesn't work
> selectedImageX->Update();
>
> //Y-image from time 1
> selector->SetTimeNr(1);//Y
> selector->Update();
> mitk::Image::Pointer selectedImageY = mitk::Image::New();
> selectedImageY->Initialize(selector->GetPic());
> selectedImageY->SetPicVolume(selector->GetPic());
>
> //selectedImageY->SetGeometry(selector->GetGeometry());//doesn't work
> selectedImageY->Update();
>
> //Z-image from time 2
> selector->SetTimeNr(2);//Z
> selector->Update();
> mitk::Image::Pointer selectedImageZ = mitk::Image::New();
> selectedImageZ->Initialize(selector->GetPic());
> selectedImageZ->SetPicVolume(selector->GetPic());
>
> //selectedImageZ->SetGeometry(selector->GetGeometry());//doesn't work
> selectedImageZ->Update();
>
> // Set the property "volumerendering" to the Boolean
> value "true"
> dataNode->SetProperty("volumerendering",
> mitk::BoolProperty::New(true));
> //dataNode->SetProperty("color",
> mitk::BoolProperty::New(true));
>
> // Create a transfer function to assign optical
> properties (color and opacity) to grey-values of the data
> mitk::TransferFunction::Pointer tfX =
> mitk::TransferFunction::New();
> tfX->InitializeByMitkImage(selectedImageX);
>
> // Set the color transfer function AddRGBPoint(double
> x, double r, double g, double b)
> tfX->GetColorTransferFunction()->AddRGBPoint ( -1.0,
> 1.0, 0.0, 0.0 );
> tfX->GetColorTransferFunction()->AddRGBPoint ( 0.0,
> 0.0, 0.0, 0.0 );
> // tfX->GetColorTransferFunction()->AddRGBPoint (
> tfX->GetColorTransferFunction()->GetRange()[0], 0.0, 0.0, 0.0 );
> tfX->GetColorTransferFunction()->AddRGBPoint ( 1.0,
> 1.0, 0.0, 0.0 );
> // tfX->GetColorTransferFunction()->AddRGBPoint (
> tfX->GetColorTransferFunction()->GetRange()[1], 1.0, 0.0, 0.0 );
>
> // Set the piecewise opacity transfer function
> AddPoint(double x, double y)
> tfX->GetScalarOpacityFunction()->AddPoint ( -1.0, 1.0 );
> tfX->GetScalarOpacityFunction()->AddPoint ( 0.0, 0.0 );
> tfX->GetScalarOpacityFunction()->AddPoint ( 1.0, 1.0);
> // tfX->GetScalarOpacityFunction()->AddPoint (
> tfX->GetColorTransferFunction()->GetRange()[1], 1.0);
>
> dataNode->SetProperty ( "TransferFunction",
> mitk::TransferFunctionProperty::New(tfX.GetPointer()));
>
> this->GetDefaultDataStorage()->Add(dataNode);//Should
> add as child, but add as new node next to the others.
>
> MITK_INFO << "Done.";
>
> </code>
>
>
> --
>
> Frank Blaschke
>
> Department for Biometry and Medical Informatics
> web: http://www.med.uni-magdeburg.de/ibmi.html
> phone: +49 391 67 135 51
> office: building 2 / room 212
>
>
>
> ------------------------------------------------------------------------------
> Automate Storage Tiering Simply
> Optimize IT performance and efficiency through flexible, powerful,
> automated storage tiering capabilities. View this brief to learn how
> you can reduce costs and improve performance.
> http://p.sf.net/sfu/dell-sfdev2dev
> _______________________________________________
> mitk-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mitk-users
>
>
--
Frank Blaschke
Department for Biometry and Medical Informatics
web: http://www.med.uni-magdeburg.de/ibmi.html
phone: +49 391 67 135 51
office: building 2 / room 212
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users