void asf::parameter_float_image::pup(PUP::er &p) { parameter_pixel_image::pup(p); // Allocate pixel data (if needed) if (p.isUnpacking()) data_alloc(src_alloc,0,bands(),bands()*pixel().size_x()); // Pup all pixel data (FIXME: speed up contiguous case?) ASF_FOR_PIXELS(x,y,pixels()) p(&at(x,y,0),bands()); }
/// Allow access to these pixels. void asf::parameter_float_image::pixel_setsize(const pixel_rectangle &pixel_meta,int zoom_meta) { super::pixel_setsize(pixel_meta,zoom_meta); int new_dx=bands(), new_dy=bands()*pixel().size_x(); if ((data!=0) && (new_dx==xd) && (new_dy==yd)) { /* then re-use existing buffer--it's still OK. */ } else { /* Have to allocate a new buffer */ data_alloc(src_alloc,0,new_dx,new_dy); } }
void AudioGraphSpectrum::processSpectrum(const SharedFrame&frame) { if (!isVisible()) return; mlt_audio_format format = mlt_audio_s16; int channels = frame.get_audio_channels(); int frequency = frame.get_audio_frequency(); int samples = frame.get_audio_samples(); Mlt::Frame mFrame = frame.clone(true, false, false); m_filter->process(mFrame); mFrame.get_audio( format, frequency, channels, samples ); QVector<double> bands(AUDIBLE_BAND_COUNT); float* bins = (float*)m_filter->get_data("bins"); int bin_count = m_filter->get_int("bin_count"); double bin_width = m_filter->get_double("bin_width"); int band = 0; bool firstBandFound = false; for (int bin = 0; bin < bin_count; bin++) { // Loop through all the FFT bins and align bin frequencies with // band frequencies. double F = bin_width * (double)bin; if (!firstBandFound) { // Skip bins that come before the first band. if (BAND_TAB[band + FIRST_AUDIBLE_BAND_INDEX].low > F) { continue; } else { firstBandFound = true; bands[band] = bins[bin]; } } else if (BAND_TAB[band + FIRST_AUDIBLE_BAND_INDEX].high < F) { // This bin is outside of this band - move to the next band. band++; if ((band + FIRST_AUDIBLE_BAND_INDEX) > LAST_AUDIBLE_BAND_INDEX) { // Skip bins that come after the last band. break; } bands[band] = bins[bin]; } else if (bands[band] < bins[bin] ) { // Pick the highest bin level within this band to represent the // whole band. bands[band] = bins[bin]; } } // At this point, bands contains the magnitude of the signal for each // band. Convert to dB. for (band = 0; band < bands.size(); band++) { double mag = bands[band]; double dB = mag > 0.0 ? 20 * log10( mag ) : -1000.0; bands[band] = dB; } // Update the audio signal widget QMetaObject::invokeMethod(m_graphWidget, "showAudio", Qt::QueuedConnection, Q_ARG(const QVector<double>&, bands)); }
void oms::SingleImageChain::setBandSelection(const std::vector<ossimString>& bandList, bool zeroBased) { std::vector<ossim_uint32> bands(bandList.size()); ossim_uint32 idx = 0; for(idx = 0; idx < bands.size(); ++idx) { bands[idx] = bandList[idx].toUInt32(); } setBandSelection(bands, zeroBased); }
std::vector<VImage> VImage::bandsplit( VOption *options ) { std::vector<VImage> b; for( int i = 0; i < bands(); i++ ) b.push_back( extract_band( i ) ); return( b ); }
/// Error-checking pixel access. Aborts if x,y, or band are out of bounds. asf::parameter_float_image::band_t &asf::parameter_float_image::at_careful(int x,int y,int band) const { if (!pixels().inbounds(x,y)) { char buf[1024]; sprintf(buf,"at_careful pixel access: pixel (%d,%d) is not in-bounds on a %d x %d pixel image", x,y,size_x(),size_y()); die(buf); } if (band<0) die("at_careful pixel access: Bogus negative band number"); if (band>=bands()) die("at_careful pixel access: Bogus too-big band number"); return data[x*xd+y*yd+band]; }
bool BassPlayer::registerEQ() { if (_fxEQ) unregisterEQ(); if ((_fxEQ = BASS_ChannelSetFX(chan, BASS_FX_BFX_PEAKEQ, 0))) { BASS_BFX_PEAKEQ eq; eq.fQ = 0; eq.fBandwidth = currentPresetBase(); eq.lChannel = BASS_BFX_CHANALL; QMap<float, QString> eqBands = bands(); QMap<float, QString>::Iterator band = eqBands.begin(); for(int num = 0; band != eqBands.end(); band++, num++) { eq.fGain = eqBandsGains.value(num, 0); eq.lBand = num; eq.fCenter = band.key(); BASS_FXSetParameters(_fxEQ, &eq); } } return _fxEQ != 0; }
VImage VImage::new_from_image( std::vector<double> pixel ) { VImage onepx = VImage::black( 1, 1, VImage::option()->set( "bands", bands() ) ); onepx = onepx.linear( to_vectorv( 1, 1.0 ), pixel ).cast( format() ); VImage big = onepx.embed( 0, 0, width(), height(), VImage::option()->set( "extend", VIPS_EXTEND_COPY ) ); big = big.copy( VImage::option()-> set( "interpretation", interpretation() )-> set( "xres", xres() )-> set( "yres", yres() )-> set( "xoffset", xres() )-> set( "yoffset", yres() ) ); return( big ); }
void KHistogram::statistics() { for (int i = 0; i < bands(); i++) band(i).statistics(); }
typename traits::upper<Matrix>::type inline upper(const Matrix& A) { return bands(A, 0, std::numeric_limits<long>::max()); }
typename traits::strict_upper<Matrix>::type inline triu(const Matrix& A, long d= 0) { return bands(A, d, std::numeric_limits<long>::max()); }
AveragingMSRowProvider::AveragingMSRowProvider(double nWavelengthsAveraging, const string& msPath, const MSSelection& selection, const std::map<size_t, size_t>& selectedDataDescIds, const string& dataColumnName, bool requireModel) : MSRowProvider(msPath, selection, selectedDataDescIds, dataColumnName, requireModel) { casacore::MSAntenna antennaTable(_ms.antenna()); _nAntennae = antennaTable.nrow(); casacore::ROArrayColumn<double> positionColumn(antennaTable, casacore::MSAntenna::columnName(casacore::MSAntennaEnums::POSITION)); std::vector<Pos> positions(_nAntennae); casacore::Array<double> posArr(casacore::IPosition(1, 3)); for(size_t i=0; i!=_nAntennae; ++i) { positionColumn.get(i, posArr); positions[i] = Pos(posArr.data()[0], posArr.data()[1], posArr.data()[2]); } // dataDescId x ant x ant _nElements = selectedDataDescIds.size() * _nAntennae * _nAntennae; _averagingFactors.assign(_nElements, 0.0); _buffers.resize(_nElements); MultiBandData bands(_ms.spectralWindow(), _ms.dataDescription()); double dt = (EndTime() - StartTime()) / (EndTimestep() - StartTimestep()); Logger::Debug << "Assuming integration time of " << dt * (24.0*60.0*60.0) << " seconds.\n"; size_t element = 0; size_t averagingSum = 0, minAvgFactor = std::numeric_limits<size_t>::max(), maxAvgFactor = 0; for(size_t a1=0; a1!=_nAntennae; ++a1) { Pos pos1 = positions[a1]; for(size_t a2=0; a2!=_nAntennae; ++a2) { Pos pos2 = positions[a2]; double dx = std::get<0>(pos1) - std::get<0>(pos2); double dy = std::get<1>(pos1) - std::get<1>(pos2); double dz = std::get<2>(pos1) - std::get<2>(pos2); double dist = sqrt(dx*dx + dy*dy + dz*dz); for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin(); spwIter!=selectedDataDescIds.end(); ++spwIter) { BandData band = bands[spwIter->first]; double lambda = band.SmallestWavelength(); double nWavelengthsPerIntegration = 2.0 * M_PI * dist / lambda * dt; _averagingFactors[element] = std::max<size_t>(size_t(floor(nWavelengthsAveraging / nWavelengthsPerIntegration)), 1); averagingSum += _averagingFactors[element]; if(a1 != a2) { minAvgFactor = std::min<size_t>(minAvgFactor, _averagingFactors[element]); maxAvgFactor = std::max<size_t>(maxAvgFactor, _averagingFactors[element]); } //Logger::Debug << a1 << '\t' << a2 << '\t' << _averagingFactors[element] << '\n'; ++element; } } } Logger::Info << "Averaging factor for longest baseline: " << minAvgFactor << " x . For the shortest: " << maxAvgFactor << " x \n"; _spwIndexToDataDescId.resize(selectedDataDescIds.size()); for(std::map<size_t, size_t>::const_iterator spwIter=selectedDataDescIds.begin(); spwIter!=selectedDataDescIds.end(); ++spwIter) { _spwIndexToDataDescId[spwIter->second] = spwIter->first; } _averageFactorSum = 0.0; _rowCount = 0; _averagedRowCount = 0; _currentData = DataArray(DataShape()); _currentModel = DataArray(DataShape()); _currentFlags = FlagArray(DataShape()); _currentWeights = WeightArray(DataShape()); _averagedDataDescId = _currentDataDescId; _flushPosition = 0; if(!MSRowProvider::AtEnd()) { bool timestepAvailable = processCurrentTimestep(); if(!timestepAvailable) NextRow(); } }
void asf::parameter_float_image::set(float toValue) { for (int b=0;b<bands();b++) { ASF_FOR_PIXELS(x,y,pixels()) at(x,y,b)=toValue; } }
rspfRefPtr<rspfImageData> rspfSFIMFusion::getTile(const rspfIrect& rect, rspf_uint32 resLevel) { if(!theInputConnection) { return rspfRefPtr<rspfImageData>(); } if (!theIntensityConnection) { return theInputConnection->getTile(rect, resLevel); } if(!theNormLowPassTile.valid()) { theNormLowPassTile = new rspfImageData(this, RSPF_NORMALIZED_FLOAT, 1, rect.width(), rect.height()); theNormHighPassTile = new rspfImageData(this, RSPF_NORMALIZED_FLOAT, 1, rect.width(), rect.height()); theNormLowPassTile->initialize(); theNormHighPassTile->initialize(); theNormLowPassTile->makeBlank(); theNormHighPassTile->makeBlank(); } theNormLowPassTile->setImageRectangle(rect); theNormHighPassTile->setImageRectangle(rect); theNormLowPassTile->makeBlank(); theNormHighPassTile->makeBlank(); if(!theLowPassFilter->getInput() && getInput()) { initialize(); } rspfRefPtr<rspfImageData> lowTile = theLowPassFilter->getTile(rect, resLevel); rspfRefPtr<rspfImageData> highTile = theHighPassFilter->getTile(rect, resLevel); // rspfRefPtr<rspfImageData> highTile = getNormIntensity(rect, resLevel); // if we don't have valid low and high pass then return the input color tile // in its original format // if(!lowTile.valid()||!highTile.valid()) { // return theInputConnection->getTile(rect, resLevel); return 0; } if((lowTile->getDataObjectStatus() == RSPF_EMPTY)|| (!lowTile->getBuf()) || (highTile->getDataObjectStatus() == RSPF_EMPTY)|| (!highTile->getBuf())) { // return theInputConnection->getTile(rect, resLevel); return 0; } rspfRefPtr<rspfImageData> normColorData = getNormTile(rect, resLevel); rspf_uint32 y = 0; rspf_uint32 x = 0; rspf_uint32 w = theTile->getWidth(); rspf_uint32 h = theTile->getHeight(); theTile->makeBlank(); theTile->setImageRectangle(rect); if(!normColorData.valid()) { return 0; // return theTile; } if((normColorData->getDataObjectStatus() == RSPF_EMPTY)|| !normColorData->getBuf()) { return theTile; } rspfRefPtr<rspfImageData> normColorOutputData = (rspfImageData*)normColorData->dup(); normColorOutputData->setImageRectangle(rect); normColorOutputData->loadTile(normColorData.get()); // rspf_float64 slopeResult = 0.0; rspf_uint32 idx = 0; std::vector<rspf_float32*> bands(normColorData->getNumberOfBands()); lowTile->copyTileToNormalizedBuffer((rspf_float32*)theNormLowPassTile->getBuf()); highTile->copyTileToNormalizedBuffer((rspf_float32*)theNormHighPassTile->getBuf()); theNormLowPassTile->validate(); theNormHighPassTile->validate(); rspfRefPtr<rspfImageData> lowPan = (rspfImageData*)theNormLowPassTile->dup(); lowPan->setImageRectangle(rect); lowPan->loadTile(theNormLowPassTile.get()); rspfRefPtr<rspfImageData> highPan = (rspfImageData*)theNormHighPassTile->dup(); highPan->setImageRectangle(rect); highPan->loadTile(theNormHighPassTile.get()); rspf_float32* panHigh = (rspf_float32*)highPan->getBuf(); rspf_float32* panLow = (rspf_float32*)lowPan->getBuf(); for(idx = 0; idx < bands.size(); ++idx) { bands[idx] = (rspf_float32*)normColorOutputData->getBuf(idx); } // double delta = 0.0; rspf_uint32 bandsSize = (rspf_uint32)bands.size(); double normMinPix = 0.0; for(y = 0; y < h; ++y) { for(x = 0; x < w; ++x) { for(idx = 0; idx < bandsSize; ++idx) { if((*bands[idx] != 0.0)&& (*panLow > FLT_EPSILON) ) // if band is not null and not divide by 0 { normMinPix = (rspf_float32)normColorOutputData->getMinPix(idx); *bands[idx] = ((*bands[idx])*(*panHigh))/ (*panLow); if(*bands[idx] > 1.0) *bands[idx] = 1.0; if(*bands[idx] < normMinPix) *bands[idx] = normMinPix; } // let's comment out the nulling and we will instead just pass the color on // // else // { // *bands[idx] = 0.0; // } ++bands[idx]; } ++panHigh; ++panLow; } } theTile->copyNormalizedBufferToTile((rspf_float32*)normColorOutputData->getBuf()); theTile->validate(); return theTile; }