-
Notifications
You must be signed in to change notification settings - Fork 21
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
Volume slicing refactoring #630
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot @AnniekStok!
I made a few minor suggestions.
// and then selects slices corresponding to Z=60, X=135, and Y=160. | ||
// Close other open images | ||
run("Close All"); | ||
// open image stack |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure "stack" is the best word...
maybe "open volumetric image" or "open 3D image" ?
# !First start Napari and drag and drop the image (https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyz_16bit_calibrated__dna_metaphase.tif) in the Napari viewer. | ||
|
||
# Access the 3D array in the image layer | ||
d = viewer.layers[0].data # assuming the image is in the first layer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe better image
instead of d
?
shape = d.shape | ||
print("Image shape:", shape) | ||
|
||
# Compare the non-scaled non-scaled image to the scaled image. You can also use the 3D view to better appreciate the dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
non-scaled non-scaled :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops
|
||
# Compare the non-scaled non-scaled image to the scaled image. You can also use the 3D view to better appreciate the dimensions. | ||
voxel_dims = (0.300, 0.1377745, 0.1377745) # original voxel dimensions in µm, in order ZYX | ||
scaled_voxel_dims = [1 / voxel_dims[0] * v for v in voxel_dims] # rescaling the voxel dimensions to maintain proportions but display with a z-step of 1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to avoid fancy python such as list comprehension...
Would that also work?
scaled_voxel_dims = voxel_dims / voxel_dims[0]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gives an error: "unsupported operand type(s) for /: 'tuple' and 'float'" (also with list), but we could do this instead:
scale_factor = 1 / voxel_dims[0]
scaled_voxel_dims = [voxel_dims[0] * scale_factor, voxel_dims[1] * scale_factor, voxel_dims[2] * scale_factor]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the latter would be the best, imho.
viewer.add_image(d, name="Scaled to physical world dimensions", scale=scaled_voxel_dims) # Note that the scaled image layer contains the exact same data as the non-scaled image, but is only visualized differently to show the correct proportions. | ||
|
||
# Create 2D slices (YX, ZX, and ZY) | ||
mid_z_slice_ind = shape[0] // 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while // 2
is cool maybe doing a floating point division and then casting to integer could be more explicit for beginners?
Thanks for your comments @tischi! I have incorporated them. |
Hi @AnniekStok, somehow I can't see the new changes...maybe due to the above "conflicts"? |
Yes I think I had a small unpulled change in my local version. I resolved the conflicts now. |
Thanks so much! |
Proposal for refactoring the Volume Slicing module based on discussion in #613, replacing the ImageJ macro 'head' example with the metaphase image, removing the Jython exercise and adding a python-napari example.