soft-matter / trackpy

Python particle tracking toolkit
http://soft-matter.github.io/trackpy
Other
445 stars 131 forks source link

'UserWarning: Image is completely black' on valid image. #667

Open b-grimaud opened 3 years ago

b-grimaud commented 3 years ago

I am using ImageIO to read .tif files that were converted from .czi using ImageJ. When processing them through tp.batch, I get the following warning : C:\ProgramData\Anaconda3\envs\IIIVII\lib\site-packages\trackpy\find.py:112: UserWarning: Image is completely black. warnings.warn("Image is completely black.", UserWarning) As I understand it, def percentile_threshold(image, percentile): checks wether any part of the array is empty not_black = image[np.nonzero(image)], and if there are any, it returns that warning later on. However, I checked each individual frame of the stack I'm processing, and none of them are, indeed, completely black.

Could this be a bug, or is there something wrong with my data ?

nkeim commented 3 years ago

That is unusual. Have you checked that you get the warning when running e.g. percentile_threshold(image, 64)? And, what do some actual grey values from your image look like—can you provide some pixel values, or min, max, and median?

This could be a case of preprocessing gone awry, possibly in the scale_to_gamut and convert_to_int functions. It might be helpful to also know what arguments you are using with batch.

b-grimaud commented 3 years ago

I have run percentile_threshold(image, 64) in my frame per frame loop, and all of them return 45.0. The warning only shows up when calling locate. Here's the ImageJ histogram of the stack I'm processing :

histogram

The actual dimensions of the image are 1200x107. I'm running locate with a diameter of 7, a minmass of 150, and a separation of 10, preprocess=True and engine='numba'. I get this warning pretty inconsistently, depending on the parameters I use and the number of frames I process. So far I've only encountered it using the dataset I'm currently working with, and coincidentally it's also much harder to extract proper trajectories from those stacks than with other datasets, which is what made me wonder if there was something wrong with the data itself, initially. I've also had this issue with both TrackPy 0.5.0 and 0.4.2, if that can be of any help.

nkeim commented 3 years ago

Thanks. The ImageJ histogram and min/max look reasonable, so I would next check the stats for the numpy array as passed to trackpy. You know that matplotlib can display the image correctly, but trackpy uses different logic in the scale and convert functions I named above.