bugGNU Octave - Bugs: bug #60946, [octave forge] (image) bug in...

 
 

bug #60946: [octave forge] (image) bug in imresize implementation

Submitter:  Rick T <ratulloch>
Submitted:  Tue 20 Jul 2021 12:57:40 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Rick T Open/Closed:  * Closed
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 28 Aug 2021 02:08:26 PM UTC, comment #8: 

Closing as fixed,
Thanks, @Hartmut.

Avinoam Kalma <avinoam>
Group Member
Mon 16 Aug 2021 02:42:32 PM UTC, comment #7: 

Thanks for reviewing, Avinoam.

I have now pushed the patch (V2) to the image repo:

   https://sourceforge.net/p/octave/image/ci/de7d55650ad741377c8f073638cbc1fd440f91d6/

(The formerly used type of web links to the image repo at sourceforge now required password authentification. That's why I switched to this one, I hope it can be freely read by everyone.)

I think this issue here is now FIXED.

Avinoam, please have a look to what extent also bug #55303 has been fixed by this patch. I did not have this other bug report in mind at all, when generating my patch. But it might well be it also fixes that bug, I just have NOT double checked it does.

Hartmut <hardy>
Sat 14 Aug 2021 08:15:11 PM UTC, comment #6: 

Thanks, @Hartmut for the patch,

Checking this bug report, indeed it was fixed in the repo.
The new patch also fixes bug #55202 (imresize fails for an image of 1 row). So, please push it (We will have two bugs solved at a price of one).

Avinoam Kalma <avinoam>
Group Member
Wed 28 Jul 2021 07:51:34 AM UTC, comment #5: 

Find attached a new PATCH (V2) that also fixes resizing of line and row rgb input images in the way scetched in comment #4. It is working around the now fixed bug #60967 in interp1 to keep the image package compatible with older core Octave versions.

Please review.

(file #51704)

Hartmut <hardy>
Sun 25 Jul 2021 03:51:38 PM UTC, comment #4: 

My last patch (V1) is actually not yet the full solution. It makes it possible to use imresize on images of size 1x1x3. But it does not yet work (for arbitrary interpolation methods) for images of size 1xNx3 or Nx1x3.

To improve my last patch, I wanted to further add special cases to imremap.m. Below is code that I would suggest to use:


  for i = 1:n_planes
    if isscalar (im(:,:,i))
      warped(:,:,i) = double(im(:,:,i));
    elseif size(im, 1) == 1
      warped(:,:,i) = ones(size(XI,1), 1) * interp1 (double (im(1,:,i)), XI(1,:), interp, extrapval);
    elseif size(im, 2) == 1
      warped(:,:,i) = interp1 (double (im(:,1,i)), YI(:,1), interp, extrapval)' * ones(1, size(YI,2));
    else
      warped(:,:,i) = interp2 (double (im(:,:,i)), XI, YI, interp, extrapval);
    endif
  endfor


Unfortunatelly the (core) Octave function interp1.m does not behave in the way I expected it, so currently this code does not work. (Matab's interp1 works fine in this respect.) I filed bug #60967 for this. During the meantime I see no useful way to go forward, here. (But let me know if you do.)

Hartmut <hardy>
Sat 24 Jul 2021 07:50:44 PM UTC, comment #3: 

I had a look into this.

It turned out that the behavior described in the original bug report is already fixed with our current version of imresize.m in the image repo. @Rick: Sorry for not releasing this new version sooner. It will be part of the next release of the image package.

Nevertheless, I also checked resizing "1 pixel rgb images" with other interpolation methods, instead of "nearest", and those ones did not yet work properly because of the mechanics inside of our (Octave only) imremap.m. (This also wrong behavior might be what Rick said in comment #1).

Matlab can deal well with resizing 1 pixel rgb images, using any interpolation method in imresize.

As a result I

  • changed the code in imremap.m such that those 1 pixel rgb images now work properly, also with other interpolation methods than "nearest", by introducing a separate code path for those types of images.
  • I added a BIST to imresize.m to check this behavior with two different interpolation methods.


I will attach a patch file (V1). Please give me feedback during the next few weeks. Afterwards I would like to push this patch to the image repository.



(file #51686)

Hartmut <hardy>
Sat 24 Jul 2021 04:40:38 PM UTC, comment #2: 

Thanks for submitting this issue to our bug tracker. I am adding people to cc for the beginning.

Hartmut <hardy>
Tue 20 Jul 2021 01:43:45 AM UTC, comment #1: 

I've also found the colors not matching with

 reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'linear'); %reshape swatch to large output

and

 reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'cubic'); %reshape swatch to large output

and


 reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'bicubic'); %reshape swatch to large output

Rick T <ratulloch>
Tue 20 Jul 2021 12:57:40 AM UTC, original submission:  

Imresize gives incorrect results.  Here's a link how it was found and how to fix it / and a work around.

https://stackoverflow.com/questions/68445353/matrix-array-to-multidimensional-rgb-image-array-and-using-imresize-to-reshape-i
 

Test Code:  Should be a color swatch but gives black boxes,
pkg load image

f(:,:,1)=[255;0;0;0;0];
f(:,:,2)=[0;255;0;0;255];
f(:,:,3)=[0;0;255;0;2];

height_wanted=640;
width_wanted=480;

repmat_rgb=cat(2,f,f); %add another column to array to get imresize to work
reshaped_output = imresize(repmat_rgb, [height_wanted, width_wanted],'nearest'); %reshape swatch to large output
imshow(reshaped_output);

Rick T <ratulloch>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51704:  imresize_1px_V2.patch added by hardy (3KiB - text/x-patch)
file #51686:  imresize_1px_V1.patch added by hardy (2KiB - text/x-patch)

 

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 hardy (Posted a comment)
  • -email is unavailable- added by hardy
  • -email is unavailable- added by hardy
  • -email is unavailable- added by siko1056 (Updated the item)
  • -email is unavailable- added by ratulloch (Submitted the item)
  • -email is unavailable- added by ratulloch
  •  

    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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-08-28 avinoam StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2021-08-14 avinoam StatusNone In Progress
        Release6.3.0 other
    2021-07-28 hardy Attached File- Added imresize_1px_V2.patch, #51704
    2021-07-24 hardy Attached File- Added imresize_1px_V1.patch, #51686
    2021-07-24 hardy Carbon-Copy- Added carandraug
        Carbon-Copy- Added avinoam
    2021-07-20 siko1056 Summarybug in imresize implementation of Octave image package [octave forge] (image) bug in imresize implementation
    2021-07-20 ratulloch Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code