欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

matlab图像预处理

程序员文章站 2022-07-13 08:53:17
...

Matlab图像处理

图像处理基础

实现代码

代码来自与书籍《精通图像处理经典算法 MATLAB版》

% i3 = imread('pout.tif');
% subplot(121),imshow(i3),title('图像');
% i4 = imread('fabric.png');
% subplot(122),imshow(i4),title('真彩色图像');

% mri = uint8(zeros(128,128,1,27));
% for frame = 1:27
%  [ mri(:,:,:,frame),map] = imread('mri.tif',frame);
% end
% montage(mri,map);

% load trees;
% i5 = ind2gray(X,map);
% imshow(X,map);
% figure,imshow(i5);


% load trees
% BW6 = im2bw(X,map,0.4);
%  imshow(X,map);
% figure,imshow(BW6);


% i8 = imread('snowflakes.png');
% x8 = grayslice(i8,16);  
% imshow(i8);
% figure,imshow(x8,jet(16));

% Ibackground = imread('pears.png');
% Ibackground = imresize(Ibackground,[200,200]);
% subplot(221),imshow(Ibackground),title('图1');
% J = imread('peppers.png');
% J = imresize(J,[200,200]);
% subplot(222),imshow(J),title('图2');
% K1 = imadd(Ibackground,J);
% subplot(223),imshow(K1),title('图像与图像相加');
% K2 = imadd(J,100);
% subplot(224),imshow(K2),title('图像与常数相加');

% Ibackground = imread('pears.png');
% Ibackground = imresize(Ibackground,[200,200]);
% subplot(221),imshow(Ibackground),title('图1');
% J = imread('peppers.png');
% J = imresize(J,[200,200]);
% subplot(222),imshow(J),title('图2');
% K1 = imsubtract(Ibackground,J);
% subplot(223),imshow(K1),title('图像与图像相减');
% K2 = imsubtract(J,100);
% subplot(224),imshow(K2),title('图像与常数相减');

% Img1 = imread('saturn.png')
% Img1 = rgb2gray(Img1);
% subplot(221),imshow(Img1),title('图1');
% [m,n] = size(Img1);
% Img2 = imread('rice.png');
% subplot(222),imshow(Img2),title('图2');
% Img2 = imresize(Img2,[m,n]);
% Img_multi = immultiply(Img1,Img2);
% subplot(223),imshow(Img_multi),title('图像与图像相乘');
% Img_multi2 = immultiply(Img1,2);
% subplot(224),imshow(Img_multi2),title('图像与常数相乘');

% Img1 = imread('rice.png')
% % Img1 = rgb2gray(Img1);
% subplot(221),imshow(Img1),title('图1');
% [m,n] = size(Img1);
% Img2 = imread('moon.tif');
% subplot(222),imshow(Img2),title('图2');
% Img2 = imresize(Img2,[m,n]);
% Img_multi = imdivide(Img1,Img2);
% subplot(223),imshow(Img_multi),title('图像与图像相除');
% Img_multi2 = imdivide(Img1,2);
% subplot(224),imshow(Img_multi2),title('图像与常数相除');


% A = imread('circles.png');
% subplot(231),imshow(A),title('图1');
% [m,n]=size(A);
% B = imread('coins.png');
% B1 = im2bw(B);
% subplot(232),imshow(B1),title('图2');
% B1 = imresize(B1, [m,n]);
% C_and = A & B1;
% subplot(233),imshow(C_and),title('与运算');
% C_or = A | B1;
% subplot(234),imshow(C_or),title('或运算');
% C_not = ~ A ;
% subplot(235),imshow(C_not),title('图1的非运算');
% C_or = xor(A,B1);
% subplot(236),imshow(C_or),title('异或运算');

% clc;
% I = imread('lighthouse.png');
% I = rgb2gray(I);
% subplot(131),imshow(I),title('原始图像');
% J = fft2(I);
% subplot(132),imshow(J),title('FFT变换结果');
% K = fftshift(J);
% subplot(133),imshow(K),title('零点平移');

% f = zeros(30,30);
% f(5:24,13:17) = 1;
% F = fft2(f,256,256);
% F2 = fftshift(F);
% F3 = log(1 + abs(F2));
% subplot(221),imshow(f),title('原图像');
% subplot(222),imshow(F3),title('傅里叶频谱');
% f1 = imrotate(f,90);
% F1 = fft2(f1,256,256);
% F21 = fftshift(F1);
% F31 = log(1 + abs(F21));
% subplot(223),imshow(f1),title('原图像旋转45');
% subplot(224),imshow(F31),title('傅里叶频谱');

% f = imread('circles.png');
% subplot(131),imshow(f),title('原图');
% F1 = fft2(f);
% F2 = log(abs(F1));
% subplot(132),imshow(F2,[-1,5]),title('变换1');
% F3 = fft2(f,256,256);
% F3 = fftshift(F3);
% F4 = log(abs(F3));
% subplot(133),imshow(F4,[-1 5]),title('变换2');

% h = fspecial('gaussian'); %%高斯低通滤波
% freqz2(h);

% I1 = imread('pears.png');
% I1 = rgb2gray(I1,256);
% subplot(121),imshow(I1),title('原图');
% I2 = dct2(I1);
% I2(abs(I2)<10) = 0;
% K = idct2(I2);
% subplot(122),imshow(K,[0 255]),title('重构图像');

% clc;
% I = imread('coins.png');
% subplot(121),imshow(I),title('原始图像');
% H = size(I);
% I1 = zeros(size(I));
% Move_x = 50;
% Move_y = 50;
% I1(Move_x + 1: H(1,1),Move_y + 1:H(1,2)) = ...
%     I(1:H(1,1)-Move_x,1:H(1,2)-Move_y);
% subplot(122),imshow(uint8(I1)),title('平移后图像');

% I = imread('office_6.jpg');
% I = rgb2gray(I);
% subplot(121),imshow(I),title('原图');
% I = double(I);
% H = size(I);
% I2(1:H(1,1),1:H(1,2)) = I(1:H(1,1),H(1,2):-1:1);
% subplot(122),imshow(uint8(I2)),title('水平镜像');

% I = imread('office_6.jpg');
% I = rgb2gray(I);
% subplot(121),imshow(I),title('原图');
% I = double(I);
% H = size(I);
% I3(1:H(1,1),1:H(1,2)) = I(H(1,1):-1:1,H(1,2):-1:1);
% subplot(122),imshow(uint8(I3)),title('对角镜像');