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

 
 

bug #63560: [octave forge] (image) imresize gives inaccurate result

Submitter:  Raghavan <ragsubra>
Submitted:  Thu 22 Dec 2022 11:16:26 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 10 Feb 2023 08:22:00 AM UTC, comment #12: 

Our current Octave repo code does exactly this! It has a big loop (that runs twice), and does first the processing of one image axis, using a first scaling factor and a first interpolation kernel, and afterwards the the processing of the second image axis. So all that you wish in comment #11 has already been taken care of in our current implementation :)

It would probably help if you used our patched imresize implementation (using the latest patch, currently V3) on a handful of real images, and thoroughly look at the results if something unexpected happens to them. If you observe no obvious side-effects, I am now confident enough to do the right think in the patch, that we could probably push it afterwards.

Hartmut <hardy>
Fri 10 Feb 2023 06:27:09 AM UTC, comment #11: 

Thanks for the fix, Hartmut,
I did not check it yet, but please note that in the original example, there are different scales in x and in y.
Our code takes only one of the scales.
I think that we should build different 1D kernels for x and y directions, and apply each of them.
What do you think?

Avinoam Kalma <avinoam>
Group Member
Thu 09 Feb 2023 04:02:49 PM UTC, comment #10: 

I realised that this fix needs also to be done for the "nearest" type of interpolation, when using antialiasing.

Attached is a new version (V3) of my patch. It increases the half width of the interpolation kernel to an integer number for all interpolation types, when using antialising. It now also includes a new unit test for this behavior. The new unit test is also Matlab compatible.

Please CHECK if there are any side effects of this change in the calculation logic. Otherwise we could push this change to the image repository,  maybe including a short note in the NEWS file.

(file #54343)

Hartmut <hardy>
Wed 08 Feb 2023 08:11:48 PM UTC, comment #9: 

Attached is a patch file (V2 already) that increases the width of the antialiasing interpolation kernels for all kernels that have continous values (custom, linear and cubic, but not for nearest). This seems to fix the problem described in this bug report.

Please CHECK this patch and have a look if it does any harm to the results, elsewhere.

In this patch there aren't any new unit tests added for this, feel free to add them if you come up with useful ones. Also I haven't checked for any Matlab compatibility, yet.

(file #54339)

Hartmut <hardy>
Thu 02 Feb 2023 05:33:05 AM UTC, comment #8: 

comment #7:

> Thanks, Raghavan
> I will be glad if you can try to help fix this bug.
> If I will find out how to fix it, I will ask you to check the fix.


Sure. Absolutely.

Raghavan <ragsubra>
Wed 25 Jan 2023 09:11:51 PM UTC, comment #7: 

Thanks, Raghavan
I will be glad if you can try to help fix this bug.
If I will find out how to fix it, I will ask you to check the fix.

Avinoam Kalma <avinoam>
Group Member
Tue 24 Jan 2023 01:56:05 PM UTC, comment #6: 

Yes, your understanding of the difference in 33 gray levels is correct. I understand the reason behind this change.
Apologies if I caused any confusion.  Let me know if I can be of any further help.

Raghavan <ragsubra>
Sun 22 Jan 2023 09:13:39 PM UTC, comment #5: 

Thanks for checking.

If I understand correctly, the difference of 33 gray levels is between the current version image package and the previous version.
This is because there was a change in imresize, in order to make it more MATLAB compatible.

This bug with anti-aliasing was not reported.
Bug #61760 related  to "imresize - antialiasing is not implemented"

Avinoam Kalma <avinoam>
Group Member
Sun 22 Jan 2023 04:48:00 PM UTC, comment #4: 

I verified that the problem is not visible by setting "antialiasing" as false.  I was not able to compare pixel values numerically with an earlier version since this option is not available in a previous version (octave:6.4.0, image:2.12.0).

Since antialiasing is used only when down-sizing, I tried resizing to [200,200] (up-sizing) instead of [100,100].  The stripe artifact was not seen in both the older and newer (octave: 7.3.0, image: 2.14.0) versions.
In 7.3.0, I also verified that for [200,200] output size, the output was the same with and without setting the "antialiasing" option as false.  This is as expected.

One note however: While no visual difference was found between outputs for 6.4.0 and 7.3.0 for output size [200,200], there was a difference of up to 33 in pixel values when I took an image difference.  This may or may not be another problem with bilinear interpolation.

Overall, I would agree that the original problem that I reported is due to a bug in anti-aliasing, which seems to be reported already.

Raghavan <ragsubra>
Thu 19 Jan 2023 06:46:10 PM UTC, comment #3: 

The problem seems to be related to antialising (see bug #61760)

With


im1 = imresize (im, [100,100], 'method', 'bilinear', 'antialiasing', false);



I do not see this problem.


Avinoam Kalma <avinoam>
Group Member
Thu 22 Dec 2022 10:42:24 PM UTC, comment #2: 

I have also checked the (adapted) sample code from comment #0 with current (online) Matlab, and it does NOT produce these stripes. So this seems to be wrong and incompatible behavior of our function imresize.

Hartmut <hardy>
Thu 22 Dec 2022 10:35:52 PM UTC, comment #1: 

Thank you for your bug report. I add the image package maintainers to cc for now.

I can reproduce this behavior with the current image 2.14 under linux with Octave 7.3.

Hartmut <hardy>
Thu 22 Dec 2022 11:16:26 AM UTC, original submission:  

When an image is resized using imresize, for some images some artifacts/distortions are introduced.  This issue is observed from version 7.2 onwards (version 6.4 does not have the issue).
To reproduce the problem, download the attached image (image.jpg) and run the following lines of code:

pkg load image
im = imread("image.jpg");
im1 = imresize(im, [100,100], 'Linear');
figure(1); subplot(2,1,1) ; imshow(im, [])
subplot(2,1,2) ; imshow(im1, [])
imwrite(im1, "image_resized.jpg", 'Quality',95)

Note the grey stripes created in the flat regions of the resized image.
If imresize method is changed to "Cubic", the artifacts do reduce for this image, but I have seen other images where it gets worse.  I tried smoothing the image to prevent aliasing, but didn't work.  Also note that this problem is not seen in older versions of Octave (6.4.0), nor with opencv

Raghavan <ragsubra>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #54137:  image.jpg added by ragsubra (5KiB - image/jpeg - Test image to reproduce the problem along with the result image)
file #54138:  image_resized.jpg added by ragsubra (4KiB - image/jpeg - Test image to reproduce the problem along with the result image)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by avinoam (Updated the item)
  • -email is unavailable- added by hardy (Posted a comment)
  • -email is unavailable- added by ragsubra (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 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-02-09 hardy Attached File- Added imresize_antialiasingAllTypes@(V3).patch, #54343
    2023-02-08 hardy Attached File- Added imresize_antialiasingMostTypes@(V2).patch, #54339
    2023-01-19 avinoam Carbon-Copy- Added christofkaufmann
    2023-01-14 avinoam StatusNone Confirmed
        Release7.3.0 other
        Operating SystemMicrosoft Windows Any
    2022-12-22 ragsubra Attached File- Added image.jpg, #54137
        Attached File- Added image_resized.jpg, #54138
    2022-12-22 mmuetzel Carbon-CopyRemoved 102357 -
    2022-12-22 mmuetzel Summaryimresize gives inaccurate result [octave forge] (image) imresize gives inaccurate result

    Back to the top

    Powered by Savane 3.13-3230.
    Corresponding source code