我正在尝试使用金字塔对一些图像运行均值偏移分割,如Learning OpenCV书中所述。源图像和目标图像都是上述宽度和高度相同的8位三通道彩色图像。但是,只有在1600x1200或1024x768图像上才能获得正确的输出。大小为625x391和644x438的其他图像导致运行时错误“输入参数的大小在函数cvPyrUp()中不匹配”我的代码如下:
IplImage *filtered = cvCreateImage(cvGetSize(img),img->depth,img->nChannels);
cvPyrMeanShiftFiltering( img, filtered, 20, 40, 1);程序使用示例中给出的参数。我试着降低数值,认为这是一个图像尺寸问题,但没有成功。通过将图像尺寸调整为644x392和640x320,mean-shift正在正常运行。我读过“金字塔分割需要N次可被2整除的图像,其中N是要计算的金字塔层的数量”,但这在这里是如何适用的呢?
有什么建议请提出来。
发布于 2011-03-27 16:48:42
好的,除了当你应用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);问题是,这种金字塔滤波器会根据你使用的级别来修改一些东西。试试这个,如果成功了以后再告诉我。希望我能帮上忙。
https://stackoverflow.com/questions/5391167
复制相似问题