void H5_LofarBFStokesWriter::_writeData( const SpectrumDataSetBase* d )
{
    if( d->type() != "SpectrumDataSetStokes" ) return;

    const SpectrumDataSetStokes* stokes = static_cast<const SpectrumDataSetStokes*>(d);
    unsigned nSamples = stokes->nTimeBlocks();
    unsigned nSubbands = stokes->nSubbands();
    unsigned nChannels = stokes->nChannels();
    unsigned nPolarisations = stokes->nPolarisations();
    float const * data = stokes->data();

    switch (_nBits) {
        case 32: {
             for (unsigned t = 0; t < nSamples; ++t) {
                 for (unsigned p = 0; p < polsToWrite(); ++p) {
                     for (int s = nSubbands - 1; s >= 0 ; --s) {
                         long index = stokes->index(s, nSubbands, 
                                 p, nPolarisations, t, nChannels );
                         for(int i = nChannels - 1; i >= 0 ; --i) {
                             _file[p]->write(reinterpret_cast<const char*>(&data[index + i]), 
                                     sizeof(float));
                         }
                     }
                 }
             }
                 }
                 break;
        case 8: {
                for (unsigned t = 0; t < nSamples; ++t) {
                    for (unsigned p = 0; p < polsToWrite(); ++p) {
                        for (int s = nSubbands - 1; s >= 0 ; --s) {
                            long index = stokes->index(s, nSubbands, 
                                    p, nPolarisations, t, nChannels );
                            for(int i = nChannels - 1; i >= 0 ; --i) {
                                int ci;
                                _float2int(&data[index + i],&ci);
                                _file[p]->write((const char*)&ci,sizeof(unsigned char));
                            }
                        }
                    }
                }
            }
            break;
        default:
            throw(QString("H5_LofarStokesWriter: %1 bit datafiles not yet supported"));
            break;
    }
}
Exemplo n.º 2
0
static int creategausskernel(float ** const kernel, int * const cw, float const sigma)
{
	int rcode = NO_ERROR;
	
	int i, cn;
	float k, sum, alpha, sigmainv;
	
	//
	// 0. 参数安全检查
	//
	assert(cw);
	assert(kernel);
	assert(NULL == *kernel);
	if (NULL == kernel || NULL != *kernel || NULL == cw || 0.0f >= sigma)
		return ERR_PARAMETER;
	
	//
	// 1. 计算窗口尺寸分配存储
	//
	alpha = (float)ceil(2.5f*sigma);
	cn  = _float2int(alpha);
	*cw = 2*cn+1;
	*kernel  = (float *)calloc((*cw), sizeof(float));
	if (NULL == *kernel) return ERR_MEM;
	
	//
	// 2. 计算高斯核
	//
	k = (float)(1.0f/sqrt(2*PI)*sigma);
	sigmainv = 1.0f/(sigma*sigma);
	
	sum = 0.0f;
	for (i = -cn; i <= cn; i++) {
		(*kernel)[i+cn] = (float)exp(-0.5f*i*i*sigmainv)*k;
		sum += (*kernel)[i+cn];
	}
	
	for (i = 0; i < (*cw); i++) {
		(*kernel)[i] /= sum;
	}
	
	return rcode;
}
Exemplo n.º 3
0
/////////////////////////////////////////////////////////////////////
// 名  称: IMAGE_GaussBlurEx
//
// 功  能: 扩展高斯模糊
//
// 参  数: IMAGE * const pimgsrc 源影像
//         IMAGE * const pimgdst 目标影像
//         float   const sigma   模糊程度
//
// 返回值: int
//===================================================================
EXPORT_C int IMAGE_GaussBlurEx(IMAGE * const pimgsrc, IMAGE * const pimgdst, float const sigma)
{
	int rcode = NO_ERROR;

	int i, cw;

	int ikernel, *kernelex = NULL;
	float fkernel, *kernel = NULL;

	IMAGE imgwrk0;
	IMAGE imgwrk1;
	IMAGE_ZeroImage(&imgwrk0);
	IMAGE_ZeroImage(&imgwrk1);

	//
	// 0. 安全检查
	//
	assert(pimgsrc);
	assert(pimgdst);
	if (NULL == pimgsrc->data || NULL == pimgdst->data) { // 要求影像有效性
		rcode = ERR_IMAGE; goto RET;
	}
	if (IMAGE_BITCOUNT(pimgsrc) != IMAGE_BITCOUNT(pimgdst)) { // 要求原影像与目标影像色深相同
		rcode = ERR_BITCOUNT; goto RET;
	}
	if (IMAGE_AREA_WIDTH(pimgsrc) != IMAGE_AREA_WIDTH(pimgdst) || IMAGE_AREA_HEIGHT(pimgsrc) != IMAGE_AREA_HEIGHT(pimgdst)) { // 要求原影像与目标影像处理区域尺寸相同
		rcode = ERR_RANGE; goto RET;
	}

	//
	// 1. 生成高斯核
	//
	rcode = creategausskernel(&kernel, &cw, sigma);
	if (rcode != NO_ERROR) goto RET;
	
	if (IMAGE_AREA_WIDTH(pimgsrc) < cw || IMAGE_AREA_HEIGHT(pimgsrc) < cw) {
		rcode = ERR_RANGE; goto RET;
	}

	//
	// 2. 根据不同色深分别调用不同函数
	//
	kernelex = (int *)calloc(cw, sizeof(int));
	if (NULL == kernelex) { rcode = ERR_MEM; goto RET; }
	
	for (i = 0; i < cw; i++) {
		fkernel = kernel[i]*1000.0f;
		ikernel = _float2int(fkernel);
		kernelex[i] = ikernel;
	}
	
	rcode = _makeworkimage(pimgsrc, &imgwrk0, cw);
	if (rcode != NO_ERROR) goto RET;

	rcode = _makeworkimage(pimgsrc, &imgwrk1, cw);
	if (rcode != NO_ERROR) goto RET;

	switch (IMAGE_BITCOUNT(pimgsrc)) {
	case  8: gaussblurex8bit(pimgdst, &imgwrk0, &imgwrk1, cw, kernelex); break;
	case 24: gaussblurex24bit(pimgdst, &imgwrk0, &imgwrk1, cw, kernelex); break;
	default: rcode = ERR_BITCOUNT; goto RET;
	}

RET:
	IMAGE_FreeImage(&imgwrk0);
	IMAGE_FreeImage(&imgwrk1);
	if (kernel) free(kernel);
	if (kernelex) free(kernelex);
	return rcode;
}