Resize mask should not use nearest method of opencv
See original GitHub issueI’m using this project to train my segmentation model. I find that the mask has a right-down offset to the image. Because the opencv resize_nearest is wrong. Please refer the opencv project issue:
https://github.com/opencv/opencv/issues/9096
https://github.com/opencv/opencv/issues/10146
The code of opencv is:
for( x = 0; x < dsize.width; x++ ) { int sx = cvFloor(x*ifx); x_ofs[x] = std::min(sx, ssize.width-1)*pix_size; }
It’s not the nearest, so it will be a offset between image and mask.
Mask uses the resize nearest in Pillow has no offset to the image. Using the resize nearest of opencv to train segmentation model will have a bad result.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:11 (2 by maintainers)
Top Results From Across the Web
python - How to resize a labeled mask with nearest neighbor ...
It is very important to use 'nearest neighbor' interpolation when resizing segmentation masks. Does anyone know how to do this with scikit-image ...
Read more >Image Resizing with OpenCV - LearnOpenCV
Come, let's learn about image resizing with OpenCV. To resize an image, scale it along each axis (height and width), considering the specified...
Read more >OpenCV Resize Image ( cv2.resize ) - PyImageSearch
In this tutorial, you will learn how to resize an image using OpenCV and the cv2.resize function.
Read more >Geometric Image Transformations - OpenCV
Resizes an image. ... They do not change the image content but deform the pixel grid and map ... In this case, an...
Read more >Different Interpolation methods in OpenCV - OpenGenus IQ
In OpenCV Python, Interpolation method is used while resizing an image as ... Unlike INTER_NEAREST, this does the interpolation in two dimensions and ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I do agree that we need a way to fix the current behavior of OpenCV’s nearest interpolation that we use for masks.
However, we need a way to inform the current users of different behaviors of
cv2.INTER_NEAREST
andcv2.INTER_NEAREST_EXACT
and let them choose the one they prefer. By following this path, we will not introduce a sudden significant change that will break the current behavior of augmentation pipelines (even if the current behavior is not optimal and may be seen as ‘buggy’, it is still how Albumentations resizes masks since the first release).So my proposal is the following:
A.Compose
, e.g.cv2.INTER_NEAREST_EXACT
instead ofcv2.INTER_NEAREST
for mask interpolation, and to preserve the old behavior, the user must explicitly specify the mask interpolation method for an augmentation pipeline. Let’s make a separate article in the documentation that tells the difference between those interpolation methods.cv2.INTER_NEAREST_EXACT
, but still, show a warning if the user didn’t specify the interpolation method and Albumentations used the default value.Can I try to fix it?
On Tue, Aug 17, 2021, 10:20 PM Mikhail Druzhinin @.***> wrote: