void ChangeResolutionAction::IncreaseFrequency(TimeFrequencyData &originalData, const TimeFrequencyData &changedData, bool restoreImage, bool restoreMask) { if(restoreImage) { size_t imageCount = originalData.ImageCount(); if(imageCount != changedData.ImageCount()) throw std::runtime_error("When restoring resolution in change resolution action, original data and changed data do not have the same number of images"); for(size_t i=0;i<imageCount;++i) { Image2DCPtr image = changedData.GetImage(i); Image2DPtr newImage(new Image2D(image->EnlargeVertically(_frequencyDecreaseFactor, originalData.ImageHeight()))); originalData.SetImage(i, newImage); } } if(restoreMask) { originalData.SetMask(changedData); size_t maskCount = originalData.MaskCount(); for(size_t i=0;i<maskCount;++i) { Mask2DCPtr mask = changedData.GetMask(i); Mask2DPtr newMask = Mask2D::CreateUnsetMaskPtr(originalData.ImageWidth(), originalData.ImageHeight()); newMask->EnlargeVerticallyAndSet(*mask, _frequencyDecreaseFactor); originalData.SetMask(i, newMask); } } }
void ChangeResolutionAction::DecreaseFrequency(TimeFrequencyData &timeFrequencyData) { size_t imageCount = timeFrequencyData.ImageCount(); for(size_t i=0;i<imageCount;++i) { Image2DCPtr image = timeFrequencyData.GetImage(i); Image2DPtr newImage = image->ShrinkVertically(_frequencyDecreaseFactor); timeFrequencyData.SetImage(i, newImage); } size_t maskCount = timeFrequencyData.MaskCount(); for(size_t i=0;i<maskCount;++i) { Mask2DCPtr mask = timeFrequencyData.GetMask(i); Mask2DPtr newMask = mask->ShrinkVertically(_frequencyDecreaseFactor); timeFrequencyData.SetMask(i, newMask); } }
void ChangeResolutionAction::DecreaseTimeWithMask(TimeFrequencyData &data) { size_t polCount = data.PolarisationCount(); for(size_t i=0;i<polCount;++i) { TimeFrequencyData *polData = data.CreateTFDataFromPolarisationIndex(i); Mask2DCPtr mask = polData->GetSingleMask(); for(unsigned j=0;j<polData->ImageCount();++j) { Image2DCPtr image = polData->GetImage(j); polData->SetImage(j, ThresholdTools::ShrinkHorizontally(_timeDecreaseFactor, image, mask)); } delete polData; } size_t maskCount = data.MaskCount(); for(size_t i=0;i<maskCount;++i) { Mask2DCPtr mask = data.GetMask(i); Mask2DPtr newMask = mask->ShrinkHorizontallyForAveraging(_timeDecreaseFactor); data.SetMask(i, newMask); } }
void ChangeResolutionAction::DecreaseTime(TimeFrequencyData &timeFrequencyData) { if(_useMaskInAveraging) { DecreaseTimeWithMask(timeFrequencyData); } else { size_t imageCount = timeFrequencyData.ImageCount(); for(size_t i=0;i<imageCount;++i) { Image2DCPtr image = timeFrequencyData.GetImage(i); Image2DPtr newImage(new Image2D(image->ShrinkHorizontally(_timeDecreaseFactor))); timeFrequencyData.SetImage(i, std::move(newImage)); } size_t maskCount = timeFrequencyData.MaskCount(); for(size_t i=0;i<maskCount;++i) { Mask2DCPtr mask = timeFrequencyData.GetMask(i); Mask2DPtr newMask(new Mask2D(mask->ShrinkHorizontally(_timeDecreaseFactor))); timeFrequencyData.SetMask(i, std::move(newMask)); } } }
void CalibratePassbandAction::calibrate(TimeFrequencyData& data) const { const size_t height = data.ImageHeight(); std::vector<num_t> stddev(_steps); for(size_t step=0; step!=_steps; ++step) { const size_t startY = step*height/_steps, endY = (step+1)*height/_steps; std::vector<num_t> dataVector((1+endY-startY) * data.ImageWidth() * data.ImageCount()); std::vector<num_t>::iterator vecIter = dataVector.begin(); const Mask2DCPtr maskPtr = data.GetSingleMask(); const Mask2D &mask = *maskPtr; for(size_t i=0; i!=data.ImageCount(); ++i) { const Image2D &image = *data.GetImage(i); for(size_t y=startY; y!=endY; ++y) { const num_t *inputPtr = image.ValuePtr(0, y); const bool *maskPtr = mask.ValuePtr(0, y); for(size_t x=0; x!=image.Width(); ++x) { if(!*maskPtr && std::isfinite(*inputPtr)) { *vecIter = *inputPtr; ++vecIter; } ++inputPtr; ++maskPtr; } } } dataVector.resize(vecIter - dataVector.begin()); num_t mean; ThresholdTools::WinsorizedMeanAndStdDev<num_t>(dataVector, mean, stddev[step]); } for(size_t i=0; i!=data.ImageCount(); ++i) { const Image2D &image = *data.GetImage(i); Image2D *destImage = Image2D::CreateUnsetImage(image.Width(), image.Height()); for(size_t step=0; step!=_steps; ++step) { const size_t startY = step*height/_steps, endY = (step+1)*height/_steps; float correctionFactor; if(stddev[step] == 0.0) correctionFactor = 0.0; else correctionFactor = 1.0 / stddev[step]; const __m128 corrFact4 = _mm_set_ps(correctionFactor, correctionFactor, correctionFactor, correctionFactor); for(size_t y=startY; y!=endY; ++y) { const float *inputPtr = image.ValuePtr(0, y); float *destPtr = destImage->ValuePtr(0, y); for(size_t x=0;x<image.Width();x+=4) { _mm_store_ps(destPtr, _mm_mul_ps(corrFact4, _mm_load_ps(inputPtr))); inputPtr += 4; destPtr += 4; } } } data.SetImage(i, Image2DPtr(destImage)); } }
void SpatialCompositionAction::Perform(ArtifactSet &artifacts, ProgressListener &progress) { size_t imageCount = artifacts.ContaminatedData().ImageCount(); std::vector<Image2DPtr> images(imageCount); for(size_t p=0;p<imageCount;++p) images[p] = Image2D::CreateZeroImagePtr(artifacts.ContaminatedData().ImageWidth(), artifacts.ContaminatedData().ImageHeight()); std::string filename = artifacts.ImageSet()->File(); SpatialMSImageSet set(filename); ImageSetIndex *index = set.StartIndex(); size_t progressStep = 0, totalProgress = artifacts.ContaminatedData().ImageWidth() * artifacts.ContaminatedData().ImageHeight()/256; while(index->IsValid()) { TimeFrequencyData *data = set.LoadData(*index); SpatialMatrixMetaData metaData(set.SpatialMetaData(*index)); for(size_t p=0;p!=imageCount;++p) { switch(_operation) { case SumCrossCorrelationsOperation: images[p]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), sumCrossCorrelations(data->GetImage(p))); break; case SumAutoCorrelationsOperation: images[p]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), sumAutoCorrelations(data->GetImage(p))); break; case EigenvalueDecompositionOperation: { num_t value = eigenvalue(data->GetImage(p), data->GetImage(p+1)); images[p]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), value); images[p+1]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), 0.0); ++p; } break; case EigenvalueRemovalOperation: { std::pair<num_t, num_t> value = removeEigenvalue(data->GetImage(p), data->GetImage(p+1)); images[p]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), value.first); images[p+1]->SetValue(metaData.TimeIndex(), metaData.ChannelIndex(), value.second); ++p; } break; } } delete data; index->Next(); ++progressStep; progress.OnProgress(*this, progressStep/256, totalProgress); } delete index; TimeFrequencyData newRevisedData = artifacts.RevisedData(); for(size_t p=0;p<imageCount;++p) newRevisedData.SetImage(p, images[p]); newRevisedData.SetMask(artifacts.RevisedData()); TimeFrequencyData *contaminatedData = TimeFrequencyData::CreateTFDataFromDiff(artifacts.ContaminatedData(), newRevisedData); contaminatedData->SetMask(artifacts.ContaminatedData()); artifacts.SetRevisedData(newRevisedData); artifacts.SetContaminatedData(*contaminatedData); delete contaminatedData; }