-
Notifications
You must be signed in to change notification settings - Fork 7
[napari-workflows] Support 2D processing #149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@tcompa What would this mean? In general: Our data may be 2 or 3 dimension and we should be able to run workflows on either. What extra handling was required for measurements for the 2D case? |
Sorry, I made it a bit too brief.. The current # Check whether data are 2D or 3D, and squeeze arrays if needed
is_2D = img.shape[0] == 1
if is_2D:
img = img[0, :, :]
label_img_up = label_img_up[0, :, :] and then for i_ROI, indices in enumerate(list_indices):
s_z, e_z, s_y, e_y, s_x, e_x = indices[:]
ROI = (slice(s_z, e_z), slice(s_y, e_y), slice(s_x, e_x))
if is_2D:
if not (s_z, e_z) == (0, 1):
raise Exception("Something went wrong with 2D ROI ", ROI)
ROI = (slice(s_y, e_y), slice(s_x, e_x)) This is to enable measurement on MIP images/labels, since we always store data as a 3D array (with a dummy Z dimension) but I'm just checking, but my reasonable guess is that:
|
Yes, we should have the same logic in the wrapper, that makes sense :)
Hmm... Generally agree for most workflows. But there are some workflows that could take in a 3D image and return a 2D label map. And for flexibility, it would be good to accept pipelines that take in e.g. the MIP image, but can produce the segmentation for the whole 3D image (not that should be a workflow used often, but maybe someone needs their 2D segmentation saved in 3D for down-the-road processing?). Both those scenarios should be somewhat of an exception. We can default to not doing this behavior, but allow users to do it somehow? Also, while we are not tackling time-data yet, maybe we should start thinking about this topic for such design decisions. Eventually, we will also process time-resolved data, so data may be 2D, 3D, 4D or e.g. 2D + time (=> 3 actual dimensions, but maybe saved as 4D with Z dimension = 1) |
Let's keep this issue about 2D napari_workflows, and move the broader discussion e.g. to #150 |
The first possible solution (not necessarily the best) would to include this information in the input/output specs for this wrapper task. The behavior would be this one:
How does that sound? To me it looks reasonable, but I'm not yet sure it covers all use cases. |
I conceptually like this. But is there a way to know whether a function will want a 2D or 3D image? Most numpy/scikit image functions can handle both after all... If it's reasonably possible to do this check, awesome, let's go with that!
That would be a good check to make. Given that we store everything as 3D (with a Z dim of 1 if it's 2D data only, right?), it would just mean potentially adding the dummy Z dimension, right?
Good point actually. I implicitly decided that this should be out-of-scope for the moment. Theoretically, I can see a use for it and we may want to tackle this eventually. e.g. one could do illumination correction via napari workflows in theory. But I'm hesitant about this, it could get quite messy either adding many new image channels through workflows. Thus, at the moment, we only allow label outputs (they are compressed very well and clearly separate from the channels) and dataframe outputs. |
I tried to virtually explore all branches for I/O dimensionality handling, based on this discussion, and I am putting my most up-to-date proposed solution below. Comments are always welcome, and I'll refrain from any implementation until we reach some roughly precise definition. Image outputsThis one is easy: they are currently out of scope. Image/label inputsFor each image/label input, we may add an
In this way, for instance, we could prepare a workflow that also measures perimeter (for MIP images/labels), and make sure that we only run it on 2D inputs.
Not all napari-workflows are fully general in the input dimensionality, and then I guess that if we don't set this Note 1The proposed solution is equivalent to my expectation for @jluethi's Note 2The discussion seems to lead to a choice of not enforcing any additional constraint like "all inputs/outputs should have the same dimensionality". We would then allow mixed-dimensionality workflows. If some inputs are combined within a workflow (e.g. when doing the difference between two image arrays) and they have a shape-mismatch which cannot be handled, then it's up to the napari-workflow/scikit-image/numpy functions to raise an error. Label outputsAlso for
NoteIn the case of outputs, we could also decide that this handling is done automatically (without any |
Thanks for the great overview! Adding additional parameters makes things more complex, but reading this, I'd say I'm fine with adding the
I don't think we can know which workflows would require which dimensionality. The user could basically put any dask graph chaining relevant function calls together into a napari workflow. I think for the time being, we assume the user created the workflow on the same data modality that they load in.
I think it will mostly be used as a global parameter like level. Not forcing it to be global does give potential extra flexibility though, e.g. loading a 2D label mask and then 3D images. We currently couldn't really do this (because we have the MIPs in a separate OME-Zarr file), but it would make sense to have them in the same OME-Zarr file eventually (though I have not yet figured out what the right way of combining them would be).
I think we can skip this, the user shouldn't be concerned with that part, because the only thing the choice can do is trigger an error when the wrong choice is made. |
All right, then I will proceed as discussed. |
I propose a new change to how we are implementing this. Both for This would mean that a workflow either works on 2D image/label arrays, or on 3D image/label arrays (note that dataframes don't have a dimensionality). Everything is always written to disk as 3D (the zarr structure we support, at the moment), but the global parameter This would obviously simplify things a bit. @jluethi: any feedback on this? Should we (already) support mixed-dimensions workflows? |
Hmm, a bit of a tricky question. => The simplification would make sense for the current setup, but we may eventually need this complexity in some edge-cases |
Ok, thanks. |
Ok, let's see if it comes up as a limitation when we process mixed 2D vs 3D workflows then :) |
In
measurement
, we had implemented some (preliminary?) handling of 2D data. Should this also be generally available innapari_workflows_wrapper
?The text was updated successfully, but these errors were encountered: