ClementPinard / SfmLearner-Pytorch

Pytorch version of SfmLearner from Tinghui Zhou et al.
MIT License
1.01k stars 224 forks source link

Question about change from PIL to skimage #128

Closed nautilus-a closed 3 years ago

nautilus-a commented 3 years ago

Thank you for your excellent codes!

I have a question about your code changes.

Some PIL-based codes are changed to skimage as follows: https://github.com/ClementPinard/SfmLearner-Pytorch/commit/4e6b7e8b545f6e80c2714ba41231e5fafb1e803c

What is the main difference between skimage and PIL?

When I test those changes, I found slightly different results about RandomScaleCrop class of custom_transform.py.

some pixel values based on PIL (original code): [np.array(Image.fromarray(im.astype(np.uint8)).resize((scaled_w, scaled_h))).astype(np.float32) for im in images] image

some pixel values based on skimage results (changed code): [resize(im, (scaled_h, scaled_w)) for im in images] image

Which result is correct for resize operation?

Thank you!

ClementPinard commented 3 years ago

resize operation from PIL uses uint8 while skimage directly uses float. As such, it's normally more precise with skimage, albeit maybe a bit slower.

From the source code, skimage uses scipy's zoom function internally which is very similar to torch's interpolate : https://github.com/scikit-image/scikit-image/blob/dad624b0f1063d653a1d7e7beba080312cfd59b6/skimage/transform/_warps.py

nautilus-a commented 3 years ago

Thank you for your quick reply.

I always learn a lot from your source code.

Thanks!