Can we use biger stride than 1 in Conv2, Convn, Imfilter ?

Hi, I want to use conv2, convn, or Imfilter to filter an image, but i want to stride more than 1, So that to have a reduced output filtered image. How can i do that with builtin matlab functions.

 Réponse acceptée

If you don't want to slide over one pixel, then you can either do the whole thing and subsample the result,
smallResults = fullSizeResult(1:4:end, 1:8:end);
Adjust the step value to whatever you want the jump to be.
Alternatively you can use blockproc(), and I'm attaching some demos for that. blockproc() allows you to scan along your image in "jumps" of a specified step (distance) and process only those window locations.

7 commentaires

Naveed Khan
Naveed Khan le 10 Déc 2015
Modifié(e) : Naveed Khan le 10 Déc 2015
Thank you for your reply. As far i understood this code, this does not have overlap, each time it consider only new area without overlap on previous section. I want something similar like the kernels in conv builtin function. but instead of having 1 movement, i want 2 or 3 , i mean a stride of 2 or 3
What does that mean? What is movement and stride? You basically set up a window and then it moves over one pixel at a time for conv2() where as blockproc() can move in "jumps" of 2 or 3 pixels. Of course if it moves 2 or 3 pixels, there may or may not be overlap depending on the inputs to blockproc(). You can have blockproc() move by distances less than the window size if you want, though that is the default. For example if your window size is 11, it will move in jumps of 11, unless you set an arugment to tell it to move in jumps of 5 or 7 or something else.
Please clarify.
Naveed Khan
Naveed Khan le 10 Déc 2015
Modifié(e) : Image Analyst le 10 Déc 2015
Thanks again, i mean to say that, for example if i have a 7x7 image, and a 3x3 kernel. the coordinates for first kernel region to be convolved will be from (1:3,1:3) and for the second it will be from (1:3,2:4) and for third it will be (1:3,3:5) and so on. each time the kernel leave one column and move to the next. This is what I call a stride of 1. (Also called by Caffe community in deep learning). What if I want to take a bigger stride. e.g. (1:3,1:3), then (1:3,3:5), then (1:3,5:7) and so on. This means I have a stride of 2. Can I change the default step of 1 in conv2, convn, or imfilter function.
The caffe community have it in convolutional neural networks. I want to try something similar in matlab, but Matlab builtin functions doesnt have any option of changing or using a specific stride value.
Just use blockproc() with the 'BorderSize' option.
Jihang Wang
Jihang Wang le 15 Août 2018
Modifié(e) : Jihang Wang le 15 Août 2018
@Image Analyst Change border size only influence the overlapping but the stride is still 1, right? I am struggling with this issue, please advise. Thanks!
No, not right. You can specify both the "jump" distance and the overlap independently. See my attached demo.
Matti Kaupenjohann
Matti Kaupenjohann le 12 Avr 2021
Modifié(e) : Matti Kaupenjohann le 12 Avr 2021
I found this conversation -- while I was looking for a faster implementation for my code -- and was using blockproc before, so I timed it again, but since it was very slow I decided to create my structure by myself and used mexfun. Still not impressing 0.356 seconds for my code but much faster than the 1.6 seconds with blockproc implementation.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by