图像灰度变换
im = imread('pout.tif');
im = double(im) / 255.0;
myimshow(im, 'Original Image');
im1 = imadjust(im);
myimshow(im1, '灰度拉伸');
im2 = imadjust(im, [min(min(im)); max(max(im))], [], 0.4);
myimshow(im2, '\gamma 变换, \gamma = 0.4');
im3 = imadjust(im, [min(min(im)); max(max(im))], [], 2.5);
myimshow(im3, '\gamma 变换, \gamma = 2.5');
im1 = imadjust(im);
myimshow(im1, '灰度拉伸');
im2 = imadjust(im, [min(min(im)); max(max(im))], [], 0.4);
myimshow(im2, '\gamma 变换, \gamma = 0.4');
im3 = imadjust(im, [min(min(im)); max(max(im))], [], 2.5);
myimshow(im3, '\gamma 变换, \gamma = 2.5');
计算显示图像直方图、直方图均衡化
im = imread('tire.tif');
myimshow(im, '原图');
im_eq = histeq(im);
myimshow(im_eq, '直方图均衡化');
空间域图像平滑、锐化
im = imread('pout.tif');
im = double(im)/255;
figure;
subplot(221);
imshow(im);
title('Original Image')
index = 2;
for N = [3, 7, 15]
kernel = ones(N) / N^2;
im_blur = imfilter(im, kernel);
subplot(2, 2, index);
index = index + 1;
imshow(im_blur);
title(['Kernel size:', num2str(N)])
end
suptitle('Blur');
im = imread('rice.png');
im = double(im)/255;
figure, subplot(221);
imshow(im);title('Original Image');
kernel = [0 1 0; 1 -4 1; 0 1 0];
im_edge = imfilter(im, kernel);
subplot(222);
imshow(im_edge);
title('Uncalibrated');
im_edge = im_edge - min(min(im_edge));
subplot(223);
imshow(mat2gray(im_edge));
title('Calibrated');
im_sharpen = mat2gray(im - 0.5*im_edge);
subplot(224);
imshow(im_sharpen);
title('Sharpened');
suptitle('Sharpen');
function myimshow(im, im_title)
figure;
subplot(121);
imshow(im);
subplot(122);
imhist(im);
suptitle(im_title);
end