Create histogram

249 Views Asked by At

I have a vtkDICOMImageReader, from where I intend to create a histogram in order to spread on my own CDialog. Here is my trial:

int* nDim = m_pDICOMReader->GetOutput()->GetDimensions();
for(int z = 0;z < nDim[2];++z)
{
    for(int y = 0;y < nDim[1];++y)
    {
        for(int x= 0 ;x < nDim[0];++x)
        {
            double* dPixel = static_cast<double*>(m_pDICOMReader->GetOutput()->GetScalarPointer(x, y, z));
            TRACE("%f|%f|%f\n", dPixel[0], dPixel[1], dPixel[2]);
        }
    }
}

but I get always 0.0 ...

I have 2 questions:

  1. Why I get 0.0 values from GetScalarPointer ?
  2. I am on the right way in order to create a histogram from a vtkDICOMImageReader ? I didn't see anything similar ...

Thank you.

P.S. Here is the code where I load vtlDICOMImageReader:

if(NULL == m_pDICOMReader)
{
    m_pDICOMReader = vtkDICOMReader::New();
}
if(! m_pDICOMReader->CanReadFile(lpszPathName))
{
    AfxMessageBox(_T("Can not read / parse the file."), MB_ICONERROR);
    return FALSE;
}
m_pDICOMReader->SetFileNames(p);
m_pDICOMReader->Update();

where p id a stringarray of dcm files ... m_pDICOMReader is working well, because I have volume on the screen, and it is moving well ...

Yes, I did this:

m_pDICOMReader->GetOutput()->AllocateScalars(VTK_DOUBLE, 1);
int* nDim = m_pDICOMReader->GetOutput()->GetDimensions();
for(int z = 0;z < nDim[2];++z)
{
    for(int y = 0;y < nDim[1];++y)
    {
        for(int x= 0 ;x < nDim[0];++x)
        {
            double* dPixel = static_cast<double*>(m_pDICOMReader->GetOutput()->GetScalarPointer(x, y, z));
            TRACE("%f|%f|%f\n", dPixel[0], dPixel[1], dPixel[2]);
        }
    }
}

but get me some weird values:

-6277438562204192500000000000000000000000000000000000000000000000000.000000|-6277438562204192500000000000000000000000000000000000000000000000000.000000|-6277438562204192500000000000000000000000000000000000000000000000000.000000

why ? Also, I tried with another vtk types: VTK_SHORT, the same result ...

P.S. I tried like that:

            m_pDICOMReader->SetFileNames(p);
            m_pDICOMReader->GetOutput()->AllocateScalars(VTK_DOUBLE, 1);
            m_pDICOMReader->Update();

The result is 0, 0, 0;

1

There are 1 best solutions below

0
On

Using AllocateScalars get me nothing on viewer (neither 2D image, neither volume) ... so, I made something (without using AllocateScalars):

int* nDim = m_pDICOMReader->GetOutput()->GetDimensions();
for(int z = 0;z < nDim[2];++z)
{
    for(int y = 0;y < nDim[1];++y)
    {
        for(int x= 0 ;x < nDim[0];++x)
        {
            unsigned char* chPixel = reinterpret_cast<unsigned char*>(m_pDICOMReader->GetOutput()->GetScalarPointer(x, y, z));
            TRACE("%d|%d|%d\n", chPixel[0], chPixel[1], chPixel[2]);
        }
    }
}

Well, here I get some values, but the issue that these loops are taking too long ... hmm ... weird, but to be honest, the looping are taken the same time with previous code (double* dPixel = static_cast(m_pDICOMReader...)).