Thanks to visit codestin.com
Credit goes to github.com

Skip to content

INTER_NEAREST_EXACT not giving expected result wrt PIL and scikit-image #22204

@prateek9623

Description

@prateek9623
System information (version)
  • OpenCV => 4.5.4
  • Language=> python/cpp
  • Operating System / Platform => Windows
  • Compiler => MSVC 19.32.31332.0
    I am trying to replicate PIL and scikit-image nearest-neighbor o/p in OpenCV but getting INTER_NEAREST o/p.
  • Original image:
    img
    temp

  • OpenCV INTER_NEAREST:
    temp1

 cv2.resize(x,(0,0),fx=0.5,fy=0.5,interpolation=cv2.INTER_NEAREST)
  • OpenCV INTER_NEAREST_EXACT:
    temp2
 cv2.resize(x,(0,0),fx=0.5,fy=0.5,interpolation=cv2.INTER_NEAREST)
  • PIL :
    temp3
x1=Image.fromarray(img)
x1.thumbnail((256,256),Image.Resampling.NEAREST) 
  • scikit-image :
    temp5
rescale(x,0.5,order=0,preserve_range=True, anti_aliasing=False) 

As it can be seen, OpenCV INTER_NEAREST and OpenCV INTER_NEAREST_EXACT are matching, which is not expected.
image

The expected was that the OpenCV INTER_NEAREST_EXACT should match PIL and scikit-image o/p, but I am getting this difference:
image

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions