⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dipproj.m

📁 circular convolution code in matlab
💻 M
字号:
clear all;

%%%%%%%%%%%%%%%%%%%%% Color conversion example %%%%%%%%%%%%%%%%%%%%%%%
[RGB] = imread('lenna.bmp');  % Reads image. Could be other image type.
R = RGB(:,:,1);                % Extract each channel
G = RGB(:,:,2);
B = RGB(:,:,3);

figure(1);
subplot('position', [0.0 0.5 0.5 0.5]); % [Left Bottom Width Height]
imshow(RGB,[0,255]);          % Displays image.[0,255] implies the minimum and maximum value are 0 & 255.
subplot('position', [0.5 0.5 0.5 0.5]);
imshow(R);
subplot('position', [0.0 0.0 0.5 0.5]);
imshow(G);
subplot('position', [0.5 0.0 0.5 0.5]);
imshow(B);

% Convert RGB to YCbCr & display each channel
% Because the type of YCbCr is double,
% the imshow function displays values between 0 & 1.
% Therefore, to display the image properly, normalization is needed.
% For example, YCbCr/255.
% Students should always check the minimum and maximum value of an image.
YCbCr = colorspace(['YCbCr','<-RGB'],RGB);
Y = YCbCr(:,:,1);
Cb = YCbCr(:,:,2);
Cr = YCbCr(:,:,3);
figure(2);
subplot('position', [0.0 0.5 0.5 0.5]); % [Left Bottom Width Height]
imshow(YCbCr/256,[0,1]);          % Displays image.[0,1] implies the minimum and maximum value are 0 & 255.
subplot('position', [0.5 0.5 0.5 0.5]);
imshow(Y/256,[0,1]);
subplot('position', [0.0 0.0 0.5 0.5]);
imshow(Cb/256,[0,1]);
subplot('position', [0.5 0.0 0.5 0.5]);
imshow(Cr/256,[0,1]);

% Convert YCbCr to RGB & display
RGB = colorspace(['RGB<-', 'YCbCr'],YCbCr);
R = RGB(:,:,1);                % Extract each channel
G = RGB(:,:,2);
B = RGB(:,:,3);
figure(3);  imshow(RGB);
YCbCr = colorspace(['YCbCr','<-RGB'], RGB);
imshow(YCbCr/256);
imsave;         % You can also save the image in the figure tool box.

%%%%%%%%%%%%%%%%%%%%% Quantization example %%%%%%%%%%%%%%%%%%%%%%%
% Since the value of RGB is between [0,1], 
% step size 0.1 will quantize the value of image into 10 levels.
qRGB=quantization(RGB,0.1);    % step size: 0.1
imshow(qRGB);

%%%%%%%%%%%%%%%%%%%%% Gaussian filtering example %%%%%%%%%%%%%%%%%%%%%%%
GaussianFilter=d2gauss(5,1,5,1,0);
gfRGB(:,:,1)=filter2(GaussianFilter,RGB(:,:,1),'same');
gfRGB(:,:,2)=filter2(GaussianFilter,RGB(:,:,2),'same');
gfRGB(:,:,3)=filter2(GaussianFilter,RGB(:,:,3),'same');
figure(4);  imshow(gfRGB);

%%%%%%%%%%%%%%%%%%%%% Sampling example %%%%%%%%%%%%%%%%%%%%%%%
%% if sampling interval is not an integer, it'll bring you a warning.
sRGB = sampling(gfRGB,4,4);   % sampling interval: 4
figure(5);  imshow(sRGB);

%%%%%%%%%%%%%%%%%%%%% Interpolation example %%%%%%%%%%%%%%%%%%%%%%%
figure(6); subplot('position', [0.05 0.5 0.125 0.125]); % [Left Bottom Width Height]
imshow(sRGB,[0,1]);
nnRGB = imresize(sRGB, 4, 'nearest');
subplot('position', [0.5 0.5 0.5 0.5]); % [Left Bottom Width Height]
imshow(nnRGB,[0,1]);
blRGB = imresize(sRGB, 4, 'bilinear');
subplot('position', [0.0 0.0 0.5 0.5]); % [Left Bottom Width Height]
imshow(blRGB,[0,1]);
bcRGB = imresize(sRGB, 4, 'bicubic');
subplot('position', [0.5 0.0 0.5 0.5]); % [Left Bottom Width Height]
imshow(bcRGB,[0,1]);

psnr(RGB, nnRGB);
psnr(RGB, blRGB);
psnr(RGB, bcRGB);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -