soft-matter / trackpy-examples

sample images, examples, and speed tests for trackpy
Other
21 stars 43 forks source link

walkthrough notebook: loading image sequence as greyscale raises NotImplementedError #8

Closed jeromefung closed 9 years ago

jeromefung commented 9 years ago

A colleague and I tried running the example notebook walkthrough.ipynb. However,

frames = pims.ImageSequence('../sample_data/bulk_water/*.png', as_grey=True)

results in a NotImplementedError: "I don't know how to convert an image of shaped (424, 640, 4) to greyscale. Write you own function and pass it using the process_func keyword argument."

The ImageSequence gets loaded correctly when I remove the as_grey kwarg. When I do that, each individual frame is RGBA, and frames[0].shape returns (424, 640, 4). (It looks like the actual image loading is being done by PIL via scikit-image.) Inspecting the _as_grey() method of FramesStream in base_frames.py in PIMS, it is clear that the presence of the alpha channel is raising the exception. Am I doing something wrong?

PIMS and TrackPy were freshly cloned from GitHub, and the unit tests for both pass (except for TrackPy tests related to HDF5 storage in TrackPy, since PyTables is not installed). I'm opening this issue here since I encountered the problem with the example notebook, but please feel free to move it to PIMS if that is more appropriate. Thanks in advance.

danielballan commented 9 years ago

Yep, I can reproduce this error. I will update the walkthrough shortly. In the meantime, here is a workaround:

def convert_to_gray(frame):
    "Very simple (not necessarily optimal) grayscale conversion"
    return frame[:, :, 0]  # take the red channel

frames = pims.ImageSequence('../sample_data/bulk_water/*.png', process_func=convert_to_gray)

The error is due to a change in PIMS. We should have better color support (and corresponding test coverage) in the next release of PIMS.

As a general note about the direction of trackpy: I'm investing some effort in the documentation in conjunction with writing my PhD thesis. I will configure our automated tests to run all our documented examples -- so this kind of thing shouldn't happen in the future.

danielballan commented 9 years ago

The underlying issue will be fixed in PIMS master shortly. See soft-matter/pims#117.

nkeim commented 9 years ago

Fix was merged.