模式识别与图像处理课程实验一:图像处理实验(颜色算子实验、Susan、Harris角点检测实验、 sobel边缘算子检测实验)
模式识别与图像处理课程实验一:图像处理实验-->> 颜色算子实验、Susan、Harris角点检测实验、 sobel边缘算子检测实验
- 一、 实验内容
- 二、 颜色算子实验
- 2.1、 提取红色
- 2.2、 提取绿色
- 2.3、 提取蓝色
- 三、 Susan、Harris角点检测实验
- 3. 1、 实验程序
- 3.1.1、Susan角点检测
- 3.1.2、Harris角点检测
- 四、 sobel边缘算子检测实验
- 4.1、sobel边缘算子检
- 五、 实验总结
一、 实验内容
要求编写一个包含颜色算子,Susan,Harris,角点,sobel边缘算子的程。
二、 颜色算子实验
2.1、 提取红色
- 实验的程序如下
import numpy as np
import cv2 as cvimage = 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.25redSub = 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.0image1 = np.mean(image * redAdd, 2)
image2 = np.mean(image * redSub, 2) + 100
imageRed = image1 / image2redMax = 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 cvimage = 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)
greenAdd[0, 0, 0] = 0.5
greenAdd[0, 0, 1] = 1.0
greenAdd[0, 0, 2] = 0.25greenSub = np.ones([1, 1, 3]).astype(np.float32)
greenSub[0, 0, 0] = 0.5
greenSub[0, 0, 1] = 0.25
greenSub[0, 0, 2] = 1.0image1 = np.mean(image * greenAdd, 2)
image2 = np.mean(image * greenSub, 2) + 100imageGreen = image1 / image2
greenMax = np.max(imageGreen)
greenMin = np.min(imageGreen)imageRed = 255 * (imageGreen - greenMin) / (greenMax - greenMin)
cv.imwrite("1green.png", imageRed)
运行结果如下
实验原图
实验结果图
2.3、 提取蓝色
- 实验的程序如下
import numpy as np
import cv2 as cvimage = cv.imread("1.jpg")
image = image / np.ones([1, 1, 3]).astype(np.float32)
image = cv.cvtColor(image, cv.COLOR_BGR2RGB)
print(image.shape)# bule
buleAdd = np.ones([1, 1, 3]).astype(np.float32)
buleAdd[0, 0, 0] = 0.25
buleAdd[0, 0, 1] = 0.5
buleAdd[0, 0, 2] = 1.0buleSub = np.ones([1, 1, 3]).astype(np.float32)
buleSub[0, 0, 0] = 1.0
buleSub[0, 0, 1] = 0.5
buleSub[0, 0, 2] = 0.25image1 = np.mean(image * buleAdd, 2)
image2 = np.mean(image * buleSub, 2) + 100imageBlue = image1 / image2
blueMax = np.max(imageBlue)
blueMin = np.min(imageBlue)imageBlue = 255 * (imageBlue - blueMin) / (blueMax - blueMin)cv.imwrite("1blue.png", imageBlue)
运行结果如下
实验原图
实验结果图
三、 Susan、Harris角点检测实验
3. 1、 实验程序
3.1.1、Susan角点检测
Susan角点检测程序如下
import numpy as np
import cv2 as cvimage = cv.imread("2.jpg")
image = np.mean(image, 2)height = image.shape[0]
width = image.shape[1]
print(image.shape)#susan 算子
radius = 5
imageSusan = np.zeros([height, width]).astype(np.float32)for h in range(radius, height-radius):for w in range(radius, width-radius):numSmall = 0numLarge = 0numAll = 0for y in range(-radius, radius + 1):for x in range(-radius, radius+1):distance = np.sqrt(y**2 + x**2)if distance <= radius:numAll += 1if image[h + y, w + x] < image[h, w] - 27:numSmall += 1if image[h + y, w + x] > image[h, w] + 27:numLarge += 1ratio = 1.0 * numSmall / numAllratio2 = 1.0 * numLarge / numAllif ratio < 0.3:imageSusan[h, w] = 0.3 - ratioif ratio2 > 0.7:imageSusan[h, w] = ratio2 - 0.7imageMax = np.max(imageSusan)
imageMin = np.min(imageSusan)imageSusan = 255*(imageSusan - imageMin)/(imageMax - imageMin)
print(imageSusan.shape)cv.imwrite("2.png", imageSusan)
- 运行结果如下
实验原图
实验结果图
3.1.2、Harris角点检测
- Harris角点检测程序如下
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt# 读取图像
img = cv.imread('3.jpg')
lenna_img = cv.cvtColor(img, cv.COLOR_BGR2RGB)# 图像转换成灰度图像
grayImage = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
grayImage = np.float32(grayImage)# Harris算子
harrisImage = cv.cornerHarris(grayImage, 2, 3, 0.04)harrisImage = cv.dilate(harrisImage, None)# 设置阈值
thresImage = 0.006 * harrisImage.max()img[harrisImage > thresImage] = [255, 0, 0]# 显示正常中文的标签
plt.rcParams['font.sans-serif'] = ['SimHei']titles = [u'(a)原始图像', u'(b)Harris图像']
images = [lenna_img, img]for i in range(2):plt.subplot(1, 2, i + 1), plt.imshow(images[i], 'gray')plt.title(titles[i])plt.xticks([]), plt.yticks([])
plt.show()
运行结果如下
四、 sobel边缘算子检测实验
4.1、sobel边缘算子检
- sobel边缘算子检程序如下
import numpy as np
import cv2image = cv2.imread("3.jpg")
height = image.shape[0]
width = image.shape[1]sobelResult = np.zeros([height - 2, width - 2, 1]).astype(np.float32)
sobelX = np.zeros([3, 3, 1]).astype(np.float32)
sobelY = np.zeros([3, 3, 1]).astype(np.float32)sobelX[0, 0, 0] = -1
sobelX[1, 0, 0] = -2
sobelX[2, 0, 0] = -1
sobelX[0, 2, 0] = 1
sobelX[1, 2, 0] = 2
sobelX[2, 2, 0] = 1sobelY[0, 0, 0] = -1
sobelY[0, 1, 0] = -2
sobelY[0, 2, 0] = -1
sobelY[2, 0, 0] = 1
sobelY[2, 1, 0] = 2
sobelY[2, 2, 0] = 1for h in range(0, height - 3):for w in range(0, width - 3):#求方向梯度imageIncre = image[h:h + 3, w:w + 3]gradientX = np.sum(imageIncre * sobelX)gradientY = np.sum(imageIncre * sobelY)gradient = np.sqrt(gradientX**2 + gradientY**2)sobelResult[h, w, 0] = gradientimageMax = np.max(sobelResult)
imageMin = np.min(sobelResult)sobelResult = 255*(sobelResult - imageMin) / (imageMax - imageMin)
cv2.imwrite("3.png", sobelResult)
2、 运行结果如下
实验原图
实验结果图
五、 实验总结
- 1、 掌握了编写含颜色算子图像处理、Susan与Harris角点图像检测、sobel边缘算子图像检测的程序编写方法。
- 2、 通过实验、对于边缘检测算子与角点检测算子有了进一步的掌握。
模式识别与图像处理课程实验一:图像处理实验(颜色算子实验、Susan、Harris角点检测实验、 sobel边缘算子检测实验)相关推荐
- 基于matlab的脑瘤mr图像处理_基于Matlab GUI的医学图像处理课程虚拟实验平台设计...
论文写作指导:请加QQ229366758 摘 要:针对医学生工程技术缺乏的状况,分析医学生学习医学图像处理存在的困难,提出利用Matlab图像处理工具和简单的GUI界面,设计和构建包含医学图像处理教学 ...
- matlab数字图像处理课程设计报告,数字图像处理课程设计实验报告.doc
数字图像处理课程设计实验报告 数字图像处理课程设计 题 目:数字图像处理及Huufman(或小波变换)编码仿真实现 学生姓名: 学 院:信息工程学院 系 别:电子信息工程系 专 业:电子信息工程 班 ...
- 数字图像处理课程(作业+实验+大作业)相关文章 传送门
数字图像处理课程(作业+实验+大作业)相关文章 传送门 博文说明 本文所使用代码或多或少参考了以往博文的同类or相似文章的代码,并非纯原创 本文仅用于记录并提供一种代码思路,供大家参考 文章目录 数字 ...
- 基于颜色布局描述符(CLD)图像特征提取算法使用Python实现简单的人脸检测功能并使用PyQt5构建简单的功能界面(数字图像处理课程实验)
文章目录 一.环境准备 二.数据集准备 三.项目结构 四.完整参考代码 imgCode/testUI3.py imgCode/test2.py 五.运行结果 测试一: 测试二 六.参考链接 一.环境准 ...
- 人工智能与模式识别的意义(模式识别与图像处理课程作业)
人工智能与模式识别的意义(模式识别与图像处理课程作业 一. 人工智能的意义 二. 模式识别的意义 2.1.文字识别 2.2.语音识别 2.3.指纹识别 2.4.遥感 2.5.医学诊断 1.语音识别技术 ...
- 图像处理边缘增强matlab,数字图像处理实验 matlab 图像增强 边缘检测 图像操作.doc...
数字图像处理实验 matlab 图像增强 边缘检测 图像操作 实验1 点运算和直方图处理 实验目的 1. 掌握利用Matlab图像工具箱显示直方图的方法 2. 掌握运用点操作进行图像处理的基本原理. ...
- 【数字图像处理】实验一 图像处理基本操作
实验一 图像处理基本操作 1 实验目的 2 实验环境 3 实验内容 4 实验心得 1 实验目的 熟悉并掌握MATLAB工具的使用: 实现图像的读取.显示.代数运算和简单变换. 2 实验环境 matla ...
- (附源码)python数字图像处理课程平台 毕业设计 242339
Python数字图像处理课程平台的开发 摘 要 数字图像处理是一门新兴技术,随着计算机硬件的发展,数字图像的实时处理已经成为可能,由于数字图像处理的各种算法的出现,使得其处理速度越来越快,能更好的为人 ...
- (附源码)Python数字图像处理课程平台 毕业设计242339
Python数字图像处理课程平台的开发 摘 要 数字图像处理是一门新兴技术,随着计算机硬件的发展,数字图像的实时处理已经成为可能,由于数字图像处理的各种算法的出现,使得其处理速度越来越快,能更好的为人 ...
最新文章
- 近万个Python开源项目中精选Top34!
- 摄像头动态锁定(Python)
- Flink SQL Client中的session window图解
- 求护士的心理阴影面积 | 今日最佳
- php通知多有人,PHP通知抑制;只有某些情况/方法
- Vue的一些API理解整理,如何一次引入多次调用
- 为什么网站总显示服务器不能创建对象,automation服务器不能创建对象”的问题的解决方案总结大全...
- elementui打包后出现图标乱码的问题解决
- 镜子--天空16度蓝
- 十七、.net core(.NET 6)搭建基于Quartz组件的定时调度任务
- 赞奇福利来袭:双重金秋好礼等着你
- 为什么祖传代码被称为「屎山」?这个回答简直太形象了
- 关于Protel 2004 绘制电路原理图——元件库的建立
- Arduino使用敲击模块和光遮断
- 百度细雨算法2.0解读
- bga封装扇出过孔_Altium Designer BGA扇出
- Chukeh 小诸葛 .Net 通用类库
- 2019.10.3 noip模拟赛
- cmd进入指定盘符详解
- Flutter——Isolate主线机制