|
43 | 43 |
|
44 | 44 | # %%
|
45 | 45 | # 1: Retrieve probability map of a motor area in Julich-Brain
|
46 |
| -parc = siibra.parcellations.get("julich 3.0.3") |
47 |
| -region = parc.get_region("4p right") |
48 |
| -pmap = parc.get_map("mni152", "statistical").get_volume(region) |
| 46 | +region = siibra.get_region("julich 3.0.3", "4p right") |
| 47 | +region_map = siibra.get_map("julich 3.0.3", "mni152", "statistical").get_volume(region) |
49 | 48 |
|
50 | 49 | # %%
|
51 | 50 | # 2: Extract BigBrain 1 micron patches with high probability in this area
|
52 |
| -patches = siibra.features.get(pmap, "BigBrain1MicronPatch", lower_threshold=0.7) |
| 51 | +patches = siibra.features.get(region_map, "BigBrain1MicronPatch", lower_threshold=0.5) |
53 | 52 | print(f"Found {len(patches)} patches.")
|
54 | 53 |
|
55 | 54 | # %%
|
56 | 55 | # 3: Display highly rated samples, here further reduced to a predefined section
|
57 | 56 | section_num = 3556
|
58 |
| -candidates = filter(lambda p: p.bigbrain_section == section_num, patches) |
59 |
| -patch = next(iter(candidates)) |
| 57 | +candidates = [p for p in patches if p.bigbrain_section == section_num] |
| 58 | +patch = candidates[0] |
60 | 59 | plt.figure()
|
61 | 60 | plt.imshow(patch.fetch().get_fdata().squeeze(), cmap="gray", vmin=0, vmax=2**16)
|
62 | 61 | plt.axis("off")
|
|
76 | 75 | layername: plane.intersect_mesh(layermap.fetch(region=layername, format="mesh"))
|
77 | 76 | for layername in layermap.regions
|
78 | 77 | }
|
79 |
| -crop_voi = patch.section.intersection(pmap.get_boundingbox().zoom(0.35)) |
80 |
| -cropped_img = patch.section.fetch(voi=crop_voi, resolution_mm=0.2) |
| 78 | +ymin, ymax = [p[1] for p in patch.section.get_boundingbox()] |
| 79 | +crop_voi = siibra.BoundingBox((17.14, ymin, 40.11), (22.82, ymax, 32.91), 'bigbrain') |
| 80 | +cropped_img = patch.section.fetch(voi=crop_voi, resolution_mm=-1) |
81 | 81 | phys2pix = np.linalg.inv(cropped_img.affine)
|
82 | 82 |
|
83 | 83 | # The probabilities can be assigned to the contour vertices with the
|
84 | 84 | # probability map.
|
85 |
| -points = siibra.PointCloud( |
86 |
| - np.vstack( |
87 |
| - sum( |
88 |
| - [ |
89 |
| - [s.coordinates for s in contour.crop(crop_voi)] |
90 |
| - for contour in layer_contours["cortical layer 4 right"] |
91 |
| - ], |
92 |
| - [], |
93 |
| - ) |
94 |
| - ), |
95 |
| - space="bigbrain", |
| 85 | +points = siibra.PointCloud.union( |
| 86 | + *[c.intersection(crop_voi) for c in layer_contours["cortical layer 4 right"]] |
96 | 87 | )
|
97 |
| -probs = pmap.evaluate_points( |
98 |
| - points |
99 |
| -) # siibra warps points to MNI152 and reads corresponding PMAP values |
| 88 | +# siibra warps points to MNI152 and reads corresponding PMAP values |
| 89 | +probs = region_map.evaluate_points(points) |
100 | 90 | img_arr = cropped_img.get_fdata().squeeze().swapaxes(0, 1)
|
101 | 91 | plt.imshow(img_arr, cmap="gray", origin="lower")
|
102 | 92 | X, Y, Z = points.transform(phys2pix).coordinates.T
|
103 |
| -plt.scatter(X, Z, s=2, c=probs) |
104 |
| -for p in patch.profile: |
105 |
| - x, y, z = p.transform(phys2pix) |
106 |
| - plt.plot(x, z, "r.", ms=3) |
| 93 | +plt.scatter(X, Z, s=10, c=probs) |
| 94 | +prof_x, _, prof_z = zip(*[p.transform(phys2pix) for p in patch.profile]) |
| 95 | +plt.plot(prof_x, prof_z, "r", lw=2) |
107 | 96 | plt.axis("off")
|
108 | 97 |
|
109 | 98 | # %%
|
|
119 | 108 | pixels = segment.transform(phys2pix, space=None).homogeneous
|
120 | 109 | plt.plot(pixels[:, 0], pixels[:, 2], "-", ms=4, color=layercolor)
|
121 | 110 |
|
122 |
| -# plot the profile points |
123 |
| -for p in patch.profile: |
124 |
| - x, y, z = p.transform(phys2pix, space=None) |
125 |
| - plt.plot(x, z, "r.", ms=3) |
126 |
| - |
| 111 | +# plot the profile |
| 112 | +plt.plot(prof_x, prof_z, "r", lw=2) |
127 | 113 | plt.axis("off")
|
128 | 114 |
|
129 | 115 | # sphinx_gallery_thumbnail_number = -2
|
0 commit comments