Skip to content

Commit

Permalink
Update image feature matching plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
Yu-AnChen committed Sep 15, 2023
1 parent ae38179 commit 6cb4477
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
21 changes: 21 additions & 0 deletions palom/cli/align_he.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ def align_he(
test_intensity_invert=True,
auto_mask=auto_mask
)
fig, ax = plt.gcf(), plt.gca()
fig.suptitle(f"{p2.name} (coarse alignment)", fontsize=8)
ax.set_title(f"{p1.name} - {p2.name}", fontsize=6)
im_h, im_w = ax.images[0].get_array().shape
set_subplot_size(im_w/288, im_h/288, ax=ax)
ax.set_anchor('N')
# use 0.5 inch on the top for figure title
fig.subplots_adjust(top=1 - .5 / fig.get_size_inches()[1])
save_all_figs(out_dir=out_dir / 'qc', format='jpg', dpi=144)

if viz_coarse_napari:
_ = viz_coarse(r1, r2, LEVEL, LEVEL, channel1, channel2, aligner.affine_matrix)
Expand Down Expand Up @@ -195,6 +204,18 @@ def save_all_figs(dpi=300, format='pdf', out_dir=None, prefix=None):
plt.close(f)


def set_subplot_size(w, h, ax=None):
""" w, h: width, height in inches """
if not ax: ax=plt.gca()
l = ax.figure.subplotpars.left
r = ax.figure.subplotpars.right
t = ax.figure.subplotpars.top
b = ax.figure.subplotpars.bottom
figw = float(w)/(r-l)
figh = float(h)/(t-b)
ax.figure.set_size_inches(figw, figh)


if __name__ == '__main__':
import fire
import sys
Expand Down
14 changes: 11 additions & 3 deletions palom/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import scipy.fft
import skimage.feature
import skimage.registration
import skimage.exposure

from . import img_util, register_util

Expand Down Expand Up @@ -229,14 +230,21 @@ def ensambled_match(
maxIters=5000
)
if plot_match_result == True:
plt.figure()
plt.gray()
_, ax = plt.subplots()
skimage.feature.plot_matches(
plt.gca(), img_left, img_right,
ax,
np.log(skimage.exposure.rescale_intensity(img_left, out_range=(1, 4095))),
np.log(skimage.exposure.rescale_intensity(img_right, out_range=(1, 4095))),
np.fliplr(all_src), np.fliplr(all_dst),
np.arange(len(all_src)).repeat(2).reshape(-1, 2)[mask.flatten()>0],
keypoints_color=np.divide([255, 215, 0, 50], 255),
matches_color='deepskyblue',
only_matches=False
)
for line in ax.get_lines():
line.set_alpha(0.5)
line.set_linewidth(.5)

return (t_matrix, mask) if return_match_mask else t_matrix


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "palom"
version = "2023.8.2"
version = "2023.9.1"
description = "Piecewise alignment for layers of mosaics"
authors = ["Yu-An Chen <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 6cb4477

Please sign in to comment.