计算机视觉(高斯模糊+RGB通道可视化)

本文介绍了两个实验,一是使用Python进行高斯模糊操作,包括图像导入、高斯模糊处理和高通滤波器测试;二是RGB通道可视化,展示如何分离和观察图像的红、绿、蓝通道。实验帮助理解图像处理技术及其在计算机视觉中的应用。
摘要由CSDN通过智能技术生成

实验14和实验2


前言

CG平台上完成


一、高斯模糊(实验14)

1、实验介绍

1). 实验内容

本实验将学习高斯模糊。

2). 实验要点

高斯模糊图像
使用高通滤波器测试性能

3). 实验环境

Python 3.6.6
numpy
matplotlib
cv2

2、实验步骤

1) 导入资源并显示图像

import numpy as np
import matplotlib.pyplot as plt
import cv2

%matplotlib inline

# 读入图像
image = cv2.imread('images/brain_MR.jpg')

# 制作图像副本
image_copy = np.copy(image)

# 将颜色更改为RGB(从BGR)
image_copy = cv2.cvtColor(image_copy, cv2.COLOR_BGR2RGB)

plt.imshow(image_copy)

输出如下:
在这里插入图片描述

2) 高斯模糊图像

代码:

# 转换为灰度用于过滤
gray = cv2.cvtColor(image_copy, cv2.COLOR_RGB2GRAY)

# 创建高斯模糊图像
gray_blur = cv2.GaussianBlur(gray, (9, 9), 0)

f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))

ax1.set_title('original gray')
ax1.imshow(gray, cmap='gray')

ax2.set_title('blurred image')
ax2.imshow(gray_blur, cmap='gray')

输出如下:
在这里插入图片描述

3) 使用高通滤波器测试性能

# 高通滤波器

# 3x3 Sobel滤波器用于边缘检测
sobel_x = np.array([[ -1, 0, 1], 
                   [ -2, 0, 2], 
                   [ -1, 0, 1]])


sobel_y = np.array([[ -1, -2, -1], 
                   [ 0, 0, 0], 
                   [ 1, 2, 1]])


# 使用filter2D过滤原始和模糊的灰度图像
filtered = cv2.filter2D(gray, -1, sobel_x)

filtered_blurred = cv2.filter2D(gray_blur, -1, sobel_y)
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20,10))

ax1.set_title('original gray')
ax1.imshow(filtered, cmap='gray')

ax2.set_title('blurred image')
ax2.imshow(filtered_blurred, cmap='gray')

输出如下:
在这里插入图片描述
创建一个阈值,将所有过滤的像素设置为白色
在一定的阈值之上

retval, binary_image = cv2.threshold(filtered_blurred, 50, 255, cv2.THRESH_BINARY)

plt.imshow(binary_image, cmap='gray')

输出如下:
在这里插入图片描述

二、RGB通道可视化(实验2)

1、实验介绍

1). 实验内容

本实验将介绍RGB色彩空间。

2). 实验要点

RGB通道

3). 实验环境

Python 3.6.6
matplotlib

2、实验步骤

1)导入资源

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

%matplotlib inline

2)读入图像

image = mpimg.imread('images/wa_state_highway.jpg')

plt.imshow(image)

如图:
在这里插入图片描述

3)RGB通道

# 隔离RGB通道
r = image[:,:,0]
g = image[:,:,1]
b = image[:,:,2]

# 可视化各个颜色通道
f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(20,10))
ax1.set_title('R channel')
ax1.imshow(r, cmap='gray')
ax2.set_title('G channel')
ax2.imshow(g, cmap='gray')
ax3.set_title('B channel')
ax3.imshow(b, cmap='gray')

输出如下:
在这里插入图片描述


总结

本次实验让我学习了高斯模糊和RGB色彩空间。让我了解了高通滤波器和RGB通道特性。通过完成实验后的结果图,能直观地分辨出实验前后图像的差别,易于理解技术,让我对计算机视觉有了更多的兴趣。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值