zoukankan      html  css  js  c++  java
  • Matlab图像直方图相关函数

    图像的灰度直方图(H是图像a.bmp的数据矩阵)

    imhist(H);%显示a的直方图

    histeq(H); %将图像a进行直方图均衡化

    adapthisteq(H); %将图像a进行直方图均衡化

    imhist函数只能处理二维数据,因此处理RGB图像,需先转化成灰度图像,显示灰度直方图。

    例1:显示图像灰度直方图并进行直方图均衡化

    H=rgb2gray(imread('peppers.png'));
    subplot(3,2,1);
    imshow(H);
    title('原图');
    subplot(3,2,2);
    imhist(H);
    title('原图直方图');
    subplot(3,2,3);
    H1=adapthisteq(H);
    imshow(H1);
    title('adapthisteq均衡后图');
    subplot(3,2,4);
    imhist(H1);
    title('adapthisteq均衡后直方图');
    subplot(3,2,5);
    H2=histeq(H);
    imshow(H2);
    title('histeq均衡后图');
    subplot(3,2,6);
    imhist(H1);
    title('histeq均衡后直方图');


    例2: 自己设计程序显示直方图,并实现直方图均衡化。

    直方图均衡化是直方图修正技术的一种。一幅均匀量化的自然图像的灰度直方图通常在低灰度区域的频率较大,这样的图像较暗,区域中的细节常常看不清楚。

    直方图均衡化可使得图像的灰度间距拉大或者使灰度分布均匀,从而增加了反差,使图像细节清晰,达到图像增强的目的。

    x=rgb2gray(imread('peppers.png'));
    [m,n]=size(x);
    p=zeros(1,256);
    for i=0:255
       p(i+1)=length(find(x==i))/(m*n);
    end
    subplot(2,2,1);
    bar(0:255,p,'b');
    title('原图直方图');
    subplot(2,2,2);
    imshow(x);
    title('原图');
     
    s=zeros(1,256);
    for i=1:256
         for j=1:i
             s(i)=p(j)+s(i);                
         end
    end
     
    a=round(s*255);
    for i=0:255
        GPeq(i+1)=sum(p(find(a==i)));          
    end
    subplot(2,2,3);
    bar(0:255,GPeq,'b')                 
    title('均衡化后的直方图');
    b=x;
    for i=0:255
         b(find(x==i))=a(i+1);              
    end
    subplot(2,2,4);
    imshow(b)                          
    title('均衡化后图像');
  • 相关阅读:
    Expected onClick listener to be a function, instead got type object
    css中的字体
    React Native之Touchable四组件
    0.44版本ReactNative真机运行的坑
    React Native之AsyncStorage
    VedioCaptureHelper
    2015年杂记一
    三级设置页面管理测试demo
    windows目录create、isExsit、remove
    验证reg注册表的操作
  • 原文地址:https://www.cnblogs.com/riasky/p/3507461.html
Copyright © 2011-2022 走看看