Is it possible to convolve a stack of 'images' with a stack equal in amount of different kernels, without a for loop?
4 次查看(过去 30 天)
显示 更早的评论
The only solutions I found so far is when one uses the same kernel. However, I have a different kernel for each image. Does someone know a smart way to omit a for loop here?
This is how my (super slow) script currently works:
images = randn(5,5,2) % 2 images in z dimension, each 5x5.
kernels = randn(3,3,2) % 2 kernels in z dimension, each 3x3.
% slow for loop method
for ii = size(images,3) % ii loops over images
images(:,:,ii) = conv2(images(:,:,ii),kernels(:,:,ii),'same')
end
Perhaps a fourier transform could do the job? But I am not so experienced with this.
Thanks in advance!
0 个评论
回答(1 个)
Vijeta
2023-3-28
Hi Kevin,
It is possible to convolve a stack of images with a stack of kernels without using a for loop. One way to do this is by using the convn function in MATLAB, which performs N-dimensional convolution.
Here are some links you can refer to:https://www.mathworks.com/help/matlab/ref/conv.html
Thanks.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!