27分段线性灰度变换

161 阅读1分钟

close all;clear all;clc;

R=imread('微信图片_20220429194904_512_512.bmp');%读入原图像,赋值给R

J=rgb2gray(R); %将彩色图像数据R转换为灰度图像数据J

[M,N]=size(J); %获得灰度图像数据J的行列数M,N

x=1;y=1; %定义行索引变量x、列索引变量y

for x=1:M

for y=1:N

    if (J(x,y)<=35);     %对灰度图像J进行分段处理,处理后的结果返回给矩阵H
    
        H(x,y)=J(x,y)*10;
        
    elseif(J(x,y)>35&J(x,y)<=75);
    
        H(x,y)=(10/7)*[J(x,y)-5]+50;
        
    else(J(x,y)>75);
    
        H(x,y)=(105/180)*[J(x,y)-75]+150;
        
    end
    
end

end

subplot(121),imshow(J)

subplot(122),imshow(H);