From: Sébastien Leclaire on
Anyway to do this by calling only one time imfilter? I would like to do this with imfilter to use the fast simd instruction. Is it possible to define a multidimensional filter that would do that? Thanks you for your help.

F=rand(128*128,9);
F=reshape(F,128,128,9);
h=[0 0 0; 0 1 0; 0 0 0];
F(:,:,1)=imfilter(F(:,:,1),h,'circular','same');
h=[0 0 0; 1 0 0; 0 0 0];
F(:,:,2)=imfilter(F(:,:,2),h,'circular','same');
h=[1 0 0; 0 0 0; 0 0 0];
F(:,:,3)=imfilter(F(:,:,3),h,'circular','same');
h=[0 1 0; 0 0 0; 0 0 0];
F(:,:,4)=imfilter(F(:,:,4),h,'circular','same');
h=[0 0 1; 0 0 0; 0 0 0];
F(:,:,5)=imfilter(F(:,:,5),h,'circular','same');
h=[0 0 0; 0 0 1; 0 0 0];
F(:,:,6)=imfilter(F(:,:,6),h,'circular','same');
h=[0 0 0; 0 0 0; 0 0 1];
F(:,:,7)=imfilter(F(:,:,7),h,'circular','same');
h=[0 0 0; 0 0 0; 0 1 0];
F(:,:,8)=imfilter(F(:,:,8),h,'circular','same');
h=[0 0 0; 0 0 0; 1 0 0];
F(:,:,9)=imfilter(F(:,:,9),h,'circular','same');
F=reshape(F,128*128,9);
From: Sean on
"Sébastien Leclaire" <sebastienleclaire(a)gmail.com> wrote in message <i22920$a36$1(a)fred.mathworks.com>...
> Anyway to do this by calling only one time imfilter? I would like to do this with imfilter to use the fast simd instruction. Is it possible to define a multidimensional filter that would do that? Thanks you for your help.
>
> F=rand(128*128,9);
> F=reshape(F,128,128,9);
> h=[0 0 0; 0 1 0; 0 0 0];
> F(:,:,1)=imfilter(F(:,:,1),h,'circular','same');
> h=[0 0 0; 1 0 0; 0 0 0];
> F(:,:,2)=imfilter(F(:,:,2),h,'circular','same');
> h=[1 0 0; 0 0 0; 0 0 0];
> F(:,:,3)=imfilter(F(:,:,3),h,'circular','same');
> h=[0 1 0; 0 0 0; 0 0 0];
> F(:,:,4)=imfilter(F(:,:,4),h,'circular','same');
> h=[0 0 1; 0 0 0; 0 0 0];
> F(:,:,5)=imfilter(F(:,:,5),h,'circular','same');
> h=[0 0 0; 0 0 1; 0 0 0];
> F(:,:,6)=imfilter(F(:,:,6),h,'circular','same');
> h=[0 0 0; 0 0 0; 0 0 1];
> F(:,:,7)=imfilter(F(:,:,7),h,'circular','same');
> h=[0 0 0; 0 0 0; 0 1 0];
> F(:,:,8)=imfilter(F(:,:,8),h,'circular','same');
> h=[0 0 0; 0 0 0; 1 0 0];
> F(:,:,9)=imfilter(F(:,:,9),h,'circular','same');
> F=reshape(F,128*128,9);

There might be a way but I would just preallocate both your filtered image and your H and it'll be pretty fast.

H = cat(3,[0 0 0; 0 1 0; 0 0 0],[0 0 0; 1 0 0; 0 0 0],...
[1 0 0; 0 0 0; 0 0 0],[0 1 0; 0 0 0; 0 0 0],[0 0 1; 0 0 0; 0 0 0],...
[0 0 0; 0 0 1; 0 0 0],[0 0 0; 0 0 0; 0 0 1],[0 0 0; 0 0 0; 0 1 0],...
[0 0 0; 0 0 0; 1 0 0]);

F_filtered = zeros(size(F));
for ii = 1:9
F_filtered(:,:,ii) = imfilter(F(:,:,ii),H(:,:,ii),'circular','same');
end
From: Sébastien Leclaire on
Thanks for your anwser, even if the solution is faster or is cleaner, this is not what is was looking for. In your exemple imfilter is still call 9 times. I really want imfilter to be call only one time. This is the thing I want to know if it is possible.

"Sean " <sean.dewolski(a)nospamplease.umit.maine.edu> wrote in message <i22asn$8p5$1(a)fred.mathworks.com>...
> "Sébastien Leclaire" <sebastienleclaire(a)gmail.com> wrote in message <i22920$a36$1(a)fred.mathworks.com>...
> > Anyway to do this by calling only one time imfilter? I would like to do this with imfilter to use the fast simd instruction. Is it possible to define a multidimensional filter that would do that? Thanks you for your help.
> >
> > F=rand(128*128,9);
> > F=reshape(F,128,128,9);
> > h=[0 0 0; 0 1 0; 0 0 0];
> > F(:,:,1)=imfilter(F(:,:,1),h,'circular','same');
> > h=[0 0 0; 1 0 0; 0 0 0];
> > F(:,:,2)=imfilter(F(:,:,2),h,'circular','same');
> > h=[1 0 0; 0 0 0; 0 0 0];
> > F(:,:,3)=imfilter(F(:,:,3),h,'circular','same');
> > h=[0 1 0; 0 0 0; 0 0 0];
> > F(:,:,4)=imfilter(F(:,:,4),h,'circular','same');
> > h=[0 0 1; 0 0 0; 0 0 0];
> > F(:,:,5)=imfilter(F(:,:,5),h,'circular','same');
> > h=[0 0 0; 0 0 1; 0 0 0];
> > F(:,:,6)=imfilter(F(:,:,6),h,'circular','same');
> > h=[0 0 0; 0 0 0; 0 0 1];
> > F(:,:,7)=imfilter(F(:,:,7),h,'circular','same');
> > h=[0 0 0; 0 0 0; 0 1 0];
> > F(:,:,8)=imfilter(F(:,:,8),h,'circular','same');
> > h=[0 0 0; 0 0 0; 1 0 0];
> > F(:,:,9)=imfilter(F(:,:,9),h,'circular','same');
> > F=reshape(F,128*128,9);
>
> There might be a way but I would just preallocate both your filtered image and your H and it'll be pretty fast.
>
> H = cat(3,[0 0 0; 0 1 0; 0 0 0],[0 0 0; 1 0 0; 0 0 0],...
> [1 0 0; 0 0 0; 0 0 0],[0 1 0; 0 0 0; 0 0 0],[0 0 1; 0 0 0; 0 0 0],...
> [0 0 0; 0 0 1; 0 0 0],[0 0 0; 0 0 0; 0 0 1],[0 0 0; 0 0 0; 0 1 0],...
> [0 0 0; 0 0 0; 1 0 0]);
>
> F_filtered = zeros(size(F));
> for ii = 1:9
> F_filtered(:,:,ii) = imfilter(F(:,:,ii),H(:,:,ii),'circular','same');
> end