好的,所以我有一个GUI,我想在其中显示颜色通道A和B,以及覆盖层C。
我想通过简单的范围裁剪手动调整对比度(基本上像其他人一样通过强度直方图和两个垂直条)。
要显示A和B,我只需将它们剪裁并塞入imshow
中。为了混合它们,我目前使用“屏幕”方法,以查看斑点重叠的位置。
但是我遇到的问题是,混合后的图像没有遵循与剪切强度相同的缩放比例。我该如何处理,以确保混合后的图像具有与单个通道相同的对比度?
import skimage.exposure
import skimage.io
import skimage.data
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors
def blend(image1, image2, cmap1, cmap2):
image1_rgba = cmap1(image1)
image2_rgba = cmap2(image2)
return 1 - (1 - image1_rgba) * (1 - image2_rgba)
cmapgrn = matplotlib.colors.LinearSegmentedColormap.from_list("", ["black", "seagreen"])
cmapred = matplotlib.colors.LinearSegmentedColormap.from_list("", ["black", "red"])
fig, ax = plt.subplots(nrows = 3, ncols = 2, figsize = (10,5))
ax = ax.ravel()
multichannel = skimage.data.hubble_deep_field() # type: np.ndarray
green_raw = multichannel[:200, :200, 0] # type: np.ndarray
red_raw = multichannel[:200, :200, 1].T # type: np.ndarray
imgs = green_raw, red_raw
all_imgs = []
for img in imgs:
img_rescale = img/img.max()
all_imgs.append(img_rescale)
green, red = all_imgs # type: np.ndarray
G = green
R = red
cmin = 0.05
cmax = 0.3
ax[0].imshow(G.clip(cmin, cmax), cmap = cmapgrn)
ax[1].imshow(R.clip(cmin, cmax), cmap = cmapred)
ax[2].imshow(blend(image1 = G,
image2 = R,
cmap1 = cmapgrn,
cmap2 = cmapred))
ax[3].imshow(blend(image1 = G.clip(cmin, cmax),
image2 = R.clip(cmin, cmax),
cmap1 = cmapgrn,
cmap2 = cmapred))
ax[4].hist((G.ravel(), R.ravel()), bins = 50, color = ("green", "red"))
ax[4].axvline(cmin, color = "black")
ax[4].axvline(cmax, color = "black")
fig.delaxes(ax[5])
plt.tight_layout()
plt.show()