3

我正在尝试使用金字塔来运行均值偏移分割,如Learning OpenCV book on some images中所解释的那样。源图像和目标图像都是 8 位、三通道彩色图像,其宽度和高度与上述相同。然而,只有在 1600x1200 或 1024x768 图像上才能获得正确的输出。其他尺寸为 625x391 和 644x438 的图像导致运行时错误“输入参数的大小在函数 cvPyrUp() 中不匹配”我的代码是这样的:

IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvPyrMeanShiftFiltering( img, filtered, 20, 40, 1);

该程序使用示例中给出的参数。我尝试降低值,认为这是图像尺寸问题,但没有运气。通过将图像尺寸调整为 644x392 和 640x320,均值偏移运行正常。我读过“金字塔分割需要可被 2 整除的 N 倍的图像,其中 N 是要计算的金字塔层数”,但这在这里如何适用?

请有任何建议。

4

1 回答 1

1

好吧,除了应用 cvPyrMeanShiftFiltering 时,您应该这样做:

  //A suggestion to avoid the runtime error
  IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
  cvCopy(img,filtered,NULL);

  //Values only you should know
  int level = kLevel;
  int spatial_radius = kSpatial_Radius;
  int color_radius = = kColor_Radius;

  //Here comes the thing
  filtered->width &= -(1<<level);
  filtered->height &= -(1<<level);

  //Now you are free to do your thing
  cvPyrMeanSihftFiltering(filtered, filtered,spatial_radius,color_radius,level);

问题是这种金字塔形过滤器会根据您使用的级别修改一些东西。试试这个,稍后告诉我是否有效。希望我能帮上忙。

于 2011-03-27T08:48:41.733 回答