直方图max javacv的变化值

时间:2013-02-10 21:00:58

标签: java image opencv image-processing javacv

我试图从我在图片上运行的直方图中获取最大值。我的直方图代码如下所示:(感谢堆栈溢出用户)

  public static CvHistogram getHueHistogram(IplImage image){

    if(image==null || image.nChannels()<3) new Exception("Error!");

    // Split the 3 channels into 3 images
    IplImageArray hsvChannels = splitChannels(image);

    //bins and value-range
    int numberOfBins=255;
    float minRange= 0f;
    float maxRange= 180f;

    // Allocate histogram object
   int dims = 1;
   int[]sizes = new int[]{numberOfBins};
   int histType = CV_HIST_ARRAY;
   float[] minMax = new  float[]{minRange, maxRange};
   float[][] ranges = new float[][]{minMax};
   int uniform = 1;
   CvHistogram hist = cvCreateHist(dims, sizes, histType, ranges, uniform);

   // Compute histogram
   int accumulate = 1;

   @SuppressWarnings("unused")
   IplImage mask = null;
   cvCalcHist(hsvChannels.position(0),hist, accumulate, null);
   return hist;
}

private static IplImageArray splitChannels(IplImage hsvImage) {
    CvSize size = hsvImage.cvSize();
    int depth=hsvImage.depth();
    IplImage channel0 = cvCreateImage(size, depth, 1);
    IplImage channel1 = cvCreateImage(size, depth, 1);
    IplImage channel2 = cvCreateImage(size, depth, 1);
    cvSplit(hsvImage, channel0, channel1, channel2, null);
    return new IplImageArray(channel0, channel1, channel2);
}

现在这是我的get max方法:

public static float getHistMaxValue (CvHistogram hist){

    float[] minValue = {0};// these exist from when I was testing the function, ignore them
    float[] maxValue = {0};
    int[] minId = {0}; // these exist from when I was testing the function, ignore them
    int[] maxId = {0};  
    cvGetMinMaxHistValue( hist, null, maxValue, null, maxId);

    System.out.printf("%2f", maxValue[0]);


    return maxValue[0];
}

现在大多数情况下这个工作正常,我的问题是我的每次运行程序的最大值从1532,298027和298038变化,即使直方图的图像保持不变。在得到直方图之前,我确实对图像进行了大量的处理,但这些函数似乎正常工作。关于为什么这些结果会发生变化的任何想法?

0 个答案:

没有答案