matlab灰度变换函数imadjust、stretchlim

1、imadjust函数

g=imadjust(f,[low_in,high_in],[low_out,high_out],gamma)

f为输入灰度图像,将low_in和high_in之间的灰度值映射到low_out到high_out之间

gamma大于1,映射函数下凸;小于1,上凸;gamma默认为1,即线性映射

例:

利用imadjust函数进行灰度变换。

clc
clear
f=imread('E:\桌面\数字图像matlab\CH01\charpt2_1.tif');

%生成负片
g1=imadjust(f,[0,1],[1,0]);

%将0.5到0.75之间的灰度扩展到0-1之间
g2=imadjust(f,[0.5,0.75],[0,1]);

%gamma=2时
g3=imadjust(f,[],[],2);

%绘图
subplot(221),imshow(f)
title('原片')
subplot(222),imshow(g1)
title('负片')
subplot(223),imshow(g2)
title('0.5-0.75')
subplot(224),imshow(g3)
title('gamma=2')

结果如下:

注:对于负片的生成也可直接用函数imcomplement。

g=imcomplement(f);

2、stretchlim函数

在imadjust函数选择灰度区间时,也可使用stretchlim自适应选择。

low_high=stretchlim(f,tol),生成的是一个1*2的向量

而后应用imadjust函数

g=imadjust(f,low_high,[]);

其中tol是一个1*2的向量【tol(1),tol(2)】,默认为【0.01,0.99】,即低于tol(1)的像素占比1%,高于tol(2)的像素占比1%(1-0.99),如果输入的是一个数,那么tol=[tol,1-tol]。

 例:应用stretchlim函数自适应选择灰度区间

f=imread('E:\桌面\数字图像matlab\CH01\charpt2_1.tif');
g=imadjust(f,stretchlim(f),[1 0]);

subplot(121),imshow(f)
title('原片')
subplot(122),imshow(g)
title('负片')

stretchlim输出为:自适应选择区间为[0.118,0.933],比选择[0,1]进行映射,效果更好

 

  • 4
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值