ToReinberger / pyHeart4Fish

A heart beat analysis tool for zebrafish hearts
BSD 2-Clause "Simplified" License
5 stars 1 forks source link

Error with bright field analysis #3

Open greenm91 opened 1 month ago

greenm91 commented 1 month ago

Hi Tobias,

I am trying to quantify the heartbeat of 3dpf zebrafish using your bright field method. I have tested your fluorescent images and they work properly, however the bright field video I am trying to analyse is not working correctly.

This is the error message I am getting:

Frame parameter

Height (px): 1080.0 Width (px): 1920.0 frames per sec: 30.0 duration (sec): 13.9 Total number of images: 416

C_3dpf C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\venv\Lib\site-packages\numpy_core\fromnumeric.py:3596: RuntimeWarning: Mean of empty slice. return _methods._mean(a, axis=axis, dtype=dtype, C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\venv\Lib\site-packages\numpy_core_methods.py:138: RuntimeWarning: invalid value encountered in scalar divide ret = ret.dtype.type(ret / rcount) Traceback (most recent call last): File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\bright_field_whole_fish.py", line 763, in eye_center, eye_temp = find_fish_eye(image_matrix2.copy()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\bright_field_whole_fish.py", line 350, in find_fish_eye x_start = int(eyetemp[1]) - 260 ^^^^^^^^^^^^^^^^^ ValueError: cannot convert float NaN to integer bright_field_whole_fish.py "C:/Users/green/Videos/Test1\C_3dpf.avi" --output "C:/Users/green/Videos/Test1_Results" --name "Test1" --pixel_size 0.2 --cut_movie_at 10 --frames_per_sec 30 --image_counter 1/1 --skip_images 0 --file_format .avi

Write excel Exception in thread Thread-3 (run_program): Traceback (most recent call last): File "C:\Users\green\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1073, in _bootstrap_inner self.run() File "C:\Users\green\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1010, in run self._target(*self._args, *self._kwargs) File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\pyHeart4Fish_App.py", line 468, in run_program out2 = pd.concat([pd.read_csv(file) for file in glob.glob(output_folder + rf"*\.csv")]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\venv\Lib\site-packages\pandas\core\reshape\concat.py", line 382, in concat op = _Concatenator( ^^^^^^^^^^^^^^ File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\venv\Lib\site-packages\pandas\core\reshape\concat.py", line 445, in init objs, keys = self._clean_keys_and_objs(objs, keys) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\green\Documents\pyHeart4Fish\pyHeart4Fish_scripts\venv\Lib\site-packages\pandas\core\reshape\concat.py", line 507, in _clean_keys_and_objs raise ValueError("No objects to concatenate") ValueError: No objects to concatenate

I have taken a screenshot of a video frame to show you the video setup we have:

Screenshot 2024-08-06 153152

Any help you could provide would be greatly appreciasted!

Thank you!

Michael Green

ToReinberger commented 1 month ago

Hi Michael, thanks for reaching out! It appears that the script is not able to find the "fish eye" because the mask is too large, which should normally remove edge artifacts (which are not present in your videos). An easy way would be to out-command or delete line 334 in your source code:

image_matrix3[mask == 255] = np.max(image_matrix3)

code (line 328-344):

# create a mask
    x, y = np.ogrid[:len(image_matrix3), :len(image_matrix3[0])]
    mask = (x - int(len(image_matrix3) / 2)) ** 2 \
           + (y - int(len(image_matrix3[0]) / 2)) ** 2 > (len(image_matrix3) * 0.78) ** 2
    mask = 255 * mask.astype(int)

    image_matrix3[mask == 255] = np.max(image_matrix3)

    """corner = 100
    image_matrix3[:corner, :corner] = 30_000
    image_matrix3[:corner:, -corner:] = 30_000
    image_matrix3[-corner::, :corner] = 30_000
    image_matrix3[-corner:, -corner:] = 30_000"""

    eye_ = np.where(image_matrix3 < np.percentile(image_matrix3, 0.22))
    eye_ = np.asarray(eye_)
    eye_temp_ = [np.mean(eye_[0]), np.mean(eye_[1])]

How did you install pyHeart4Fish? is it possible for you to send a video to >tobias.reinberger@uni-luebeck,de< so that I can test it?

Please let me know if you need help again!

Best regards, Tobias