模式识别与图像处理课程实验一:图像处理实验-->> 颜色算子实验、Susan、Harris角点检测实验、 sobel边缘算子检测实验
一、 实验内容
要求编写一个包含颜色算子,Susan,Harris,角点,sobel边缘算子的程。
二、 颜色算子实验
2.1、 提取红色
- 实验的程序如下
import numpy as np
import cv2 as cv
image = cv.imread("1.jpg")
image = image / np.ones([1, 1, 3]).astype(np.float32)
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
print(image.shape)
# 颜色算子
# red
redAdd = np.ones([1, 1, 3]).astype(np.float32)
redAdd[0, 0, 0] = 1.0
redAdd[0, 0, 1] = 0.5
redAdd[0, 0, 2] = 0.25
redSub = np.ones([1, 1, 3]).astype(np.float32)
redSub[0, 0, 0] = 0.25
redSub[0, 0, 1] = 0.5
redSub[0, 0, 2] = 1.0
image1 = np.mean(image * redAdd, 2)
image2 = np.mean(image * redSub, 2) + 100
imageRed = image1 / image2
redMax = np.max(imageRed)
redMin = np.min(imageRed)
imageRed = 255 * (imageRed - redMin) / (redMax - redMin)
cv.imwrite("1red.png", imageRed)
运行结果如下
- 实验原图
- 实验结果图
2.2、 提取绿色
实验的程序如下
import numpy as np
import cv2 as cv
image = cv.imread("1.jpg")
image = image / np.ones([1, 1, 3]).astype(np.float32)
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
print(image.shape)
# green
greenAdd = np.ones([1, 1, 3]).astype(np.float32)
gr