seung-lab / euclidean-distance-transform-3d

Euclidean distance & signed distance transform for multi-label 3D anisotropic images using marching parabolas.
GNU General Public License v3.0
234 stars 37 forks source link

Different running time for running the same code #35

Closed chxii closed 3 years ago

chxii commented 3 years ago

Hello, I was trying to do some simple testing using this package. I ran edt.edt() twice on the same image, but the running time seems quite different.

import edt
import time

# image_array is a 3D binary numpy array of shape (242, 512, 512), read from nii file using SimpleITK

start_time = time.time()
dt1 = edt.edt(image_array, parallel=1)
print("first time edt: ", time.time() - start_time)  # first time edt:  7.87526

start_time = time.time()
dt2 = edt.edt(image_array, parallel=1)
print("second time edt: ", time.time() - start_time)  # second time edt:  2.08331

I was running this code using Python 3.6.9, numpy 1.18.0, edt 2.1.0, on Ubuntu 18.04.4. I thought running the same function would give similar runtime, but I'm not sure if I'm doing this right...

william-silversmith commented 3 years ago

Hi, that's pretty odd. It's possible you warmed up a cache but I don't think I'd expect such a huge difference.

If you'd like to inspect the 3D volume to see if it looks right, you can try:

$ pip install cloud-volume

Then in your code, try:

from cloudvolume import view
view(dt1)
view(dt2)

This will open a local webserver that you can use a browser to connect to and look at the volume in using a 3D slice viewer based on https://github.com/seung-lab/data-cube-x

chxii commented 3 years ago

I have done multiple tests on this issue. Here's what I have found:

I still don't know the exact reason, and this doesn't affect the correct result, so this might not be a problem. I couldn't provide my testing data because of the privacy policy of the medical data. For most of the data, I didn't find this situation. Thanks for your great package, and thank you for the reply!