图像处理基础

图像的基础知识

1.灰度量化级

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

imag = cv2.imread("cameraman.tif", 0) #直接读取为灰度图像

heigth=imag.shape[0]
width=imag.shape[1]  #图片尺寸
print('heigth=%f\nwidth=%f\n'%(heigth,width))

title = ["1","2","3","4","5","6"]
for i in range(1,6):
    figure = imag[::(pow(2,i)),::pow(2,i)]
    plt.subplot(2, 3, i)
    plt.imshow(figure)
    plt.title(title[i-1])
    print(figure.shape)
plt.subplot(2, 3, 6)
plt.imshow(imag)
plt.title(6)
plt.show()

在这里插入图片描述

2.降采样

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

imag = cv2.imread("cameraman.tif", 0) #直接读取为灰度图像

heigth=imag.shape[0]
width=imag.shape[1]  #图片尺寸
figure = np.zeros([heigth,width],dtype=np.uint8)
print((figure.shape))
print('heigth=%f\nwidth=%f\n'%(heigth,width))

for i in range(1,6):
    f = 256/(pow(2,i))
    for j in range(0,heigth):
        for k in range(0,width):
               figure[j,k] = np.uint8(imag[j,k]/f)*f
    plt.subplot(2,3,i)
    plt.imshow(figure,cmap='gray')
plt.subplot(2,3,6)
plt.imshow(imag,cmap='gray')
plt.show()

在这里插入图片描述
温馨提示
图片相应路径问题可自行更正

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三毛是she

感谢打赏,我会继续努力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值