pyfli.phasor.phasorS.phasor_clustering#
Convert phasor images to feature matrices and back for PCA, clustering and LDA.
Functions
|
|
|
|
|
Legend of colors (from |
|
Rename cluster ids so they best match reference labels (Hungarian assignment on the contingency table). |
|
Per-cluster summary of a first-harmonic phasor image: pixel count, mean |
|
Fraction of pixels whose (aligned) cluster matches the reference label. |
|
Read a label (e.g. the ground-truth region id) for every pixel in pixels. |
|
Place per-pixel labels at their pixels coordinates in an image of shape. |
|
|
|
One feature row per pixel from multi-harmonic phasor coordinates. |
|
Bar chart of per-component explained-variance ratio with the cumulative curve. |
|
Scatter of the first two columns of scores (PCA or LDA projections), colored by labels when given. |
- phasor_feature_matrix(G, S, mask=None, harmonics=(1,), polar=False, extra_maps=None)[source]#
One feature row per pixel from multi-harmonic phasor coordinates.
- Parameters:
G (
np.ndarray) – Phasor coordinates,(n_harmonics, H, W)or(H, W).S (
np.ndarray) – Phasor coordinates,(n_harmonics, H, W)or(H, W).mask (
np.ndarray | None) – Pixels to use ((H, W)boolean); default all. Pixels with any non-finite feature are dropped as well.harmonics (
iterableofint) – 1-based harmonics to include.polar (
bool) – Use phaseatan2(S, G)and modulationsqrt(G^2 + S^2)instead ofG/S.extra_maps (
dict[str,np.ndarray] | None) – Additional(H, W)maps appended as features (e.g.{"log_intensity": np.log1p(decay.sum(-1))}).
- Returns:
(X, pixels, names): features(n_pixels, n_features), the(row, col)coordinates of every row, and the feature names.- Return type:
tuple[np.ndarray,np.ndarray,list[str]]
- labels_to_image(labels, pixels, shape, fill=-1)[source]#
Place per-pixel labels at their pixels coordinates in an image of shape.
- image_to_labels(label_map, pixels)[source]#
Read a label (e.g. the ground-truth region id) for every pixel in pixels.
- align_labels(predicted, reference)[source]#
Rename cluster ids so they best match reference labels (Hungarian assignment on the contingency table). Cluster ids are arbitrary; this makes them comparable with ground truth. Returns
(aligned_labels, mapping); clusters without a partner keep their own id.
- clustering_accuracy(predicted, reference)[source]#
Fraction of pixels whose (aligned) cluster matches the reference label.
- cluster_summary(G1, S1, label_map, phasor, param_maps=None, background=-1, intensity=None)[source]#
Per-cluster summary of a first-harmonic phasor image: pixel count, mean
G/S, the phase and modulation lifetimes of the cluster-mean phasor – computed with the givenpyfli.phasor.phasorS.PhasorAnalyzer(compute_lifetime/compute_modulation_lifetime) – and the mean of every map in param_maps (e.g. the simulator’s ground-truth maps) inside the cluster. Pixels labelled background are ignored.By default every pixel counts equally. Pass the photon-count image as intensity to weight the mean phasor by photons instead: it is then exactly the phasor of the cluster’s summed decay (phasors add with intensity weights).
- labels_to_rgb(label_map, background=-1)[source]#
(H, W, 3)RGB image with one categorical color per label (background black), and the{label: color}legend. Pass the image ascolors=topyfli.phasor.phasorS.PhasorAnalyzer.plot_phasor_diagram()to color the phasor points by cluster, or show it withimshow.
- add_label_legend(ax, colors, title=None, loc='upper right')[source]#
Legend of colors (from
labels_to_rgb()) on ax, placed at loc.