void CompleteExtendedHogFilter::buildInitialHistograms(Mat& histograms, const Mat& image, size_t cellRowCount, size_t cellColumnCount) const { if (image.type() != CV_8UC1) throw invalid_argument("CompleteExtendedHogFilter: image must be of type CV_8UC1"); createLut(rowLut, image.rows, cellRowCount); createLut(columnLut, image.cols, cellColumnCount); size_t height = cellRowCount * cellSize; size_t width = cellColumnCount * cellSize; for (size_t y = 0; y < height; ++y) { int rowIndex1 = rowLut[y].index1; int rowIndex2 = rowLut[y].index2; float rowWeight1 = rowLut[y].weight1; float rowWeight2 = rowLut[y].weight2; for (size_t x = 0; x < width; ++x) { int colIndex1 = columnLut[x].index1; int colIndex2 = columnLut[x].index2; float colWeight1 = columnLut[x].weight1; float colWeight2 = columnLut[x].weight2; int dx = image.at<uchar>(y, std::min(width - 1, x + 1)) - image.at<uchar>(y, std::max(0, static_cast<int>(x) - 1)) + 256; int dy = image.at<uchar>(std::min(height - 1, y + 1), x) - image.at<uchar>(std::max(0, static_cast<int>(y) - 1), x) + 256; const BinInformation& binInformation = binLut[dx * 512 + dy]; if (interpolateCells) { float* histogram11Values = histograms.ptr<float>(rowIndex1, colIndex1); float* histogram12Values = histograms.ptr<float>(rowIndex1, colIndex2); float* histogram21Values = histograms.ptr<float>(rowIndex2, colIndex1); float* histogram22Values = histograms.ptr<float>(rowIndex2, colIndex2); if (interpolateBins) { histogram11Values[binInformation.index1] += binInformation.weight1 * rowWeight1 * colWeight1; histogram11Values[binInformation.index2] += binInformation.weight2 * rowWeight1 * colWeight1; histogram12Values[binInformation.index1] += binInformation.weight1 * rowWeight1 * colWeight2; histogram12Values[binInformation.index2] += binInformation.weight2 * rowWeight1 * colWeight2; histogram21Values[binInformation.index1] += binInformation.weight1 * rowWeight2 * colWeight1; histogram21Values[binInformation.index2] += binInformation.weight2 * rowWeight2 * colWeight1; histogram22Values[binInformation.index1] += binInformation.weight1 * rowWeight2 * colWeight2; histogram22Values[binInformation.index2] += binInformation.weight2 * rowWeight2 * colWeight2; } else { histogram11Values[binInformation.index1] += binInformation.weight1 * rowWeight1 * colWeight1; histogram12Values[binInformation.index1] += binInformation.weight1 * rowWeight1 * colWeight2; histogram21Values[binInformation.index1] += binInformation.weight1 * rowWeight2 * colWeight1; histogram22Values[binInformation.index1] += binInformation.weight1 * rowWeight2 * colWeight2; } } else { float* histogramValues = histograms.ptr<float>(rowIndex1, colIndex1); if (interpolateBins) { histogramValues[binInformation.index1] += binInformation.weight1; histogramValues[binInformation.index2] += binInformation.weight2; } else { histogramValues[binInformation.index1] += binInformation.weight1; } } } } }
void Image::readImage(const QString & path) { QFile file(path); if (file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); QString line = ""; for(int i=0;i<3;i++) { line = stream.readLine(); if(!line.startsWith("#")) { if(i==0) format = line; if(i==1) { QStringList list = line.split(" "); columns=list[0].toInt(); rows=list[1].toInt(); if(QString::compare(format, "P3") == 0 || QString::compare(format, "P6") == 0) width=columns*3; else width=columns; } if(i==2) levels = line.toInt(); } else i--; } createLut(); createMatrix(); for (int idx=0; idx<rows; idx++ ) { for (int idy=0; idy<width; idy++ ) { stream>>matrix[idx][idy]; } } }