MATLAB's im2col
and col2im
are very important function for vectorization in MATLAB when dealing with images.
Yet they require MATLAB's Image Processing Toolbox.
My question is, is there an efficient (Vectorzied) way to implement the using MATLAB's functions (With no toolbox)?
I need both the sliding
and distinct
mode.
I don't need any padding.
Thank You.
You can cheat while looking to GNU Octave image package. There are im2col and col2im as script language implemented:
As far as I see, it differs most in different comment style (# instead of %) and different string style (" instead of '). If you change this and remove the assert test on the bottom, it might be runnable already. If not, go through it with the debugger.
Furthermore, be aware of the License (GPLv3). It's free, but your changes have to be free too!
I can only hope that Mathworks guys don't sue you or me or
Stackoverflow
for that matter, trying to create vectorized implementations of their IP toolbox functions, as they have put price on that toolbox. But in any case, forgetting those issues, here are the implementations.Replacement for
im2col
with'sliding'
optionI wasn't able to vectorize this until I sat down to write solution to another problem on Stackoverflow. So, I would strongly encourage to look into it too.
Replacement for
im2col
with'distinct'
optionSome quick tests show that both these implementations particularly
sliding
one for small to decent sized input data anddistinct
for all datasizes perform much better than the in-built MATLAB function implementations in terms of runtime performance.How to use