Ask Your Question
0

filter2D function error

asked 2013-05-20 08:07:59 -0600

residentelvio gravatar image

updated 2019-01-25 12:52:52 -0600

I m using this line with this function but I have an error.

filter2D(GaussKernel,conspic1,GaussKernel.depth(),split(GaussKernel,KernelAchrSplit),Point(-1,-1),0,BORDER_DEFAULT);

Kernel and conspic1 are Mat object. I suppose I have a problem with the kernel, because I don'tknow any function that returns me it. So I use split function

This is how to use the function for C++:

void filter2D(InputArray src, OutputArray dst, int ddepth, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT );

The error I have is:

invalid use of void expression

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2013-05-20 09:22:07 -0600

Guanta gravatar image

updated 2013-05-20 09:22:52 -0600

You can't use split-fnct here (why do you want that at all?), the function filter2D expects a matrix as a kernel, split returns nothing (i.e. void) thus the error, so call it properly with a kernel which you can build yourself with cv::getGaussianKernel() (see http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=blur#getgaussiankernel) or blur your image directly via cv::GaussianBlur() (see http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=blur#gaussianblur). Good luck!

edit flag offensive delete link more

Comments

I supposed was the function getGaussianKernel() but I don t know how to se t his paramethers :ksize and sigma. I suppose the ktype must be the same of the input array of filter2D

residentelvio gravatar imageresidentelvio ( 2013-05-20 10:17:07 -0600 )edit

sigma you can set to -1, then the ideal sigma to your kernel size is computed, thus the larger you chose the kernel to be the larger you'll blur/smooth your image. Kernel-type can be different from the destination-image-depth (ddepth) of filter2d, see http://docs.opencv.org/modules/imgproc/doc/filtering.html?highlight=blur#filter2d

Guanta gravatar imageGuanta ( 2013-05-20 10:26:15 -0600 )edit

What I have to do is translating from Matlab:

GaussKernel=fspecial('gaussian',maxhw,sigma);

conspic=filter2(GaussKernel,conspic,'same'); //Gaussian snoothing in each orientation

What I did is:

GaussianBlur(maxhw,GaussKernel,Size(0,0),1,1,BORDER_DEFAULT;

//setting 1,1 ; i m setting the Gaussian kernel standard deviation as the paramether sigma in Matlab first line

filter2D(GaussKernel,conspic1,GaussKernel.depth(),split(GaussKernel,KernelAchrSplit),Point(-1,-1),0,BORDER_DEFAULT); //I know I don t have to use split for the kernel paramether, but I suppose I have to use GaussKernel Mat object's kernel and I don t know how get it

residentelvio gravatar imageresidentelvio ( 2013-05-21 10:12:06 -0600 )edit

So can you help me with the code of second line? Is it better I use getGaussianKernel doing something like: ilter2D(GaussKernel,conspic1,GaussKernel.depth(),getGaussianKernel(5,-1.0,GaussKernel.type()),Point(-1,-1),0,BORDER_DEFAULT) How I have to set the getGaussianKernel's paramether?

residentelvio gravatar imageresidentelvio ( 2013-05-21 10:41:06 -0600 )edit

I can only point to my original post. EITHER use GaussianBlur OR use getGaussianKernel together with filter2D, i.e. your last comment should be correct and you can omit your other lines of your second last comment.

Guanta gravatar imageGuanta ( 2013-05-21 15:06:36 -0600 )edit

MATLAB CODE : %Softening Gaussian filter % Gaussian parameters as functions of image size

   maxhw = max(0,floor(min(r/2,c/2) - 1));  
   sigma = max(r,c)*0.025; 
   GaussKernel=fspecial('gaussian',maxhw,sigma); 

     % Gaussian smoothing in each orientation 
     conspic=filter2(GaussKernel,conspic,'same'); 
     conspic1 = conspic1 + conspic;

C++ CODE just: GaussianBlur(maxhw,GaussKernel,Size(0,0),1,1,BORDER_DEFAULT);

Right? P.S. Thanks to help me!

residentelvio gravatar imageresidentelvio ( 2013-05-21 18:58:31 -0600 )edit

You are pretty close, however try to read the documentation better. GaussianBlur wants the input image as first parameter, the output image as second parameter, the kernel-size as third (that is maxhw) and the sigma as fourth parameter (for the other parameters you can leave the default-parameters), i.e. it follows:

GaussianBlur(input_img, blurred_output_img, Size(maxhw,maxhw), sigma);

of course you have to compute maxhw and sigma as in the matlab implementation. I hope it is clear now! Please also mark the answer as solved.

Guanta gravatar imageGuanta ( 2013-05-22 08:51:08 -0600 )edit
      maxhw=max(0,(int)floor(min(r/2,c/2) - 1));
      sigma = max(r,c)*0.025;
      GaussianBlur=(conspic,conspic,Size(maxhw,maxhw),sigma,sigma,BORDER_DEFAULT);
      conspic1=conspic1+conspic
residentelvio gravatar imageresidentelvio ( 2013-05-22 10:52:01 -0600 )edit
for i_orient =1: achrOrient

stack=cat(3,resp{i_orient,:});
inComp=reshape(stack,r*c,achrScales)
Tsquared=whitening_sqr_meanDistance(inComp);
conspic=(reshape(Tsquared,r,c));
  % Gaussian softening of orientation conspicuities
conspic=conspic/max(conspic(:));

   % Softening Gaussian filter
   % Gaussian parameters as functions of image size 
maxhw=max(0,floor(min(r/2,c/2) - 1));
sigma=max(r,c)*0.025;
GaussKernel=fspecial('gaussian',maxhw,sigma);
     % Gaussian snoothing in each orientation
 conspic=filter2(GaussKernel,conspic,'same');
 conspic1=conspic1+conspic;
   end

conspic1=conspic1/max(conspic1(:));
conspic1=filter2(GaussKernel,conspic1,'same');
residentelvio gravatar imageresidentelvio ( 2013-05-22 11:30:45 -0600 )edit

I suppose that what I wrote (thanks to you) is right,but now I have doubt for the second filter2 it use, I have to use another time GaussianBlur? This is the Chromatic Saliency of a picture, after I work fot the Achromatic Saliceny and it use in matlab filter2 2 times for the softening.So what have I to use to the other filter2 functions. I have some problems to translate stack=cat(3,resp{i_orient,:});

Sorry for all this problems I m giving to you and thanks for helps

residentelvio gravatar imageresidentelvio ( 2013-05-22 11:44:53 -0600 )edit

Question Tools

Stats

Asked: 2013-05-20 08:07:59 -0600

Seen: 2,383 times

Last updated: May 20 '13