/*!
 * Initialize phi
 */
void ActiveContourSeed::initializePhi(int protobuf_idx, Protobuf *proto) {

	// set resolution
	phi_->setResolution(p_->res_x, p_->res_y, p_->res_z);

	// initialize image
	phi_->resize(_dimx_Rel, _dimy_Rel, _dimz_Rel);

	// get cell centers, previous sparse segmentation from protobuf file
	Array1D<int> xAbs(cb), yAbs(cb), zAbs(cb);
	proto->getSparseSegmentationCoordinates("full", protobuf_idx, &xAbs, &yAbs,
			&zAbs);

	// if previous sparse segmentation is empty, then initialize phi from single point
	if (xAbs.size() == 0) {
		for (int x = 0; x < _dimx_Rel; x++) {
			for (int y = 0; y < _dimy_Rel; y++) {
				for (int z = 0; z < _dimz_Rel; z++) {
					float xRadial = (float) (x - _hszX);
					float yRadial = (float) (y - _hszY);
					float zRadial = (float) (z - _hszZ);
					(*phi_)(x, y, z) = sqrtf(
							xRadial * xRadial + yRadial * yRadial + zRadial
									* zRadial) - p_->r;
				}
			}
		}
		// otherwise, initialize phi using distance transform on previous segmentation
	} else {
		// get previous binary segmentation, store in phi
		for (int p = 0; p < xAbs.size(); p++) {
			int xRel, yRel, zRel;
			absToRel(xRel, yRel, zRel, xAbs(p), yAbs(p), zAbs(p));
			(*phi_)(xRel, yRel, zRel) = 1;
		}

		// get perimeter segmentation and store in phi.  Store original segmentation in temp
		Image3D<float> temp(*phi_);
		perim(phi_, 1);

		// calculate distance transform
		bwdist(phi_);

		// Make distances negative inside the segmentation
		for (int x = 0; x < _dimx_Rel; x++) {
			for (int y = 0; y < _dimy_Rel; y++) {
				for (int z = 0; z < _dimz_Rel; z++) {
					if (temp(x, y, z) > float(BWTHRESH)) {
						(*phi_)(x, y, z) = -(*phi_)(x, y, z);
					}
				}
			}
		}
	}

	updateFullSeg(phi_);
}
Exemple #2
0
CChartDataList AFR::toChartData(unsigned interalParts) const {
    CChartDataList result;
    if (interalParts & Real) {
        CDimensionArray* xRe(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yRe(new CDimensionArray(static_cast<int>(this->size())));
        double* xReIt(xRe->data());
        double* yReIt(yRe->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xReIt, ++yReIt) {
            *xReIt = it->frequency;
            *yReIt = it->amplitude.real();
        }
        xRe->updateRange();
        yRe->updateRange();
        CChartData re;
        re.push_back(xRe);
        re.push_back(yRe);
        result << re;
    }
    if (interalParts & Imaginary) {
        CDimensionArray* xIm(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yIm(new CDimensionArray(static_cast<int>(this->size())));
        double* xImIt(xIm->data());
        double* yImIt(yIm->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xImIt, ++yImIt) {
            *xImIt= it->frequency;
            *yImIt = it->amplitude.imag();
        }
        xIm->updateRange();
        yIm->updateRange();
        CChartData im;
        im.push_back(xIm);
        im.push_back(yIm);
        result << im;
    }
    if (interalParts & Amplitude) {
        CDimensionArray* xAbs(new CDimensionArray(static_cast<int>(this->size())));
        CDimensionArray* yAbs(new CDimensionArray(static_cast<int>(this->size())));
        double* xAbsIt(xAbs->data());
        double* yAbsIt(yAbs->data());
        for (AFR::const_iterator it(this->begin()); it != this->end(); ++it, ++xAbsIt, ++yAbsIt) {
            *xAbsIt = it->frequency;
            *yAbsIt = abs(it->amplitude);
        }
        xAbs->updateRange();
        yAbs->updateRange();
        CChartData abs;
        abs.push_back(xAbs);
        abs.push_back(yAbs);
        result << abs;
    }
    return result;
}