# filter2D function error

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 close merge delete

Sort by » oldest newest most voted

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!

more

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

( 2013-05-20 10:17:07 -0500 )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

( 2013-05-20 10:26:15 -0500 )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

( 2013-05-21 10:12:06 -0500 )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?

( 2013-05-21 10:41:06 -0500 )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.

( 2013-05-21 15:06:36 -0500 )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!

( 2013-05-21 18:58:31 -0500 )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.

( 2013-05-22 08:51:08 -0500 )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

( 2013-05-22 10:52:01 -0500 )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');

( 2013-05-22 11:30:45 -0500 )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

( 2013-05-22 11:44:53 -0500 )edit

Official site

GitHub

Wiki

Documentation