获取图片中指定像素点的灰度值并画图显示

本文展示了如何使用Python的OpenCV、numpy、matplotlib等库获取图像的指定像素点灰度值,并将这些值绘制成图表。代码读取多张图片,将每个像素点的灰度值存储到列表中,最后用matplotlib进行可视化展示。
摘要由CSDN通过智能技术生成

1、获取图片中某一像素点的灰度值并画图显示

import cv2
import numpy as np

import os
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib

if __name__ == "__main__":
    path = "C:/Users/HY2020828/Desktop/aa/2/"   #处理图片路径
    path1 = "C:/Users/HY2020828/Desktop/aa/h/"   #保存图片路径
    filelist = os.listdir(path) 
    aa=[]
    for file in filelist:
        
        img_path =os.path.join(path,file)
        img = cv2.imread(img_path)
        width,height = img.shape[:2][::-1]
        img_resize = cv2.resize(img,(int(width),int(height)),interpolation=cv2.INTER_CUBIC
        img_gray = cv2.cvtColor(img_resize,cv2.COLOR_RGB2GRAY))      #转化为灰度图
        cv2.imwrite(path1+file+".jpg",img_gray)
        img_point=img_g

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值