From eaf25348ab1a3c1b26bab3bdd7dec9bf6492553d Mon Sep 17 00:00:00 2001 From: Johannes Friedrich Date: Wed, 2 Oct 2024 21:36:09 +0000 Subject: [PATCH] Add plot of ROI contours w/o IDs --- README.md | 2 +- code/extraction.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 40c438d..6fedacb 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ of the _registered_ (or, in the case of multi-plane imaging, _decrosstalked_) mo ## Output The main output is the `extraction.h5` file. -For QC, the figure `detected_ROIs.png` displays contours of the detected ROIs over a selection of summary images. +For QC, the figures `detected_ROIs.png` and `detected_ROIs_withIDs.png` display contours of the detected ROIs over a selection of summary images. If the capsule is run with the `--contour_video` argument, a 10x sped-up video is also created, showing ROI contours overlaid on the raw data, along with ROI activity and the remainder.
The `extraction.h5` file contains three groups: `traces`, `rois`, and `cellpose`, with the latter only present if Cellpose is used for detection (--anatomical_only ≠ 0). diff --git a/code/extraction.py b/code/extraction.py index 21691b1..7d2f93b 100644 --- a/code/extraction.py +++ b/code/extraction.py @@ -843,15 +843,12 @@ def contour_video( corr_img = max_corr_image(f["data"]) # plot x_size = 8.5 * max(dims[1] / dims[0], 0.4) - plt.figure(figsize=(x_size, 3)) + fix, ax = plt.subplots(1, 3, figsize=(x_size, 3)) for i, img in enumerate((ops["meanImg"], ops["max_proj"], corr_img)): - plt.subplot(1, 3, 1 + i) vmin, vmax = np.nanpercentile(img, (1, 99)) - plt.imshow(img, interpolation=None, cmap="gray", vmin=vmin, vmax=vmax) + ax[i].imshow(img, interpolation=None, cmap="gray", vmin=vmin, vmax=vmax) for c in coordinates: - plt.plot(*c["coordinates"].T, c="orange") - for k in range(rois.shape[0]): - plt.text(*cm[k], str(k), color="orange") + ax[i].plot(*c["coordinates"].T, c="orange") plt.axis("off") plt.title( ("mean image", "max image", "correlation image")[i], @@ -859,6 +856,10 @@ def contour_video( ) plt.tight_layout(pad=0.1) plt.savefig(output_dir / "detected_ROIs.png", bbox_inches="tight", pad_inches=0.02) + for i in (0, 1, 2): + for k in range(rois.shape[0]): + ax[i].text(*cm[k], str(k), color="orange") + plt.savefig(output_dir / "detected_ROIs_withIDs.png", bbox_inches="tight", pad_inches=0.02) if args.contour_video: with h5py.File(str(motion_corrected_fn), "r") as f: