[vtkusers] Processing DIOCM image with vtkImageData class

orientation f fuzengliang435 at gmail.com
Sat Aug 25 21:07:23 EDT 2007


hello:
I want to do a series of DICOM image processing with vtkImageData class, ie,
getting the gray value of point (i,j) with
GetScalarComponentAsDouble(i,  j,0,0), and set it with
SetScalarComponentFromDouble(i,j,0,0,grayValue), but there is some problem:
the program is as follow:
   #include "vtkDICOMImageReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageData.h"
#include "vtkRenderer.h"

int main()
{
    vtkDICOMImageReader   *reader =  vtkDICOMImageReader::New();
        reader->SetDataByteOrderToLittleEndian();
        reader->SetFileName("ankle.dcm");
        //Set the origin of the data (location of first pixel in the file)
        reader->SetDataOrigin(0.0,0.0,0.0);
        reader->Update();
        int wide=reader->GetWidth();
        int height=reader->GetHeight();

        vtkImageData *imgData=vtkImageData::New();
        imgData->SetDimensions(wide,height,1);
    imgData->SetScalarTypeToUnsignedChar();
    imgData->SetNumberOfScalarComponents(4);
    imgData->AllocateScalars();

        imgData->DeepCopy(reader->GetOutput());


        for(int i=1;i<wide-1;i++)
                for(int j=1;j<height-1;j++)
                {
                        double temp;

temp=reader->GetOutput()->GetScalarComponentAsDouble(i,  j,0,0);
                        //evaluate imgData with original image's gray value
                        imgData->SetScalarComponentFromDouble(i,j,0,0,temp);
                }

                //grads
         for( i=1;i<wide-1;i++)
                for(int j=1;j<height-1;j++)
                {

                        int temp1[10];
    //the processed image is good when using progarm 2. but the processed
image is exceptional when progarm 1 is used. The data in imageData and
reader should be the same with
"temp=reader->GetOutput()->GetScalarComponentAsDouble(i,  j,0,0);
                        //evaluate imgData with original image's gray
value
imgData->SetScalarComponentFromDouble(i,j,0,0,temp);"
but the actual result is different. Maybe the class data style is different.
It will be thankful if you can tell me why!

                        //=====program 1:
                        /*

temp1[1]=imgData->GetScalarComponentAsDouble(i-1,j-1,0,0);


temp1[2]=imgData->GetScalarComponentAsDouble(i,  j-1,0,0);

temp1[3]=imgData->GetScalarComponentAsDouble(i+1,j-1,0,0);


temp1[4]=imgData->GetScalarComponentAsDouble(i-1,j,0,0);

temp1[5]=imgData->GetScalarComponentAsDouble(i,  j,0,0);

temp1[6]=imgData->GetScalarComponentAsDouble(i+1,j,0,0);*/

                        //=====program 2:

temp1[1]=reader->GetOutput()->GetScalarComponentAsDouble(i-1,j-1,0,0);

temp1[2]=reader->GetOutput()->GetScalarComponentAsDouble(i,  j-1,0,0);

temp1[3]=reader->GetOutput()->GetScalarComponentAsDouble(i+1,j-1,0,0);


temp1[4]=reader->GetOutput()->GetScalarComponentAsDouble(i-1,j,0,0);

temp1[5]=reader->GetOutput()->GetScalarComponentAsDouble(i,  j,0,0);

temp1[6]=reader->GetOutput()->GetScalarComponentAsDouble(i+1,j,0,0);
                        //=====program2


temp1[5]=sqrt((temp1[5]-temp1[3])*(temp1[5]-temp1[3])+(temp1[2]-temp1[6])*(temp1[2]-temp1[6]));


imgData->SetScalarComponentFromDouble(i,j,0,0,temp1[5]);

                }




//=======================================================

    vtkImageViewer  *viewer = vtkImageViewer::New();
    viewer->SetInput(imgData);
        viewer->SetColorWindow(280);
        viewer->SetColorLevel(40);
        viewer->SetPosition(100,100);
        viewer->Render();

    vtkRenderWindowInteractor *viewerinter =
vtkRenderWindowInteractor::New();
    viewer->SetupInteractor(viewerinter);
    viewerinter->Initialize();
    viewerinter->Start();

        reader->Delete();
        imgData->Delete();
        viewer->Delete();
        viewerinter->Delete();

        return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070826/bb28e559/attachment.htm>


More information about the vtkusers mailing list