2D / 3D graph of image processing filters

I tried to understand the function of 2D and 3D construction in Matlab regarding image processing filters such as boxes, gauss, Mexican hats, etc.

I only got a kernel for filters, for example. 5x5 matrix with the coefficients of each cell. ezsurfc will not work, and I do not understand this. surf works, but I had no idea about meshes and how to make it more grainy and smooth?

My understanding of surf is that I need the same sizes for each parameter, so how do I do this without making my kernel 20x20 or even larger? The idea is that I get output similar to the examples I posted. I mentioned a 20x20 filter mesh mask because it looks like smoothness and alignment require more coefficients than just 5x5 ... Am I right or totally wrong?

I have already tried the following matlab code, an example for a Laplace filter:

[x,y] = meshgrid(1:1:5); %create a 5x5 matrix for x and y (meshes) z = [0 1 2 1 0; 1 3 5 3 1;2 5 9 5 2; 1 3 5 3 1;0 1 2 1 0]; % kernel 5x5 surf(x,y,z); 

This gives me this conclusion: current output

So, how do I create a thin and granular 2D and 3D chart from this 5x5 core information? Thank you very much in advance!

PS: I hope my indentation of the code is not confused ... otherwise edit freely - this is my first post on StackOverflow. :-)

What I want to get is similar to these two examples: example no.1example no.2

+4
source share
1 answer

You can use interp2 to find intermediate values ​​in the same grid size for visualization purposes

 step = 0.1; % granularity [xn,yn] = meshgrid(1:step:5); % define finer grid zn = interp2(x,y,z,xn,yn); % get new z values surf(xn,yn,zn); 

enter image description here

Please note that you will get the closest approximation to the original kernel using the default linear interpolation method, i.e. interp2(x,y,z,xn,yn,'linear') . Using other methods will lead to the use of smoother cores, but their three-dimensional shape will be different. It depends on your use and application.

Update :

You can bypass the incorrect up-sampling problem with a much higher resolution (reverse reconstruction is possible only if the hypothetical "downsampling" takes into account the Nyquist sampling rate), trying to bring your data closer to the known core, which can then be tuned.

For example, since you give an example of a symmetric core that decays isotopically around a maximum value, you can use the Gauss function. MATLAB does this through the fspecial function.

Suppose that the main function (for example, Gaussian) uses parameters determined from your current kernel (for example, fitting the function to your data).

 % use max location, amplitude and std from your kernel max_z = max(z(:)); std_z = std(z(:)); % Set of tunable parameters (size of grid & granularity) bounds_grid = [30 30]; grid bounds step = 0.5; % resolution % Grid siz = (bounds_grid-1)/2; [x,y] = meshgrid(-siz(2):step:siz(2),-siz(1):step:siz(1)); % Gaussian parameters s = std_z; m = 0; % Analytic function g = exp(-((xm).^2 + (ym).^2)/(2*s*s)); g(g<eps*max(g(:))) = 0; g = max_z*g./max(g(:)); surf(g); 

Thus, you respect the kernel parameters in a Gaussian fraction, but control the grid size and resolution of the final Gaussian kernel.

Some examples:

enter image description here

+5
source

Source: https://habr.com/ru/post/1436416/


All Articles