Skip to content
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

Merged
merged 6 commits into from
Mar 19, 2024
Merged

Volume slicing refactoring #630

merged 6 commits into from
Mar 19, 2024

Conversation

AnniekStok
Copy link
Collaborator

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.

@AnniekStok AnniekStok changed the title Volume slicing anniek Volume slicing refactoring Mar 14, 2024
Copy link
Collaborator

@tischi tischi left a 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
Copy link
Collaborator

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
Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-scaled non-scaled :)

Copy link
Collaborator Author

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.
Copy link
Collaborator

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]

Copy link
Collaborator Author

@AnniekStok AnniekStok Mar 18, 2024

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]

Copy link
Collaborator

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
Copy link
Collaborator

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?

@AnniekStok
Copy link
Collaborator Author

Thanks for your comments @tischi! I have incorporated them.

@tischi
Copy link
Collaborator

tischi commented Mar 19, 2024

Hi @AnniekStok, somehow I can't see the new changes...maybe due to the above "conflicts"?

@AnniekStok
Copy link
Collaborator Author

Yes I think I had a small unpulled change in my local version. I resolved the conflicts now.

@tischi
Copy link
Collaborator

tischi commented Mar 19, 2024

Thanks so much!

@tischi tischi merged commit 43fe671 into master Mar 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants