Exemplo n.º 1
0
void PivotMDS::singularValueDecomposition(
	Array<Array<double> >& pivDistMatrix,
	Array<Array<double> >& eVecs,
	Array<double>& eVals)
{
	const int l = pivDistMatrix.size();
	const int n = pivDistMatrix[0].size();
	Array<Array<double> > K(l);
	for (int i = 0; i < l; i++) {
		K[i].init(l);
	}
	// calc C^TC
	selfProduct(pivDistMatrix, K);

	Array<Array<double> > tmp(DIMENSION_COUNT);
	for (int i = 0; i < DIMENSION_COUNT; i++) {
		tmp[i].init(l);
	}

	eigenValueDecomposition(K, tmp, eVals);

	// C^Tx
	for (int i = 0; i < DIMENSION_COUNT; i++) {
		eVals[i] = sqrt(eVals[i]);
		for (int j = 0; j < n; j++) { // node j
			eVecs[i][j] = 0;
			for (int k = 0; k < l; k++) { // pivot k
				eVecs[i][j] += pivDistMatrix[k][j] * tmp[i][k];
			}
		}
	}
	for (int i = 0; i < DIMENSION_COUNT; i++) {
		normalize(eVecs[i]);
	}
}
Exemplo n.º 2
0
void TubeDetection::calcMaxMedialness()
{
    unsigned x,y,z;

    unsigned int x_size;
    unsigned int y_size;
    unsigned int z_size;

    float V[3][3];
    float d[3];

    FloatImageType::Pointer max_medialnessimage;

    FloatImageType::IndexType index;

    float scale_index[3];
    HessianFilter::OutputImageType::IndexType indexi;

    DuplicatorType::Pointer duplicator = DuplicatorType::New();
    duplicator->SetInputImage(medialnessImages.at(medialnessImages.size() - 1));
    duplicator->Update();

    max_medialnessimage = duplicator->GetOutput();

    allocateEigenvectorImage();


    std::cout << "Starting calculating maximum of medialness." << std::endl;

    x_size = medialnessImages.at(medialnessImages.size() - 1)->GetLargestPossibleRegion().GetSize(0);
    y_size = medialnessImages.at(medialnessImages.size() - 1)->GetLargestPossibleRegion().GetSize(1);
    z_size = medialnessImages.at(medialnessImages.size() - 1)->GetLargestPossibleRegion().GetSize(2);

    float current_medialness_value;
    float max_medialness_value;
    int  max_medialness_scale_level;

    for(x = 0; x < x_size; x++)
    {
      index[0] = x;

      if(x % 10 == 0)
        std::cout << "x " << x << std::endl;

      for(y = 0; y < y_size; y++)
      {
        index[1] = y;

        for(z = 0; z < z_size; z++)
        {
          index[2] = z;

          //This is the value we obtain from the largest resolution
          max_medialness_value = max_medialnessimage->GetPixel(index);
          max_medialness_scale_level = medialnessImages.size() - 1;

          //Now we go through all scale levels and look for a maximum..
          for(unsigned i = 0; i < this->medialnessImages.size() - 1; i++)
          {
            scale_index[0] = static_cast<float>(x) / powf(2,medialnessImages.size() - 1 - i);
            scale_index[1] = static_cast<float>(y) / powf(2,medialnessImages.size() - 1 - i);
            scale_index[2] = static_cast<float>(z) / powf(2,medialnessImages.size() - 1 - i);

            current_medialness_value = NumericsHelper::trilinearInterp(medialnessImages.at(i), scale_index[0], scale_index[1], scale_index[2]);

            if(current_medialness_value > max_medialness_value)
            {
              max_medialness_value = current_medialness_value;
              max_medialness_scale_level = i;
            }

          }

          //Now write the maximum into the image again
          max_medialnessimage->SetPixel(index, max_medialness_value);



          //now calculate and save the EV of that pixel:
          indexi[0] = static_cast<int>(roundf(static_cast<float>(x) / powf(2,medialnessImages.size() - 1 - max_medialness_scale_level)));
          indexi[1] = static_cast<int>(roundf(static_cast<float>(y) / powf(2,medialnessImages.size() - 1 - max_medialness_scale_level)));
          indexi[2] = static_cast<int>(roundf(static_cast<float>(z) / powf(2,medialnessImages.size() - 1 - max_medialness_scale_level)));


          eigenValueDecomposition(max_medialness_scale_level, indexi, V, d);


          eigenvector[0]->SetPixel(index, V[0][0]);
          eigenvector[1]->SetPixel(index, V[0][1]);
          eigenvector[2]->SetPixel(index, V[0][2]);

        }
      }
    }

   this->maxMedialnessOverScales = max_medialnessimage;
   std::cout << "Finished calculating maximum of medialness." << std::endl;
}
Exemplo n.º 3
0
void TubeDetection::calcMedialness()
{
    unsigned x,y,z;
    HessianFilter::OutputImageType::IndexType index;
    unsigned int x_size;
    unsigned int y_size;
    unsigned int z_size;



    float V[3][3];
    float d[3];

    FloatImageType::Pointer medialnessimage;

    std::cout << "Starting calculating medialness for level: ";


    for(unsigned i = 0; i < this->imagePyramid.size(); i++)
    {
        std::cout << i << " " << std::endl;

        //medialnessimage = imagePyramid.at(i)->Clone();
        DuplicatorType::Pointer duplicator = DuplicatorType::New();
        duplicator->SetInputImage(imagePyramid.at(i));
        duplicator->Update();

        medialnessimage = duplicator->GetOutput();

        x_size = imagePyramid.at(i)->GetLargestPossibleRegion().GetSize(0);
        y_size = imagePyramid.at(i)->GetLargestPossibleRegion().GetSize(1);
        z_size = imagePyramid.at(i)->GetLargestPossibleRegion().GetSize(2);

        for(x = 0; x < x_size ; x++)
        {
            index[0] = x;

            if(x % 10 == 0)
              std::cout << "x = " << x << std::endl;

            for(y = 0; y < y_size; y++)
            {
                index[1] = y;

                for(z = 0; z < z_size; z++)
                {
                    //Indices for gradient, forward differences
                    index[2] = z;


                    eigenValueDecomposition(i, index, V, d);

                    float medialness = calcMedialness(i, x, y, z, d, V);

                    medialnessimage->SetPixel(index, medialness);
                }
            }
        }

        medialnessImages.push_back(medialnessimage);
    }

    std::cout << std::endl << "Finished calculation of medialness" << std::endl;
}