bugGNU Octave - Bugs: bug #43823, image package: potential bug in...

 
 

bug #43823: image package: potential bug in imresize.m

Submitter:  None
Submitted:  Sun 14 Dec 2014 10:06:52 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  John Smith Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 3.8.1
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 08 Dec 2016 05:41:56 PM UTC, comment #2: 


No answer from OP.

Closing as invalid, according to comment #1.

Avinoam Kalma <avinoam>
Group Member
Mon 15 Dec 2014 04:43:59 PM UTC, comment #1: 

Thank you for your bug report.  The version of imresize you are linking too is very much out of date. Could you please compare with the latest version at

http://hg.code.sf.net/p/octave/image/file/8e61772f2fcf/inst/imresize.m

and let me know if you still have a problem there.


Carnë Draug <carandraug>
Group Member
Sun 14 Dec 2014 10:06:52 PM UTC, original submission:  

There might be a bug related to the use of anti-aliasing filter in the "imresize.m" function, whose code one can see at

http://sourceforge.net/p/octave/image/ci/Octave-Forge-2006.01.28/tree/imresize.m

Consider running this function with an image of size 32x32, i.e.

img_bigger = imresize(img, [64,64], 'cubic')

or

img_smaller = imresize(img, [16,16], 'cubic')

Here 'cubic' could be 'spline', but not 'nearest'.

The problem is with the "reverse logic of the algorithm". At line 85 we have:

if (m > 1 & filter > 0)
      # If the image is being enlarged and filter > 0 then
      # convolve the image with a filter*filter gaussian.

...

and at line 93:

elseif (m < 1 & nargin == 4)
      # If the image size is being reduced and a fourth argument
      # is given, use it as a FIR filter.
...


As we have 3 arguments and the method which is not "nearest", filter is set to 11, and hence the anti-aliasing filter will be applied (wrongly) when using imresize to enlarge an image. When imresize is applied to reduce the size of the original image, there will be no anti-aliasing filtering at all since nargin==3.

This seems to be wrong: the problem with aliasing is about representing a higher resolution image in a low-resolution domain.

We need antialiasing (low pass filter) BEFORE resampling with interp2 to lower resolution, and we do not need antialiasing when upsampling with interp2 to bigger than original resolutions.

The suggestion is to reverse "m>1" on line 85 to "m<1", and similarly on line 93. The suggested change is attached in the file imresizemod.m.

P.S. Optinal matters: Consider also switching from Gaussian smoothing to fir1 filter as is done in MATLAB (might not be important at all, but to be more consistent with MATLAB and more flexible), and also "mexing" interp2 as it is currently 5-10x slower than MATLAB's equivalent already on very tiny images such as when resizing from 28x28 to 32x32.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #32666:  imresizemod.m added by None (4KiB - text/x-objcsrc - Please verify imresize.m code logic and consider the suggested change.)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam (Posted a comment)
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-12-08 avinoam StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2014-12-15 carandraug CategoryLibraries Octave Package
        SummaryPotential bug in imresize.m in Image toolbox image package: potential bug in imresize.m
    2014-12-15 avinoam Carbon-Copy- Added avinoam
    2014-12-14 None Attached File- Added imresizemod.m, #32666

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code