// run the initilized retina filter in order to perform gray image tone mapping, after this call all retina outputs are updated void _runGrayToneMapping(const std::valarray<float> &grayImageInput, std::valarray<float> &grayImageOutput) { // apply tone mapping on the multiplexed image // -> photoreceptors local adaptation (large area adaptation) _multiuseFilter->runFilter_LPfilter(grayImageInput, grayImageOutput, 0); // compute low pass filtering modeling the horizontal cells filtering to acess local luminance _multiuseFilter->setV0CompressionParameterToneMapping(1.f, grayImageOutput.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels()); _multiuseFilter->runFilter_LocalAdapdation(grayImageInput, grayImageOutput, _temp2); // adapt contrast to local luminance // -> ganglion cells local adaptation (short area adaptation) _multiuseFilter->runFilter_LPfilter(_temp2, grayImageOutput, 1); // compute low pass filtering (high cut frequency (remove spatio-temporal noise) _multiuseFilter->setV0CompressionParameterToneMapping(1.f, _temp2.max(), _meanLuminanceModulatorK*grayImageOutput.sum()/(float)_multiuseFilter->getNBpixels()); _multiuseFilter->runFilter_LocalAdapdation(_temp2, grayImageOutput, grayImageOutput); // adapt contrast to local luminance }
int find_histogram(const std::valarray<T>& vol, std::valarray<int>& hist, unsigned int bins, T& min, T& max) { // size and zero the histogram hist.resize(bins); hist = 0; if(min == max) { min = vol.min(); max = vol.max(); } int validsize(-1); if(min != max) { double fA = bins / double(max - min); double fB = (bins * -min) / double(max - min); validsize = 0; for(unsigned int i = 0; i < vol.size(); ++i) { unsigned int idx = unsigned(fA * vol[i] + fB); ++hist[ std::max(unsigned(0), std::min(idx, bins - 1)) ]; ++validsize; } } return validsize; }
void histogram_plot::Plot(const std::valarray<double>& data) { { QWriteLocker locker(&data_lock); if (intervals.size() != (int)(data.size())) { intervals.resize(data.size()); values.resize(data.size()); for (int i = 0; i < intervals.size(); i++ ) intervals[i] = QwtDoubleInterval(i, i + 1); } double nTotal = 0; for (size_t i = 0; i < data.size(); i++ ) nTotal += data[i]; for (size_t i = 0; i < data.size(); i++ ) values[i] = data[i] / nTotal; double max_val = data.max() / nTotal; IncludeY(max_val); } replot(); }
void histogram_plot::barPlot(const std::valarray<double>& data) { if (data.size() == 0) return; { QWriteLocker locker(&data_lock); if (intervals.size() != (int)(data.size())) { intervals.resize(data.size()); values.resize(data.size()); for (int i = 0; i < intervals.size(); i++ ) intervals[i] = QwtDoubleInterval(i, i + 1); } for (size_t i = 0; i < data.size(); i++ ) values[i] = data[i]; double max_val = data.max(); double min_val = data.min(); if (max_val > 0) max_val *= 2; else max_val = 0; if (min_val < 0) min_val *= 2; else min_val = 0; SetYRange(min_val, max_val); } replot(); }
void find_thresholds(const std::valarray<T>& vol, std::valarray<int>& hist, unsigned int bins, T& minval, T& maxval) { const unsigned int max_passes(10); unsigned int pass(1); unsigned int lowest_bin(0), highest_bin(bins-1), bottom_bin(0), top_bin(0); T min(vol.min()), max(vol.max()); T thresh2(0), thresh98(0); while((pass == 1) || (double(thresh98 - thresh2) < (double(max - min) / 10))) { if(pass > 1) { // increase range slightly from the 2-98% range found bottom_bin = std::max(int(bottom_bin) - 1, 0); top_bin = std::min(int(top_bin) + 1, int(bins) - 1); double fA = ((max - min) / double(bins)); T tmpmin = min + ( bottom_bin * fA); max = min + ((top_bin+1) * fA); min = tmpmin; } if(pass == max_passes) { min = max = max_passes; } // give up and revert to full range ... int validsize = find_histogram(vol, hist, bins, min, max); if(validsize < 1) { minval = thresh2 = min; maxval = thresh98 = max; return; } if(pass == max_passes) { // ... _but_ ignore end bins validsize -= hist[lowest_bin] + hist[highest_bin]; ++lowest_bin; --highest_bin; } if (validsize < 0) { // ie zero range thresh2=thresh98=min; break; } double fA = ((max-min)/double(bins)); int count; for(count=0, bottom_bin=lowest_bin; count<validsize/50; ++bottom_bin) count += hist[bottom_bin]; --bottom_bin; thresh2 = min + (bottom_bin*fA); for(count=0, top_bin=highest_bin; count<validsize/50; --top_bin) count += hist[top_bin]; ++top_bin; thresh98 = min + ((top_bin+1)*fA); if (pass==max_passes) break; ++pass; } find_histogram(vol, hist, bins, thresh2, thresh98); minval = thresh2; maxval = thresh98; }
T norm1(const std::valarray<T> &v){ return v.max(); }