开发者

Error in Pyramid mean shift filtering of image of certain dimensions?

开发者 https://www.devze.com 2023-02-19 10:30 出处:网络
I\'m trying to run the mean shift segmentation using pyramids as explained in the Learning OpenCV book on some images. Both source and destination images are 8-bit, three-channel color images of the s

I'm trying to run the mean shift segmentation using pyramids as explained in the Learning OpenCV book on some images. Both source and destination images are 8-bit, three-channel color images of the same width and height as mentioned. However correct output is obtained only on a 1600x1200 or 1024x768 images. Other images of sizes 625x391 and 644x438 are causing a runtime error "Sizes of input arguments do not match in function cvPyrUp()" My code is t开发者_如何学运维his:

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

The program uses the parameters as given in the sample. I've tried decreasing values thinking it to be an image dimensions problem, but no luck. By resizing image dimensions to 644x392 and 640x320 the mean-shift is running properly. I've read that "pyramid segmentation requires images that are N-times divisible by 2, where N is the number of pyramid layers to be computed" but how is that applicable here?

Any suggestions please.


Well you have anything wring except that when you apply cvPyrMeanShiftFiltering you should do it like this:

  //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);

The thing is that this kind of pyramidal filter modifies som things acording the level you use. Try this and tell me later if worked. Hope i can help.

0

精彩评论

暂无评论...
验证码 换一张
取 消