python比较两张图片是否一样_检测两张图片之间的相似点,然后覆盖它们(Python)...

我有两张同一根神经在稍有不同深度处被切开的照片,在每个切片上用不同的染料染色。我想覆盖这两张图片,但它们在幻灯片/照片上没有完全对齐。我要做的是编写代码,检测两个切片之间相似的形状(即相同的单元格),然后根据这些单元格的位置覆盖图片。有办法吗?在

到目前为止,我掌握的代码是:import matplotlib

import matplotlib.pyplot as plt

import matplotlib.image as mpimg

import numpy as nb

from skimage import data, io, filters

import skimage.io

from PIL import Image

from scipy import misc

import numpy as np

from skimage.transform import resize

%matplotlib inline

picture1 = "Images/294_R_C3_5" # define your image pathway

i1 = Image.open(picture1 + ".jpg").convert('L') # open your first image and convert it to greyscale

i1 = i1.point(lambda p: p * 5) # brighten the image

region=i1.crop((600,0, 4000, 4000)) # crop the image

region.save(picture1 + ".png", "PNG") # save the cropped image as a PNG

i1 = matplotlib.image.imread(picture1 + ".png", format=None) # print the new cropped image

io.imshow(i1)

io.show()

IwETgt5.png

^{pr2}$

p4xu7PI.pngpicture2 = "Images/294_R_B3_6" #define your image pathway

i2 = Image.open(picture2 + ".jpg").convert('L') # open your second image and convert it to greyscale

i2 = i2.point(lambda p: p * 5)

region=i2.crop((600,0, 4000, 4000)) # crop the image

region.save(picture2 + ".png", "PNG") # save the cropped image as a PNG

i2 = matplotlib.image.imread(picture2 + ".png", format=None) # print the new cropped image

io.imshow(i2)

io.show()

VuPCElI.pngI2 = Image.open(picture2 + ".png") # open your image using a different module

I2

SQNrnTw.png

我试过用略读法,但似乎太多了。而且,我不知道如何基于这些点来堆叠图像。这是我的代码:from skimage.feature import ORB

orb = ORB(n_keypoints=800, fast_threshold=0.05)

orb.detect_and_extract(i1)

keypoints1 = orb.keypoints

descriptors1 = orb.descriptors

orb.detect_and_extract(i2)

keypoints2 = orb.keypoints

descriptors2 = orb.descriptors

from skimage.feature import match_descriptors

matches12 = match_descriptors(descriptors1, descriptors2, cross_check=True)

from skimage.feature import plot_matches

fig, ax = plt.subplots(1, 1, figsize=(12, 12))

plot_matches(ax, i1, i2, keypoints1, keypoints2, matches12)

ax.axis('off');

2Osu9qA.png

然后我试着把它清理一下,但这删除了比我希望的更多的点:from skimage.transform import ProjectiveTransform

from skimage.measure import ransac

src = keypoints1[matches12[:, 0]][:, ::-1]

dst = keypoints2[matches12[:, 1]][:, ::-1]

module_robust12, inliers12 = ransac((src, dst), ProjectiveTransform, min_samples=4, residual_threshold=1, max_trials=300)

fig, ax = plt.subplots(1, 1, figsize=(12, 12))

plot_matches(ax, i1, i2, keypoints1, keypoints2, matches12[inliers01])

ax.axis('off');

3THjYBA.png

有什么想法吗?谢谢您。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值