|
| 1 | +import itertools |
1 | 2 | import matplotlib.pyplot as plt
|
2 | 3 |
|
3 | 4 | from cryoet_data_portal_neuroglancer.io import load_omezarr_data
|
|
9 | 10 |
|
10 | 11 | FILEPATH = r"/media/starfish/LargeSSD/data/cryoET/data/0004_image/Tomograms/VoxelSpacing13.48/CanonicalTomogram/TS_0004.zarr"
|
11 | 12 |
|
12 |
| -dask_data = load_omezarr_data(FILEPATH, resolution_level=2) |
| 13 | +dask_data = load_omezarr_data(FILEPATH, resolution_level=1) |
13 | 14 | data_array = dask_data.compute()
|
14 |
| -contrast_calculator = ContrastLimitCalculator(data_array) |
15 |
| -contrast_calculator.set_volume_and_z_limits(data_array, central_z_slice=10, z_radius=5) |
16 |
| -contrast_limits = contrast_calculator.contrast_limits_from_percentiles(0.0, 100.0) |
17 |
| -print(contrast_limits) |
18 | 15 |
|
19 |
| -rendered_mem, image_shape = volume_render( |
20 |
| - data_array, contrast_limits=contrast_limits, depth_samples=256 |
21 |
| -) |
22 |
| -volume_rendered_image = np.ndarray( |
23 |
| - image_shape, dtype=np.float32, buffer=rendered_mem.buf |
24 |
| -) |
| 16 | +# def rms(data): |
| 17 | +# return np.sqrt(np.mean(data**2)) |
| 18 | + |
| 19 | + |
| 20 | +# standard_deviation_per_z_slice = np.std(data_array, axis=(1, 2)) |
| 21 | +# standard_deviation_per_z_slice = np.nan_to_num( |
| 22 | +# standard_deviation_per_z_slice, copy=False |
| 23 | +# ) |
| 24 | +# for i, std in enumerate(standard_deviation_per_z_slice): |
| 25 | +# print(f"Standard deviation for z-slice {i}: {std:.2f}") |
| 26 | + |
| 27 | +# lowest_points = find_peaks(-standard_deviation_per_z_slice, prominence=0.1) |
| 28 | +# print(lowest_points) |
| 29 | + |
| 30 | +# fig, ax = plt.subplots() |
| 31 | +# ax.plot(standard_deviation_per_z_slice) |
| 32 | +# ax.set_xlabel("Z-slice") |
| 33 | +# ax.set_ylabel("Standard deviation") |
| 34 | +# plt.show() |
| 35 | + |
| 36 | +# exit(-1) |
| 37 | + |
| 38 | +contrast_calculator = ContrastLimitCalculator() |
| 39 | + |
| 40 | +percentile_thresholds = [(0.0, 100.0), (45.0, 99.5), (5.0, 95.0)] |
| 41 | +for (low_percentile, high_percentile), clip in itertools.product( |
| 42 | + percentile_thresholds, [True, False] |
| 43 | +): |
| 44 | + contrast_calculator.volume = data_array |
| 45 | + if clip: |
| 46 | + contrast_calculator.trim_volume_around_central_zslice() |
| 47 | + |
| 48 | + contrast_limits = contrast_calculator.contrast_limits_from_percentiles( |
| 49 | + low_percentile, high_percentile |
| 50 | + ) |
| 51 | + |
| 52 | + rendered_mem, image_shape = volume_render( |
| 53 | + data_array, contrast_limits=contrast_limits, depth_samples=256 |
| 54 | + ) |
| 55 | + volume_rendered_image = np.ndarray( |
| 56 | + image_shape, dtype=np.float32, buffer=rendered_mem.buf |
| 57 | + ) |
25 | 58 |
|
26 |
| -try: |
27 |
| - # Save the RGBA image |
28 |
| - print("Saving the volume rendered image to volume_rendered_image.png") |
29 |
| - plt.imsave("volume_rendered_image.png", volume_rendered_image) |
30 |
| - del volume_rendered_image |
31 |
| -except Exception as e: |
32 |
| - print(f"Error saving the volume rendered image: {e}") |
33 |
| -finally: |
34 |
| - rendered_mem.close() |
35 |
| - rendered_mem.unlink() |
| 59 | + try: |
| 60 | + # Save the RGBA image |
| 61 | + print( |
| 62 | + f"Saving volume rendered image with contrast limits {contrast_limits} and clipping {clip}" |
| 63 | + ) |
| 64 | + clip_string = "clipped" if clip else "unclipped" |
| 65 | + plt.imsave( |
| 66 | + f"volume_rendered_image_{low_percentile}_{high_percentile}_{clip_string}_{contrast_limits[0]:.2f}_{contrast_limits[1]:.2f}.png", |
| 67 | + volume_rendered_image, |
| 68 | + ) |
| 69 | + del volume_rendered_image |
| 70 | + except Exception as e: |
| 71 | + print(f"Error saving the volume rendered image: {e}") |
| 72 | + finally: |
| 73 | + rendered_mem.close() |
| 74 | + rendered_mem.unlink() |
0 commit comments