找回密码
 注册
关于网站域名变更的通知
查看: 297|回复: 1
打印 上一主题 下一主题

在MATLAB环境下图像直方图均匀化代码实现

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-3-3 15:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x

至于图像直方图均匀化的概念我就不说了,下面直接给出直方图均匀化的代码吧。


" a% m6 @3 ^5 p3 o
9 H% Z! v8 d+ F2 K+ K1 w+ s
  • function om=myhisteq(im,a,b,flag)
  • % HISTOGRAM EQUALIZATION
  • %
  • % input parameters
  • % im (must): input grayscale image, can be double, uint8, uint16 and int16
  • % a,b (must): piecewise linear stretching parameters, must be a vector between [0 1],
  • % a and b must have the same length
  • % flag (optional): 1 meaning plot the result, otherwise don't plot
  • %
  • % output parameters
  • % om: output grayscale image after histogram equalization, have the same
  • % class with im
  • %
  • % example
  • % close all
  • % im=imread('darklena.gif');
  • % a=[0 0.1 0.2 1];
  • % b=[0 0.8 0.95 1];
  • % % 关于myhisteq的使用说明参见myhisteq.m内部
  • % om=myhisteq(im,a,b,1);
  • %
  • % By LaterComer of MATLAB技术论坛
  • % See also http://www.matlabsky.com
  • % Contact me matlabsky@gmail.com
  • % Modifid at 2010-10-13 12:52:53
  • %
  • % close all
  • if nargin<3
  •     error('Input parameters must have im, a, b at least!');
  • elseif nargin==3
  •     flag=0;
  • elseif nargin>4
  •     error('Too many input parameters, the function have 4 arguments at most!');
  • end
  • if flag==1
  •     figure('name','Piecewise Linear Function')
  •     plot(a,b,'o-')
  •     xlabel('Input')
  •     ylabel('Output')
  •     title('Piecewise Linear Function')
  •     saveas(gcf,'_Piecewise Linear Function.jpg')
  • end
  • dataclass=class(im);
  • switch dataclass
  •     case {'double','sigle'}
  •         if ~all(im<=1 & im>=0)
  •             error('If input image is double, then the data "im" must be between [0 1]!');
  •         end
  •     case {'uint8','uint16','int16'}
  •         vmin=double(intmin(dataclass));
  •         vmax=double(intmax(dataclass));
  •         a=a*(vmax-vmin)+vmin;
  •         b=b*(vmax-vmin)+vmin;
  • end
  • om=zeros(size(im),dataclass);
  • for i=1:length(a)-1
  •     pix = im>=a(i) & im<a(i+1);
  •     om(pix)=(b(i+1)-b(i))/(a(i+1)-a(i))*(im(pix)-a(i))+b(i);
  • end
  • if flag==1
  •     figure('name','Input Image')
  •     imshow(im)
  •     title('Input Image')
  •     imwrite(im,'_Input Image.jpg');
  •     figure('name','Histogram of Input Image')
  •     imhist(im)
  •     title('Histogram of Input Image')
  •     saveas(gcf,'_Histogram of Input Image.jpg');
  •     figure('name','Oput Image')
  •     imshow(om)
  •     title('Oput Image')
  •     imwrite(om,'_Oput Image.jpg')
  •     figure('name','Histogram of Output Image')
  •     imhist(om)
  •     title('Histogram of Output Image')
  •     saveas(gcf,'_Histogram of Output Image.jpg')
  • end- B! K" z/ w8 K+ ]0 H

; B$ q4 X- B4 h) E! V3 W
# z2 ^/ R) M9 V: _# Y, f; N

该用户从未签到

2#
发表于 2020-3-3 16:35 | 只看该作者
在MATLAB环境下图像直方图均匀化代码实现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-7-21 05:30 , Processed in 0.109375 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表