[bug #67989] (Image) Octave image ordfilt2 is slower than matlab

"Dmitri A. Sergatskov" <[email protected]>
Newsgroups gmane.comp.gnu.octave.bugs
Message-ID <[email protected]>
Please use the bug tracker to post updates to a bug report.  The mailing list is intended as a read-only notification stream.  Info posted to this mailing list address won't appear in the tracker database where it is most useful.

Follow-up Comment #6, bug #67989 (group octave):

Matlab is probably using Intel IPP library for that. Hard to compete with
those but we can try. With attached
(file __spatial_filtering__das_100.cc) replacement for
"__spatial_filtering__.cc" in the package I see:


octave:1> Img = imread("3.jpg");
octave:2> whos Img
Variables visible from the current scope:

variables in scope: top scope

  Attr   Name        Size                     Bytes  Class
  ====   ====        ====                     =====  ===== 
         Img      3072x4096x3              37748736  uint8

Total is 37748736 elements using 37748736 bytes

octave:3> pkg load image
octave:4> tic; d=ordfilt2((Img(:,:,1)),1,true(7,7)); toc 
Elapsed time is 0.027658 seconds.
octave:5> tic; d=ordfilt2((Img(:,:,1)),1,true(7,7)); toc 
Elapsed time is 0.021487 seconds.
octave:6> tic; d=ordfilt2((Img(:,:,1)),25,true(7,7)); toc 
Elapsed time is 0.122359 seconds.
octave:7> tic; d=ordfilt2(double(Img(:,:,1)),25,true(7,7)); toc 
Elapsed time is 0.150791 seconds.


Attached also is a recent hg snapshot of "image" package with replaced
__spatial_filtering__.cc 
(file image_das_20260211.tgz)
You should be able to install it as usual. 
It may be helpful if your CXXFLAGS are set to "-O3 -mtune=native" and also OMP
is enaled.

I tested with recent Octave-12 snapshot on Fedora 43 (x86-64; Ultra 9 285) and
on MacOS (M4). 

I think further improvements are possible with different filter algorithm
(e.g. "Huang sliding window"), but that is for somebody else.

Dmitri.
-- 


(file #58236, file #58237)

    _______________________________________________________

Additional Item Attachment:

Name: __spatial_filtering__das_100.cc Size: 32KiB

<https://file.savannah.gnu.org/file/__spatial_filtering__das_100.cc?file_id=58236>

Name: image_das_20260211.tgz         Size: 462KiB
    <https://file.savannah.gnu.org/file/image_das_20260211.tgz?file_id=58237>


    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://savannah.gnu.org/source/savane-9cb3993bd77cd3a7b4e316c57f63ab757e1a05d8.tar.gz


    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?67989>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYIAB0WIQQk97aszIMMAvLLwm6qLAuaBUf3TgUCaY1JnAAKCRCqLAuaBUf3
TuFBAQCo2SUFo86DkFWccKseYadsZRJXVJ02IeEV8lvLudYrxQD+IPr/DQOmV/fE
85ylVL19igrld/H+057xJwrfPIu/3Ak=
=K+pE
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.