[cv]Image transformation

Image transform









image warping



similarity transformation





A perspective transformation is a homography when the content of the image is on a plane.

In pixel coordinates, (0,0) is located at top left.

The DOF is 8 in a homography transformation.

































How many points are necessary to compute a homography? 4 points, 8 equations.

Here is a good tutorial for computing homography matrix.








这段代码有几个问题需要修改: 1. `plt.show()` 函数没有传入参数,应该将图像数组作为参数传入,即 `plt.imshow(result)`。 2. `gamma_transformation()` 函数中的 `img` 参数与 `cv2.imread()` 中读入的图像变量名相同,会导致函数中的 `img` 变量与外部变量重名,建议将函数中的参数名改为 `src` 或其他不与外部变量名重复的名称。 3. 在 `gamma_transformation()` 函数中,计算 `dst` 的过程可以简化为 `dst = (img/255)**gamma * 255`,无需调用 `np.round(dst).astype(np.uint8)`。 4. 在使用 `cv2.imshow()` 显示图像时,应该传入窗口名称参数,如 `cv2.imshow('image', img)`。 修改后的代码如下: ```python import cv2 import numpy as np import matplotlib.pyplot as plt img = cv2.imread(r'E:\\postgraduate\\three\\DIP3E_Original_Images_CH03\\3.8.tif', 0) def gamma_transformation(src, gamma): height, width = src.shape dst = np.zeros((height, width), np.uint8) cv2.normalize(src, dst=dst, alpha=0, beta=1.0) dst = (src/255)**gamma * 255 dst = dst.astype(np.uint8) return dst image1 = gamma_transformation(img, 0.6) image2 = gamma_transformation(img, 0.4) image3 = gamma_transformation(img, 0.3) fig = plt.figure(figsize=(8, 6)) vs1 = np.concatenate([img, image1, image2, image3], axis=1) vs2 = np.concatenate([image2, image3], axis=1) result = np.concatenate([vs1, vs2], axis=0) plt.imshow(result) plt.show() cv2.imshow('image', img) cv2.waitKey(0) cv2.destroyAllWindows() ``` 其中,`np.concatenate()` 函数第二个参数应该为 `axis=1` 或者 `axis=0`,表示沿着列或者行方向进行合并操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值