-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 3 commits
bacf849
4015ab0
c6bb725
59bc455
4db8a0e
8770c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
// This macro opens the head image stack and reslices it to view it from different angles (side, front, top and diagonal view) | ||
// and then selects slices corresponding to Z=60, X=135, and Y=160. | ||
// Close other open images | ||
run("Close All"); | ||
// open image stack | ||
open("https://github.com/NEUBIAS/training-resources/raw/master/image_data/xyz_16bit_calibrated__dna_metaphase.tif"); | ||
|
||
// open head image stack | ||
open("http://imagej.net/images/t1-head.zip"); | ||
rename("Head viewed from the side"); | ||
run("Duplicate...", "duplicate range=60"); | ||
rename("Head Z=60"); | ||
// explore the dimensions | ||
width = getWidth(); | ||
height = getHeight(); | ||
depth = nSlices(); | ||
print("Original Image Dimensions: Width = " + width + ", Height = " + height + ", Depth = " + depth); | ||
|
||
// Reslice the head image stack to view the head from the front and from the top, and select the slices for X=135 and Y=160 in the orginal view. | ||
selectWindow("Head viewed from the side"); | ||
run("Reslice [/]...", "output=1.500 start=Left rotate"); // view head from the front | ||
rename("Head viewed from the front"); | ||
run("Duplicate...", "duplicate range=135-135"); | ||
rename("Head X=135"); | ||
// reslice YZ with interpolation | ||
run("Reslice [/]...", "output=0.300 start=Left flip rotate"); | ||
rename("YZ view"); | ||
width = getWidth(); | ||
height = getHeight(); | ||
depth = nSlices(); | ||
print("Image Dimensions YZ view: Width = " + width + ", Height = " + height + ", Depth = " + depth); | ||
|
||
selectWindow("Head viewed from the side"); | ||
run("Reslice [/]...", "output=1.500 start=Top rotate"); // view head from the top | ||
rename("Head viewed from the top"); | ||
run("Duplicate...", "duplicate range=160-160"); | ||
rename("Head Y=160"); | ||
// reslice XZ with interpolation | ||
selectImage("xyz_16bit_calibrated__dna_metaphase.tif"); | ||
run("Reslice [/]...", "output=0.300 start=Top"); | ||
rename("XZ view"); | ||
width = getWidth(); | ||
height = getHeight(); | ||
depth = nSlices(); | ||
print("Image Dimensions XZ view: Width = " + width + ", Height = " + height + ", Depth = " + depth); | ||
|
||
// Rotate the head stack that is viewed from the side and reslice to obtain diagonal view | ||
selectWindow("Head viewed from the side"); | ||
run("Duplicate...", "duplicate"); | ||
run("Rotate... ", "angle=45 grid=1 interpolation=Bilinear enlarge stack"); // rotate the stack | ||
run("Reslice [/]...", "output=1.500 start=Top rotate"); | ||
rename("Head in diagonal view"); | ||
// reslice YZ without interpolation | ||
selectImage("xyz_16bit_calibrated__dna_metaphase.tif"); | ||
run("Reslice [/]...", "output=0.300 start=Left flip rotate avoid"); | ||
rename("YZ view"); | ||
width = getWidth(); | ||
height = getHeight(); | ||
depth = nSlices(); | ||
print("Image Dimensions YZ view WITHOUT interpolation: Width = " + width + ", Height = " + height + ", Depth = " + depth); | ||
|
||
run("Tile"); | ||
// reslice XZ with interpolation | ||
selectImage("xyz_16bit_calibrated__dna_metaphase.tif"); | ||
run("Reslice [/]...", "output=0.300 start=Top avoid"); | ||
rename("XZ view"); | ||
width = getWidth(); | ||
height = getHeight(); | ||
depth = nSlices(); | ||
print("Image Dimensions XZ view WITHOUT interpolation: Width = " + width + ", Height = " + height + ", Depth = " + depth); | ||
|
||
run("Tile") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# !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 commentThe reason will be displayed to describe this comment to others. Learn more. maybe better |
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oops |
||
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 commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then the latter would be the best, imho. |
||
print("New voxel dimensions scaled relative to original", scaled_voxel_dims) | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. while |
||
mid_y_slice_ind = shape[1] // 2 | ||
mid_x_slice_ind = shape[2] // 2 | ||
|
||
viewer.add_image(d[mid_z_slice_ind], name=f"z={mid_z_slice_ind}") | ||
viewer.add_image(d[mid_z_slice_ind], name=f"scaled: z={mid_z_slice_ind}", scale = scaled_voxel_dims[1:]) | ||
viewer.add_image(d[:, mid_y_slice_ind, :], name=f"y={mid_y_slice_ind}") | ||
viewer.add_image(d[:, mid_y_slice_ind, :], name=f"scaled: y={mid_y_slice_ind}", scale = [scaled_voxel_dims[0], scaled_voxel_dims[2]]) | ||
viewer.add_image(d[:, :, mid_x_slice_ind], name=f"x={mid_x_slice_ind}") | ||
viewer.add_image(d[:, :, mid_x_slice_ind], name=f"scaled: x={mid_x_slice_ind}", scale = scaled_voxel_dims[:2]) | ||
|
||
# View in grid mode side by side | ||
viewer.grid.stride = 1 | ||
viewer.grid.shape = (-1, 2) | ||
viewer.grid.enabled=True |
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" ?