Hey everyone,

 

I'm trying to get the coordinates of all pixels from a fresh created
segmentation. What I achieved so far is to get the node from the data
manager and I also could iterate through all the points oft the segmentation
to check if its 0 or not. However this takes quite a lot of time and even
gives me wrong values or NaN, wich means something must be wrong. So now I
try to get only the shown segmentation where only the existing points are
included. My problem is, that i cant acces the label properly. 

 

Does anyone have an idea how to achieve my goal? Anything that I could do
better? Thanks for your time anyway!

 

My attempts so far:

 

// acces the data storage

    QList<mitk::DataNode::Pointer> nodes = this->GetDataManagerSelection();

    if (nodes.empty())

      return;

 

    mitk::DataNode *node = nodes.front();

 

    if (!node)

    {

      // Nothing selected. Inform the user and return

      QMessageBox::information(NULL, "Template", "Please load and select an
image before starting image processing.");

      return;

    }

 

    

    // get the label with the stored points

    mitk::LabelSetImage *lsi =
dynamic_cast<mitk::LabelSetImage*>(node->GetData());

 

    unsigned int labels = lsi->GetTotalNumberOfLabels();

    std::cout << "Total number of Labels: " << labels << std::endl; // 2
labels

    std::cout << "number of Labels layer 0: " << lsi->GetNumberOfLabels(0)
<< std::endl; // 2

    std::cout << "number of Labels layer 1: " << lsi->GetNumberOfLabels(1)
<< std::endl; // >1000000 (changes with every new segmentation)

    //std::cout << "number of labels layer 2: " << lsi->GetNumberOfLabels(2)
<< std::endl; // crash

 

    std::cout << "number of layer: " << lsi->GetNumberOfLayers() <<
std::endl; // 1

    std::cout << "number of channels " << lsi->GetNumberOfChannels() <<
std::endl; // 1

 

    const mitk::PixelType type = lsi->GetPixelType();

    std::cout << "image type: " << type.GetPixelTypeAsString() << std::endl;
//nothing

 

 

    mitk::Label *lab = lsi->GetActiveLabel();

    mitk::Point3D cent = lab->GetCenterOfMassIndex();

    std::cout << "label 0 center of mass index " << cent << std::endl; //
nothing

 

 

    //read in all of the points and write to matrix

    uint32_t neuerzaehlerb = 0;

 

    mitk::Image *layerfive = lsi->GetLayerImage(lsi->GetActiveLayer()); //
try till 5

 

    unsigned int maxx = layerfive->GetDimension(0); //lsi

    unsigned int maxy = layerfive->GetDimension(1);

    unsigned int maxz = layerfive->GetDimension(2);

 

    Eigen::MatrixXd matb(1,3);

    double point[3];

 

    for (unsigned int a = 0; a < maxx; a++){

        for (unsigned int b = 0; b < maxy; b++){

            for (unsigned int c = 0; c < maxz; c++){

                itk::Index<3> idx = {{ a, b, c }};

                double pt = layerfive->GetPixelValueByIndex(idx);

                if (pt != 0){

                    point[0] = static_cast<double>(a);

                    point[1] = static_cast<double>(b);

                    point[2] = static_cast<double>(c);

                    if ( isnan(point[0]) == false || isnan(point[1]) ==
false || isnan(point[2] == false) ) {

                        matb.resize(neuerzaehlerb+2,3);

                        matb(neuerzaehlerb,0)=point[0];

                        matb(neuerzaehlerb,1)=point[1];

                        matb(neuerzaehlerb,2)=point[2];

                        std::cout << "mat zeile: " << neuerzaehlerb << " : "
<< matb.row(neuerzaehlerb) << std::endl;

                        neuerzaehlerb++;

                    }

                }

            }

        }

    }

 

    neuerzaehlerb = neuerzaehlerb - 5;

    matb.resize(neuerzaehlerb,3);

 

 

    QString outputpoints="Points: ";

    outputpoints +=QString::number(neuerzaehlerb);

    outputpoints.append(" ...succesfull loaded from the selected
segmentation.");

    m_Controls.displaybottom->append(outputpoints + "\n");

 

    Setmatrix(matb);

    Pca();

 

/*

    //attempt 2

    

    mitk::Image::Pointer image =
dynamic_cast<mitk::Image*>(node->GetData());

    const mitk::PixelType &type = image->GetPixelType();

    std::string types = type.GetPixelTypeAsString();

    std::cout << "image type: " << types << std::endl;  // nothing

 

    // access the raw image data

    try

    {

      itk::Index<3> idx = {{ 1, 1, 1 }};

 

      mitk::ImagePixelReadAccessor<short,3> readAccess(image,
image->GetSliceData(2));

      std::cout << "step 1.1..OK  "  << std::endl;

      short value = readAccess.GetPixelByIndex(idx);

      std::cout << "step 1.2..OK...value:  " << value << std::endl;

    }

    catch(mitk::Exception& e)

    {

      // deal with the situation not to have access

        std::cout << "no acces to image data " << std::endl;

    }

 

    // another attempt

    try

    {

      float coords[3]={1.0,1.0,1.0};

      mitk::Point3D position(coords);

 

      mitk::ImagePixelReadAccessor<uint16_t,3> readAccess(image);

      std::cout << "step 2.1..OK " << std::endl;

      short value = readAccess.GetPixelByWorldCoordinates(position);

      std::cout << "step 2.2..OK..value 2: " << value << std::endl;

    }

    catch(mitk::Exception& e)

    {

      // deal with the situation not to have access

        std::cout << "no acces to image data v 2 " << std::endl;

    }

 

    // iterate through all pixels and check if the value is 0 or 1 (binary
image)

*/

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
mitk-users mailing list
mitk-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to