コード例 #1
0
ファイル: tests.c プロジェクト: smdarry/rdefaut2010
void testNormalizeHistogram()
{
    printf("\nTEST NORMALIZE HISTOGRAM\n");

    Histogram h1;
    initHistogram(&h1, 5, 3);
    h1.freq[0][0] = 12;
    h1.freq[1][0] = 15;
    h1.freq[2][0] = 20;
    h1.freq[3][0] = 45;
    h1.freq[4][0] = 19;

    h1.freq[0][1] = 5;
    h1.freq[1][1] = 7;
    h1.freq[2][1] = 16;
    h1.freq[3][1] = 6;
    h1.freq[4][1] = 4;

    normalizeHistogram(&h1);
    printf("Expected: 0.11, Actual: %.2f\n", h1.freq[0][0]);
    printf("Expected: 0.14, Actual: %.2f\n", h1.freq[1][0]);
    printf("Expected: 0.18, Actual: %.2f\n", h1.freq[2][0]);
    printf("Expected: 0.41, Actual: %.2f\n", h1.freq[3][0]);
    printf("Expected: 0.17, Actual: %.2f\n", h1.freq[4][0]);

    printf("Expected: 0.13, Actual: %.2f\n", h1.freq[0][1]);
    printf("Expected: 0.18, Actual: %.2f\n", h1.freq[1][1]);
    printf("Expected: 0.42, Actual: %.2f\n", h1.freq[2][1]);
    printf("Expected: 0.16, Actual: %.2f\n", h1.freq[3][1]);
    printf("Expected: 0.11, Actual: %.2f\n", h1.freq[4][1]);
}
コード例 #2
0
ファイル: qgsrasterinterface.cpp プロジェクト: Aladar64/QGIS
bool QgsRasterInterface::hasHistogram( int theBandNo,
                                       int theBinCount,
                                       double theMinimum, double theMaximum,
                                       const QgsRectangle & theExtent,
                                       int theSampleSize,
                                       bool theIncludeOutOfRange )
{
  QgsDebugMsg( QString( "theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );
  // histogramDefaults() needs statistics if theMinimum or theMaximum is NaN ->
  // do other checks which don't need statistics before histogramDefaults()
  if ( mHistograms.size() == 0 ) return false;

  QgsRasterHistogram myHistogram;
  initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );

  foreach ( QgsRasterHistogram histogram, mHistograms )
  {
    if ( histogram == myHistogram )
    {
      QgsDebugMsg( "Has cached histogram." );
      return true;
    }
  }
  return false;
}
コード例 #3
0
bool QgsRasterInterface::hasHistogram( int bandNo,
                                       int binCount,
                                       double minimum, double maximum,
                                       const QgsRectangle &extent,
                                       int sampleSize,
                                       bool includeOutOfRange )
{
  QgsDebugMsgLevel( QString( "theBandNo = %1 binCount = %2 minimum = %3 maximum = %4 sampleSize = %5" ).arg( bandNo ).arg( binCount ).arg( minimum ).arg( maximum ).arg( sampleSize ), 4 );
  // histogramDefaults() needs statistics if minimum or maximum is NaN ->
  // do other checks which don't need statistics before histogramDefaults()
  if ( mHistograms.isEmpty() ) return false;

  QgsRasterHistogram myHistogram;
  initHistogram( myHistogram, bandNo, binCount, minimum, maximum, extent, sampleSize, includeOutOfRange );

  Q_FOREACH ( const QgsRasterHistogram &histogram, mHistograms )
  {
    if ( histogram == myHistogram )
    {
      QgsDebugMsgLevel( "Has cached histogram.", 4 );
      return true;
    }
  }
  return false;
}
コード例 #4
0
ファイル: trigger_central.cpp プロジェクト: jmt42/rusefi
void initTriggerCentral(Engine *engine) {
	strcpy((char*) shaft_signal_msg_index, "x_");

#if EFI_WAVE_CHART
	initWaveChart(&waveChart);
#endif /* EFI_WAVE_CHART */

#if EFI_PROD_CODE || EFI_SIMULATOR
	initLogging(&logger, "ShaftPosition");
	addConsoleActionP("triggerinfo", (VoidPtr) triggerInfo, engine);
	addConsoleActionP("triggershapeinfo", (VoidPtr) triggerShapeInfo, engine);
#endif

#if EFI_HISTOGRAMS
	initHistogram(&triggerCallback, "all callbacks");
#endif /* EFI_HISTOGRAMS */
}
コード例 #5
0
ファイル: trigger_central.cpp プロジェクト: Vijay1190/rusefi
void initTriggerCentral(Logging *sharedLogger, Engine *engine) {
	logger = sharedLogger;
	strcpy((char*) shaft_signal_msg_index, "x_");

#if EFI_WAVE_CHART
	initWaveChart(&waveChart);
#endif /* EFI_WAVE_CHART */

#if EFI_PROD_CODE || EFI_SIMULATOR
	addConsoleActionP("triggerinfo", (VoidPtr) triggerInfo, engine);
	addConsoleActionP("trigger_shape_info", (VoidPtr) triggerShapeInfo, engine);
	addConsoleAction("reset_trigger", resetRunningTriggerCounters);
#endif

#if EFI_HISTOGRAMS
	initHistogram(&triggerCallback, "all callbacks");
#endif /* EFI_HISTOGRAMS */
}
コード例 #6
0
ファイル: test_util.cpp プロジェクト: rusefi/rusefi
TEST(util, histogram) {
	print("******************************************* testHistogram\r\n");

	initHistogramsModule();

	ASSERT_EQ(80, histogramGetIndex(239));
	ASSERT_EQ(223, histogramGetIndex(239239));
	ASSERT_EQ(364, histogramGetIndex(239239239));

	histogram_s h;

	initHistogram(&h, "test");

	int result[5];
	ASSERT_EQ(0, hsReport(&h, result));

	hsAdd(&h, 10);
	ASSERT_EQ(1, hsReport(&h, result));
	ASSERT_EQ(10, result[0]);

	// let's add same value one more time
	hsAdd(&h, 10);
	ASSERT_EQ(2, hsReport(&h, result));
	ASSERT_EQ(10, result[0]);
	ASSERT_EQ(10, result[1]);

	hsAdd(&h, 10);
	hsAdd(&h, 10);
	hsAdd(&h, 10);

	hsAdd(&h, 1000);
	hsAdd(&h, 100);

	ASSERT_EQ(5, hsReport(&h, result));

	ASSERT_EQ(5, result[0]);
	ASSERT_EQ(10, result[1]);
	ASSERT_EQ(10, result[2]);
	ASSERT_EQ(100, result[3]);
	// values are not expected to be exactly the same, it's the shape what matters
	ASSERT_EQ(1011, result[4]);
}
コード例 #7
0
ファイル: engine_sniffer.cpp プロジェクト: rusefi/rusefi
void initWaveChart(WaveChart *chart) {
	/**
	 * constructor does not work because we need specific initialization order
	 */
	chart->init();

	printStatus();

#if DEBUG_WAVE
	initLoggingExt(&debugLogging, "wave chart debug", &debugLogging.DEFAULT_BUFFER, sizeof(debugLogging.DEFAULT_BUFFER));
#endif

#if EFI_HISTOGRAMS
	initHistogram(&engineSnifferHisto, "wave chart");
#endif /* EFI_HISTOGRAMS */

	addConsoleActionI("chartsize", setChartSize);
	addConsoleActionI("chart", setChartActive);
#if ! EFI_UNIT_TEST
	addConsoleAction("reset_engine_chart", resetNow);
#endif
}
コード例 #8
0
ファイル: LBP.cpp プロジェクト: Canas/lbp_gender_classifier
std::vector<std::vector<int> > getFeatures(std::vector<cv::Mat> imLBP){
	int m = imLBP[0].rows / 2;
	int n = imLBP[0].cols / 2;

	std::vector<int> bins = initHistogram();
	std::vector<std::vector<int> > features;

	for (unsigned int k = 0; k < imLBP.size(); k++){
		cv::Mat quad1(m, n, CV_8U);
		cv::Mat quad2(m, n, CV_8U);
		cv::Mat quad3(m, n, CV_8U);
		cv::Mat quad4(m, n, CV_8U);

		for (int i = 0; i < m; i++){
			for (int j = 0; j < n; j++){
				quad1.at<uchar>(i, j) = imLBP[k].at<uchar>(i, j);
				quad2.at<uchar>(i, j) = imLBP[k].at<uchar>(i, j+n);
				quad3.at<uchar>(i, j) = imLBP[k].at<uchar>(i+m, j);
				quad4.at<uchar>(i, j) = imLBP[k].at<uchar>(i+m, j+n);
			}
		}

		std::vector<int> histLBP_1 = histLBP(quad1, bins);
		std::vector<int> histLBP_2 = histLBP(quad2, bins);
		std::vector<int> histLBP_3 = histLBP(quad3, bins);
		std::vector<int> histLBP_4 = histLBP(quad3, bins);

		std::vector<int> feature;
		feature.reserve(histLBP_1.size() + histLBP_2.size() + histLBP_3.size() + histLBP_4.size());
		feature.insert(feature.end(), histLBP_1.begin(), histLBP_1.end());
		feature.insert(feature.end(), histLBP_2.begin(), histLBP_2.end());
		feature.insert(feature.end(), histLBP_3.begin(), histLBP_3.end());
		feature.insert(feature.end(), histLBP_4.begin(), histLBP_4.end());

		features.push_back(feature);
	}

	return features;
}
コード例 #9
0
ファイル: wave_chart.c プロジェクト: rus084/rusefi
void initWaveChart(WaveChart *chart) {
	initLogging(&logger, "wave info");

	if (!isChartActive) {
		printMsg(&logger, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! chart disabled");
	}

	printStatus();

	initLoggingExt(&chart->logging, "wave chart", WAVE_LOGGING_BUFFER, sizeof(WAVE_LOGGING_BUFFER));
	chart->isInitialized = TRUE;
#if DEBUG_WAVE
	initLoggingExt(&debugLogging, "wave chart debug", &debugLogging.DEFAULT_BUFFER, sizeof(debugLogging.DEFAULT_BUFFER));
#endif

#if EFI_HISTOGRAMS
	initHistogram(&waveChartHisto, "wave chart");
#endif /* EFI_HISTOGRAMS */

	resetWaveChart(chart);
	addConsoleActionI("chartsize", setChartSize);
	addConsoleActionI("chart", setChartActive);
}
コード例 #10
0
::kj::Promise<void> BackendServer::getCoinDetails(Backend::Server::GetCoinDetailsContext context)
{
    auto results = context.getResults().initDetails();
    results.setIconUrl("https://followmyvote.com/wp-content/uploads"
                                                  "/2014/02/Follow-My-Vote-Logo.png");
    results.setActiveContestCount(15);

    auto historyLength = context.getParams().getVolumeHistoryLength();
    if (historyLength <= 0)
        results.getVolumeHistory().setNoHistory();
    else {
        auto history = results.getVolumeHistory().initHistory();
        // Get current time, rewound to the most recent hour
        history.setHistoryEndTimestamp(
                    std::chrono::duration_cast<std::chrono::milliseconds>(
                        std::chrono::system_clock::now().time_since_epoch()
                    ).count() / (1000 * 60 * 60) * (1000 * 60 * 60));
        // TODO: test that this logic for getting the timestamp is correct
        auto histogram = history.initHistogram(historyLength);
        for (int i = 0; i < historyLength; ++i)
            histogram.set(i, 1000000);
    }
    return kj::READY_NOW;
}
コード例 #11
0
ファイル: drawer.c プロジェクト: thejaylee/MouseTrace
void drawHistogram(HWND hwnd, long *values, int nValues, int maxval) {
	HDC hdc;
	RECT bounds;
	HBRUSH brush;
	HPEN pen;
	int w,h;
	int bars;
	float barw;
	long histidx;
	unsigned short histmax;
	//unsigned short phist[HIST_BARS], nhist[HIST_BARS];
	unsigned short *phist = NULL,
						*nhist = NULL;
	int c;

	if (hdcHist == NULL) initHistogram(hwnd);

	if (maxval < MAX_BARS)
		bars = maxval;
	else
		bars = MAX_BARS;

	phist = malloc(sizeof(short) * bars);
	nhist = malloc(sizeof(short) * bars);

	if ((phist == NULL) || (nhist == NULL))
		return;

	/* compute histogram data */
	memset(phist, 0, sizeof(short) * bars);
	memset(nhist, 0, sizeof(short) * bars);
	for (c=0; c<nValues; c++) {
		histidx = (long)(((float)abs(values[c]) / maxval) * (bars - 0.001f));
		if (values[c] > 0)
			phist[histidx]++;
		else if (values[c] < 0)
			nhist[histidx]++;
	}
	//find scale
	histmax = 0;
	for (c=0; c<bars; c++) {
		if (phist[c] > histmax) histmax = phist[c];
		if (nhist[c] > histmax) histmax = nhist[c];
	}

	/* get attributes */
	GetClientRect(hwnd, &bounds);
	w = bounds.right - bounds.left;
	h = bounds.bottom - bounds.top;
	barw = (float) w / bars;

	/* fill with black */
	brush = CreateSolidBrush(RGB(0,0,0));
	FillRect(hdcHist, &bounds, brush);
	DeleteBrush(brush);
	GdiFlush();

	/* draw histogram */
	//positive values
	brush = CreateSolidBrush(RGB(0,255,0));
	pen = CreatePen(PS_SOLID, 1, RGB(0,255,0));
	SelectBrush(hdcHist, brush);
	SelectPen(hdcHist, pen);
	for (c=0; c<bars; c++) {
		Rectangle(hdcHist,
					 bounds.left + (int)(c * barw),
					 bounds.top + h/2 - (int)(((float)phist[c] / histmax) * (h / 2.0f)),
					 bounds.left + (int)((c + 1) * barw),
					 bounds.bottom - h/2);
	}
	DeleteBrush(brush);
	DeletePen(pen);
	GdiFlush();

	//negative values
	brush = CreateSolidBrush(RGB(255,0,0));
	pen = CreatePen(PS_SOLID, 1, RGB(255,0,0));
	SelectBrush(hdcHist, brush);
	SelectPen(hdcHist, pen);
	for (c=0; c<bars; c++) {
		Rectangle(hdcHist,
					 bounds.left + (int)(c * barw),
					 bounds.top + h/2,
					 bounds.left + (int)((c + 1) * barw),
					 bounds.top + h/2 + (int)(((float)nhist[c] / histmax) * (h / 2.0f)));
	}
	DeleteBrush(brush);
	DeletePen(pen);
	GdiFlush();

	/* draw a line through zero */
	pen = CreatePen(PS_SOLID, 1, RGB(0,255,255));
	SelectPen(hdcHist, pen);
	MoveToEx(hdcHist, 0, h/2, (LPPOINT) NULL);
	LineTo(hdcHist, w, h/2);
	DeletePen(pen);
	GdiFlush();

	/* swap the buffer */
	hdc = GetDC(hwnd);
	BitBlt(hdc, 0, 0, w, h, hdcHist, 0, 0, SRCCOPY);
	GdiFlush();
	ReleaseDC(hwnd, hdc);

	free(phist);
	free(nhist);
}
コード例 #12
0
ファイル: qgsrasterinterface.cpp プロジェクト: Aladar64/QGIS
QgsRasterHistogram QgsRasterInterface::histogram( int theBandNo,
    int theBinCount,
    double theMinimum, double theMaximum,
    const QgsRectangle & theExtent,
    int theSampleSize,
    bool theIncludeOutOfRange )
{
  QgsDebugMsg( QString( "theBandNo = %1 theBinCount = %2 theMinimum = %3 theMaximum = %4 theSampleSize = %5" ).arg( theBandNo ).arg( theBinCount ).arg( theMinimum ).arg( theMaximum ).arg( theSampleSize ) );

  QgsRasterHistogram myHistogram;
  initHistogram( myHistogram, theBandNo, theBinCount, theMinimum, theMaximum, theExtent, theSampleSize, theIncludeOutOfRange );

  // Find cached
  foreach ( QgsRasterHistogram histogram, mHistograms )
  {
    if ( histogram == myHistogram )
    {
      QgsDebugMsg( "Using cached histogram." );
      return histogram;
    }
  }

  int myBinCount = myHistogram.binCount;
  int myWidth = myHistogram.width;
  int myHeight = myHistogram.height;
  QgsRectangle myExtent = myHistogram.extent;
  myHistogram.histogramVector.resize( myBinCount );

  int myXBlockSize = xBlockSize();
  int myYBlockSize = yBlockSize();
  if ( myXBlockSize == 0 ) // should not happen, but happens
  {
    myXBlockSize = 500;
  }
  if ( myYBlockSize == 0 ) // should not happen, but happens
  {
    myYBlockSize = 500;
  }

  int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
  int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;

  double myXRes = myExtent.width() / myWidth;
  double myYRes = myExtent.height() / myHeight;

  double myMinimum = myHistogram.minimum;
  double myMaximum = myHistogram.maximum;

  // To avoid rounding errors
  // TODO: check this
  double myerval = ( myMaximum - myMinimum ) / myHistogram.binCount;
  myMinimum -= 0.1 * myerval;
  myMaximum += 0.1 * myerval;

  QgsDebugMsg( QString( "binCount = %1 myMinimum = %2 myMaximum = %3" ).arg( myHistogram.binCount ).arg( myMinimum ).arg( myMaximum ) );

  double myBinSize = ( myMaximum - myMinimum ) / myBinCount;

  // TODO: progress signals
  for ( int myYBlock = 0; myYBlock < myNYBlocks; myYBlock++ )
  {
    for ( int myXBlock = 0; myXBlock < myNXBlocks; myXBlock++ )
    {
      int myBlockWidth = qMin( myXBlockSize, myWidth - myXBlock * myXBlockSize );
      int myBlockHeight = qMin( myYBlockSize, myHeight - myYBlock * myYBlockSize );

      double xmin = myExtent.xMinimum() + myXBlock * myXBlockSize * myXRes;
      double xmax = xmin + myBlockWidth * myXRes;
      double ymin = myExtent.yMaximum() - myYBlock * myYBlockSize * myYRes;
      double ymax = ymin - myBlockHeight * myYRes;

      QgsRectangle myPartExtent( xmin, ymin, xmax, ymax );

      QgsRasterBlock* blk = block( theBandNo, myPartExtent, myBlockWidth, myBlockHeight );

      // Collect the histogram counts.
      for ( qgssize i = 0; i < (( qgssize ) myBlockHeight ) * myBlockWidth; i++ )
      {
        if ( blk->isNoData( i ) )
        {
          continue; // NULL
        }
        double myValue = blk->value( i );

        int myBinIndex = static_cast <int>( qFloor(( myValue - myMinimum ) /  myBinSize ) ) ;

        if (( myBinIndex < 0 || myBinIndex > ( myBinCount - 1 ) ) && !theIncludeOutOfRange )
        {
          continue;
        }
        if ( myBinIndex < 0 ) myBinIndex = 0;
        if ( myBinIndex > ( myBinCount - 1 ) ) myBinIndex = myBinCount - 1;

        myHistogram.histogramVector[myBinIndex] += 1;
        myHistogram.nonNullCount++;
      }
      delete blk;
    }
  }

  myHistogram.valid = true;
  mHistograms.append( myHistogram );

#ifdef QGISDEBUG
  QString hist;
  for ( int i = 0; i < qMin( myHistogram.histogramVector.size(), 500 ); i++ )
  {
    hist += QString::number( myHistogram.histogramVector.value( i ) ) + " ";
  }
  QgsDebugMsg( "Histogram (max first 500 bins): " + hist );
#endif

  return myHistogram;
}
コード例 #13
0
ファイル: tests.c プロジェクト: smdarry/rdefaut2010
void testAbsDiffHistograms()
{
    printf("\nTEST HISTOGRAM DIFFERENCE\n");

    // Construction d'histogrammes de test
    int channel = 0;
    Histogram h1;
    initHistogram(&h1, 5, 3);
    h1.freq[0][channel] = 12;   // 0.11
    h1.freq[1][channel] = 15;   // 0.14
    h1.freq[2][channel] = 20;   // 0.18
    h1.freq[3][channel] = 45;   // 0.41
    h1.freq[4][channel] = 19;   // 0.17
    
    Histogram h2;
    initHistogram(&h2, 5, 3);
    h2.freq[0][channel] = 3;    // 0.02
    h2.freq[1][channel] = 17;   // 0.14
    h2.freq[2][channel] = 19;   // 0.15
    h2.freq[3][channel] = 70;   // 0.56
    h2.freq[4][channel] = 16;   // 0.13

    float sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 40.00, Actual: %.2f\n", sum);

    // Avec histogrammes normalises
    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 0.31, Actual: %.2f\n", sum);


    // Test 2: histogrammes identiques
    //
    h1.freq[0][channel] = 12;   // 0.11
    h1.freq[1][channel] = 15;   // 0.14
    h1.freq[2][channel] = 20;   // 0.18
    h1.freq[3][channel] = 45;   // 0.41
    h1.freq[4][channel] = 19;   // 0.17

    h2.freq[0][channel] = 12;   // 0.11
    h2.freq[1][channel] = 15;   // 0.14
    h2.freq[2][channel] = 20;   // 0.18
    h2.freq[3][channel] = 45;   // 0.41
    h2.freq[4][channel] = 19;   // 0.17

    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 0.00, Actual: %.2f\n", sum);


    // Test 3: histogrammes disjoints completement
    //
    h1.freq[0][channel] = 0;   // 0.00
    h1.freq[1][channel] = 0;   // 0.00
    h1.freq[2][channel] = 0;   // 0.00
    h1.freq[3][channel] = 45;  // 0.70
    h1.freq[4][channel] = 19;  // 0.30

    h2.freq[0][channel] = 23;  // 0.56
    h2.freq[1][channel] = 15;  // 0.37
    h2.freq[2][channel] = 3;   // 0.07
    h2.freq[3][channel] = 0;   // 0.00
    h2.freq[4][channel] = 0;   // 0.00

    normalizeHistogram(&h1);
    normalizeHistogram(&h2);

    sum = absDiffHistograms(&h1, &h2, channel);
    printf("Expected: 2.00, Actual: %.2f\n", sum);
}