convolution of multiple images with multiple filters

2 ビュー (過去 30 日間)
MA
MA 2021 年 10 月 25 日
コメント済み: Image Analyst 2021 年 10 月 25 日
Let's assume I have a set of images in one variable X, where the size of this variable is 4D [width, height, channels, number of images]. Now, I want to do a convolution with a set of filters that are all in one variable F of size 4D [filter width, filter height, channels, number of filters]. Is there any function in Matlab that could do that or any thing similar to this idea?
Thanks.

採用された回答

Image Analyst
Image Analyst 2021 年 10 月 25 日
I'd just do a for loop over the 4th dimension
for k = 1 : size(X, 4)
thisFilter = F(:, :, :, k);
thisX = X(:, :, :, k);
filteredImage = convn(thisX, thisFilter, 'same');
end
For readability and maintainability, I really recommend you use more descriptive variable names. No one lilkes to read code that looks like alphabet soup.
  2 件のコメント
MA
MA 2021 年 10 月 25 日
The number of filters in my setting is not the same as the number of images. I was seeking for a function to do the convolution without looping over the filters and the images. Thanks.
Image Analyst
Image Analyst 2021 年 10 月 25 日
How would that work? Let's say you have 20 images and 100 filters? How many filtered output images do you want? If it's 20x100 = 2000 then just have two for loops. Don't worry about for loops being slow, especially for only 2000 iterations. You computer can do 200 iterations in microseconds. It's the filtering itself that will take most of the time, not the iterations.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by