0
点赞
收藏
分享

微信扫一扫

Matlab底层算法实现图像灰度幂次变换

公式

幂次变换公式如下:
                                                      y = c x r + b y=cx^{r}+b y=cxr+b
其中c,r为正数。修改幂次变化公式,使x与y的取值范围都在0到255之间。
                                                      y = 255 c ( x 255 ) r + b y=255c(\frac{x}{255})^{r}+b y=255c(255x)r+b

源代码

clc
image = imread('D:\2.png');
image_matrix=image(:,:,1);
image_matrix=double(image_matrix);
[height,width,channels]=size(image);
G=zeros(height,width);

%输入值
c=1;
r=1.7;
b=20;

%灰度映射表,灰度在0255之间
gray_map = zeros(1,256);

%计算灰度映射表
for i=1:256  
  y=c*255*(i/255)^r+b;
  if(y<0)
     y=0;
  elseif(y>255)
     y=255;
  end
  gray_map(i)=round(y);
end

for i=1:height
    for j=1:width
       T = image_matrix(i,j);
       if(T==0)
           G(i,j)=gray_map(1);
       else
           G(i,j)=gray_map(T);
       end
    end
end
image_out = uint8(G);
%显示
subplot(1,2,1);
imshow(image);
subplot(1,2,2);
imshow(image_out);

效果图

在这里插入图片描述

举报

相关推荐

0 条评论