3

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 this:

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.

AruniRC
  • 5,070
  • 7
  • 43
  • 73

1 Answers1

1

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.

jsan
  • 733
  • 11
  • 26
  • when I ran your program a run-time error occurred - "Sizes of input arguments do not match (The input and output images must have same size) in function cvPyrMeanShiftFiltering" what happens with your code? – AruniRC Mar 28 '11 at 01:48
  • sorry i didn't understand clearly what you tried to say by your 'edition'? If you mean the `filtered->widht` thing: that gave an error message as the size of the filtered iamge is being changed and pyramids need images of same size. – AruniRC Mar 29 '11 at 14:15
  • i meant width, the change was in copying your img to filetered img before doing the process. – jsan Mar 29 '11 at 18:03
  • ah ok. wait lemme run that! *fingers crossed* – AruniRC Mar 30 '11 at 00:54
  • 1
    works perfectly, thanks a ton! Now could you please explain what that code does? – AruniRC Mar 30 '11 at 01:06
  • The thing that that kind of segmentation actually change the image size for each level you decide to use. – jsan Mar 30 '11 at 05:47