Matlab 图像灰度变换

图像灰度线性变换只需要线性改变图像像素灰度值即可;通过线性变换可以实现图像对比度和亮度的变化;

i = imread('F:\Myfile\Matlab\Test_picture\0_1.jpg');
[count,x] = imhist(i,64);
subplot(2,5,1); imshow(i);title('origin image');
subplot(2,5,6); stem(x,count);title('origin image hist');

%对比度提高
i1 = 2.*i + 50;
[count,x] = imhist(i1,64);
subplot(2,5,2); imshow(i1);title('image 1');
subplot(2,5,7); stem(x,count);title('image 1 hist');

%对比度降低
i2 = 0.2.*i + 50;
[count,x] = imhist(i2,64);
subplot(2,5,3); imshow(i2);title('image 2');
subplot(2,5,8); stem(x,count);title('image 2 hist');

%亮度增加
i3 = i + 30;
[count,x] = imhist(i3,64);
subplot(2,5,4); imshow(i3);title('image 3');
subplot(2,5,9); stem(x,count);title('image 3 hist');

%反相显示
i4 = 255-i;
[count,x] = imhist(i4,64);
subplot(2,5,5); imshow(i4);title('image 4');
subplot(2,5,10); stem(x,count);title('image 4 hist');

i为图像数据:
i1 = log(i+1);%对数变换,只能处理double类型值;

i1 = imadjust(i,[lin,hin],[lout,hout],r);
gamma变换,[] 中可以定义范围,范围外的被裁剪掉,可缺省,r为gamma值;

i1 = im2bw(i,level); 阈值变换,level为阈值0-1;

thresh = graythresh(i); 自动确定阈值0-1;
i1 = im2bw(i,thresh); 利用上面的阈值处理;

i = imread('F:\Myfile\Matlab\Test_picture\0_1.jpg');
i = im2double(i);
i1 = log(i+1);
i2 = imadjust(i,[],[],3);
i3 = im2bw(i,0.3);
thresh = graythresh(i);
i4 = im2bw(i,thresh);

subplot(1,5,1); imshow(i);
subplot(1,5,2); imshow(i);
subplot(1,5,3); imshow(i2);
subplot(1,5,4); imshow(i3);
subplot(1,5,5); imshow(i4);

你可能感兴趣的:(matlab)