Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential to update utils.resize and edge-pixel corner case #138

Open
rossbar opened this issue Jan 13, 2023 · 0 comments
Open

Potential to update utils.resize and edge-pixel corner case #138

rossbar opened this issue Jan 13, 2023 · 0 comments
Labels
chore Maintenance question Further information is requested

Comments

@rossbar
Copy link
Contributor

rossbar commented Jan 13, 2023

utils.resize branches internally calling cv2.resize for single-channel data and skimage.transforms.resize for multichannel data. Comments indicate this was done because cv2 didn't support multichannel input, but it does now. There are two potential paths for improvement:

  1. Refactor utils.resize to always use cv2, which is 50-100x faster.
  2. Refactor utils.resize to always use skimage, which would remove the opencv dependency from the deepcell libraries.

If utils.resize is used frequently in pre/post processing, then option 1 makes the most sense.

While digging around I also noticed that there is a discrepancy in the values of boundary pixels between the two methods:

from skimage import transform
import cv2
rng = np.random.default_rng()
img = rng.random((32, 32))
out_shape = (40, 40)
# These parameters generally match the defaults of `utils.resize`
rs_cv = cv2.resize(img, out_shape, interpolation=cv2.INTER_LINEAR)
rs_sk = transform.resize(
    img, out_shape, mode="constant", preserve_range=True, order=1, anti_aliasing=True
)
plt.imshow(rs_cv - rs_sk)
plt.colorbar()

imdiff

There's no difference (within floating point precision) for the central pixels, but the discrepancy for edge pixels is significant. This may affect any workflows where single-channel and multi-channel images are used together.

@rossbar rossbar added question Further information is requested chore Maintenance labels Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Maintenance question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant