Can I get matrix operator for imfilter?

3 次查看(过去 30 天)
For example, I can get x-direction gradient of image through u_x = imfilter(u, [1 -1], 'corr','symmetric','same');
But I want to get the matrix operator corresponding to the above such that D*u = u_x Is it possible? (For example, in one dimension, D*u := [1 -1 0; 0 1 -1; 0 0 1] * [u1; u2; u3];)
(Additional question) Actually, what I want to do is to get transpose of D, i.e., D'. Is there a way to directly apply D' through imfilter?

采纳的回答

Matt J
Matt J 2015-9-27
编辑:Matt J 2015-9-27
But I want to get the matrix operator corresponding to the above such that D*u = u_x Is it possible?
To get a general linear operation in matrix form, you can use my func2mat utility ( Download ). This covers 1D, 2D, or whatever. However, some of the operations you describe are separable in the x,y components of the image and that can be exploited to make things more efficient.
Your example with imfilter along the x direction is a particular case of this. The x-direction operator Dx can be obtained as,
[m,n]=size(yourImage);
fun = @(u) imfilter(u, [1;-1], 'corr','symmetric','same');
Dx = func2mat(fun,yourImage(:,1));
and now the operator for the total 2D image is
D=kron(speye(n),Dx);
In other words
ux=imfilter(yourImage, [1 -1], 'corr','symmetric','same');
is now equivalent to
ux=D*YourImage(:)
ux=reshape(ux,m,n);
Of course, once you have the 1D operator Dx, you can also just as easily do,
ux=Dx*yourImage;
(Additional question) Actually, what I want to do is to get transpose of D, i.e., D'. Is there a way to directly apply D' through imfilter?
It can largely be obtained by switching 'corr' to 'conv' and off-centering the filter kernel,
imfilter(u, [0;1;-1],'conv','symmetric','same');
except there may be some discrepancy at the boundaries of the image due to nonlinear edge handling done by imfilter. If the edge voxel are zero, it won't matter.

更多回答(1 个)

Image Analyst
Image Analyst 2015-9-26
I don't know what all those dollar signs mean. And I have no idea what D is.
You know the filter because you pass it in. You passed in [1, -1] so that is your filter matrix - what you I guess you call "matrix operator".
  4 个评论
jakeoung koo
jakeoung koo 2015-9-27
In one dimension, the matrix is like this D = [1 -1 0; 0 1 -1; 0 0 1]. So I thought that it can be generalized to two dimension.
Image Analyst
Image Analyst 2015-9-27
No, it can't. Think of it like this, in a matrix multiplication, the upper left element is the sum of the products of the first row of one matrix times the first row of the second matrix. So, that upper left element has "information" about all those pixels. In a convolution with a 3x3 window, the first element has information about every element in the 3x3 window, and information about the upper left 3x3 window of the second, larger matrix. Totally different pixels are going into the result, so they are not the same.
Perhaps you were thinking of something like convolution in the spatial or time domain is equivalent to multiplication in the frequency domain (which is true), and just got confused.

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by