MatLab 图像基本处理[1 2 3]源代码
%--------------------原图像显示-------------------------%
[f_name,p_name] = uigetfile('*.jpg; *.bmp; *.png'); %<1>
picture_read = imread(f_name);%<2>
%or delete <1><2> ,change: picture_read = imread('you_path');
%picture_read = imread('1.jpg');%private_test
subplot(3,3,1);
figure0 = imshow(picture_read);
title('原图')
%-----------------------进一步处理----------------------%
%图像灰度化
picture_gray = rgb2gray(picture_read);
subplot(3,3,2);
figure1=imshow(picture_gray);
title('图像灰度化')
%图像增强
picture_inten = imadjust(picture_gray);
subplot(3,3,3);
figure2 = imshow(picture_inten);
title('图像增强');
%直方图均衡
picture_balance = histeq(picture_gray);
subplot(3,3,4);
figure3 = imshow(picture_balance);
title('直方图均衡')
%--------------------加噪-------------------------%
%图像加上高斯噪声
picture_gaussian = imnoise(picture_gray,'gaussian');
subplot(3,3,5);
figure4 = imshow(picture_gaussian);
title('加上高斯噪声')
%图像加上椒盐噪声
picture_salt = imnoise(picture_gray,'salt & pepper',0.04);
subplot(3,3,7);
figure6 = imshow(picture_salt);
title('加上椒盐噪声')
%图像加上泊松噪声
picture_poisson = imnoise(picture_gray,'poisson');
subplot(3,3,9);
figure8 = imshow(picture_poisson);
title('加上泊松噪声');
%--------------------二维中值滤波-------------------------%
%二维中值滤波滤除椒盐噪声
picture_filter = medfilt2(picture_salt);
subplot(3,3,8);
figure7 = imshow(picture_filter);
title('二维中值滤除椒盐噪声');
%二维中值滤波滤除高斯噪声
picture_gussian2 = medfilt2(picture_gaussian);
subplot(3,3,6);
figure5 = imshow(picture_gussian2);
title('二维中值滤除高斯噪声');
%--------------------直方图-------------------------%
%原始直方图
figure,imhist(picture_gray);title('原始直方图');
%直方图线性变换增强
figure,imhist(picture_inten);title('线性变换增强后的直方图');
%直方图归一化
gray_num = numel(picture_gray); %图像像素的总数
gray_proportion = imhist(picture_gray)/gray_num;
gray_range = 0:255;
figure,stem(gray_range,gray_proportion);title('直方图归一化');