bugGNU Octave - Bugs: bug #45568, image package: imfilter...

 
 

bug #45568: image package: imfilter incompatible to MATLAB for even filter width

Submitter:  Felix <fefe>
Submitted:  Fri 17 Jul 2015 01:01:42 PM UTC
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * other Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Mon 07 Dec 2015 04:58:26 PM UTC, comment #7: 

Seems good to me and passes the tests. I have pushed it http://hg.code.sf.net/p/octave/image/rev/a25350dffab4

Thank you for fixing this.

Carnë Draug <carandraug>
Project Member
Fri 04 Dec 2015 10:30:43 PM UTC, comment #6: 

Could you try the attached PATCH and see if it

  • fixes this issue
  • maybe has some unwanted side effects?

(file #35642)

Hartmut <hardy>
Mon 20 Jul 2015 01:47:30 AM UTC, comment #5: 

yes, sorry, didn't dig farther after seeing the conv2 in imfilter. so, with the same imfilter call, within filter2, here's the input to conv2 in Octave 4.0.0, heading into the following line of code (after [nr,nc]=size(b))

y = conv2 (x, b(nr:-1:1, nc:-1:1), shape);

debug> x
x =

   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   1   1   0   0   0   0
   0   0   0   1   1   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0

debug> b
b =

   0   0   0   0
   0   1   1   0
   0   0   0   0
   0   0   0   0

debug> b(nr:-1:1,nc:-1:1)
ans =

   0   0   0   0
   0   0   0   0
   0   1   1   0
   0   0   0   0

debug> shape
shape = valid

Output in octave is:

debug> conv2 (x, b(nr:-1:1, nc:-1:1), shape)
ans =

   0   0   0   0   0   0
   0   0   0   0   0   0
   0   1   2   1   0   0
   0   1   2   1   0   0
   0   0   0   0   0   0
   0   0   0   0   0   0

same inputs into ML conv2 give:

>> x=zeros(9,9);x(4:5,4:5)=ones(2,2)

x =

     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0

>> b = zeros(4,4);b([6,10])=1

b =

     0     0     0     0
     0     1     1     0
     0     0     0     0
     0     0     0     0

>> [nr,nc]=size(b)

nr =

     4


nc =

     4

>> shape='valid'

shape =

valid

>> conv2 (x, b(nr:-1:1, nc:-1:1), shape)

ans =

     0     0     0     0     0     0
     0     0     0     0     0     0
     0     1     2     1     0     0
     0     1     2     1     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0

So, we get the same answer from MLs conv2 as Octave's conv2.

Nicholas Jankowski <nrjank>
Project Member
Sun 19 Jul 2015 11:26:39 PM UTC, comment #4: 

I also found that the function called filter2. But when I checked filter2 at my system (3.81), it called "conv2" but with the filter being "flipped". So if we could rule out conv2 behaving differently, then it would be enough to see how signal and filter is being treated up until the point of calling conv2.

ImageGfield <imagegfield>
Sun 19 Jul 2015 07:20:21 PM UTC, comment #3: 

equivalent ML output from filter2 matches Octave filter2 output. So the error seems to be in what works its way to filter2.

>> f = [0 0 0 0;0 1 1 0;0 0 0 0;0 0 0 0]

f =

     0     0     0     0
     0     1     1     0
     0     0     0     0
     0     0     0     0

>> im=zeros(9,9);im(4:5,4:5)=ones(2,2)

im =

     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     1     1     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0     0

>> res_size='valid'

res_size =

valid

>> filter2(f,im,res_size)

ans =

     0     0     0     0     0     0
     0     0     0     0     0     0
     0     1     2     1     0     0
     0     1     2     1     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0

Nicholas Jankowski <nrjank>
Project Member
Sun 19 Jul 2015 07:15:30 PM UTC, comment #2: 

just doing a quick check on Felix's original code, it doesn't pass through the conv2 loop at line 121, it goes through filter2 code on line 117. (at least, setting a breakpoint at 121, it never hit it, but it calls 117

stopping at 117 here are the input parameters to filter two and the output of that function call, which is the returned value from imfilter. (I'll see if I can compare with ML soon)

debug> f
f =

   0   0   0   0
   0   1   1   0
   0   0   0   0
   0   0   0   0

debug> im(:,:,i)
ans =

   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   1   1   0   0   0   0
   0   0   0   1   1   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0
   0   0   0   0   0   0   0   0   0

debug> res_size
res_size = valid
debug> filter2(f,im(:,:,i),res_size)
ans =

   0   0   0   0   0   0
   0   0   0   0   0   0
   0   1   2   1   0   0
   0   1   2   1   0   0
   0   0   0   0   0   0
   0   0   0   0   0   0

Nicholas Jankowski <nrjank>
Project Member
Fri 17 Jul 2015 06:35:07 PM UTC, comment #1: 

Ok. Seems that imfilter, filter2 et.c. calls conv2 in the end.

I don't have Matlab so I can't check for conv2.
Can you check if the same inconsistency of functionality is true for conv2?

ImageGfield <imagegfield>
Fri 17 Jul 2015 01:01:42 PM UTC, original submission:  

There is a difference in the results of MATLAB and Octave for the imfilter() function when used with even filter-sizes.

Used versions:
Octave 4.0.0
image-2.4.0

Example Code:

I = zeros(6);
I(2:3,2:3) = 1;
F = zeros(4);
F(2,2:3) = 1;
imfilter(I, F)

Matlab-Result:

     0     0     0     0     0     0
     1     2     1     0     0     0
     1     2     1     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0

Octave-Result:

     0     0     0     0     0     0
     0     0     0     0     0     0
     0     1     2     1     0     0
     0     1     2     1     0     0
     0     0     0     0     0     0
     0     0     0     0     0     0

Felix <fefe>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #35642:  imfilter_padding_pos.patch added by hardy (1KiB - text/x-diff)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by hardy (Updated the item)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by imagegfield (Posted a comment)
  • -email is unavailable- added by fefe (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 project members can vote.

     

     

     

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-12-07 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
        Release4.0.0 other
        Operating SystemMicrosoft Windows Any
        Summaryimfilter incompatible to MATLAB for even filter width image package: imfilter incompatible to MATLAB for even filter width
    2015-12-04 hardy Attached File- Added imfilter_padding_pos.patch, #35642

    Back to the top


    Powered by Savane 3.9