help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Help with matrix replication


From: Richardson, Anthony
Subject: RE: Help with matrix replication
Date: Fri, 11 Jan 2013 14:54:06 +0000

 From:  Carnë Draug
> On 20 December 2012 21:04, Richardson, Anthony <address@hidden>
> wrote:
> > Pixel replication appears to produce the same result as imresize only
> > when imresize is used with the "nearest" interpolation option and only
> > for integer scale factors greater than one.  (imresize supports
> > non-integer scale factors both larger (enlarge) and smaller (shrink)
> > than one.)
> >
> > Anyway:
> >
> >   b = a((1:size(a,1))(ones(1,n),:), (1:size(a,2))(ones(1,n),:));
> >
> > appears (for the test cases I've run) to return the same result as b =
> imresize(a, n, 'nearest') when n is an integer larger than one.  In this
> particular case, the line above is much faster and uses much less memory
> than imresize.
> >
> > Similarly, I assume pixel elimination:
> >
> > m = round(1/n);
> > b = a(1:m:end,1:m:end);
> >
> > would be faster than b = imresize(a, n) when (1/n) is an integer greater
> than one (image shrinking) regardless of the interpolation method (but I
> have not tested this).
> >
> > I don't know that such special cases (enlarging or shrinking by integer 
> > scale
> factors) merit making changes to imresize.
> >
> > Tony
> 
> Just to let you know, I pushed a commit that implements this.
> https://sourceforge.net/p/octave/code/11557/tree/trunk/octave-
> forge/main/image/inst/imresize.m
> 
> There was no performance increase when shrinking but it still shows when its
> shrinking in one direction and enlarging on the other.
> 
> octave> a = round (1000, 1000);
> octave> t = cputime(); b = old_imresize (a, 2, "nearest"); cputime() - t
> ans =  1.5641
> octave> t = cputime(); b = new_imresize (a, 2, "nearest"); cputime() - t
> ans =  0.056003
> 
> octave> t = cputime(); b = old_imresize (a, 4, "nearest"); cputime() - t
> error: memory exhausted or requested size too large for range of Octave's
> index type -- trying to return to prompt
> octave> t = cputime(); b = new_imresize (a, 4, "nearest"); cputime() - t
> ans =  0.16001
> 
> octave> t = cputime(); b = old_imresize (a, 1/4, "nearest"); cputime() -
> octave> t
> ans =  0.024002
> octave> t = cputime(); b = new_imresize (a, 1/4, "nearest"); cputime() -
> octave> t
> ans =  0.020002
> 
> octave> t = cputime(); b = old_imresize (a, [2000 500], "nearest");
> cputime() - t
> ans =  0.40803
> octave> t = cputime(); b = new_imresize (a, [2000 500], "nearest");
> cputime() - t
> ans =  0.028001
> 
> Carnë

Very cool!  Thanks Carnë.

Tony


reply via email to

[Prev in Thread] Current Thread [Next in Thread]