数字图象处理MATLAB学习

diagram = imread('C:UsersAdministratorDesktopCompressedfiterlena256.jpg')
%diagram = rgb2gray(diagram);%------------------------------将图片转换为灰度图
%diagram = logical(diagram)%
figure,imshow(diagram),title('Original picture');%----------显示原图
%figure,imshow(diagram(100,:)),title('Original picture');%--显示100行水平扫描线
%plot(diagram(255,:))
size(diagram)
whos diagram
% imfinfo lena256.jpg %---------------------------------------显示图片信息
diagram(256,256)
diagram(1:10,1:10)

% diagram = imadjust(diagram,[0,1],[1,0]) %-----------------图像反转 亮度
% figure,imshow(diagram)
% diagram = intrans(diagram,'stretch',mean2(im2double(diagram)),0.9);


%%======================直方图============================%%
% h = imhist(diagram)
% h1 = h(1:1:256)
% horz = 1:1:256;
%bar(horz,h1)
%axis([0 255 0 1500])


%%======================图像复原===========================%%
%g = imnoise(diagram,'gaussian') %-------------------------添加高斯噪声
%figure,imshow(g)

[M,N]=size(diagram)
R = imnoise2('salt & pepper',M,N,0.01,0) %-----------------椒盐噪声
c = find(R == 0);
gp = diagram
gp(c) = 255   %--------------------------------------------椒盐噪声
%figure,imshow(gp);title('salt noise ')
%g2 = imnoise(diagram,'poisson') %-------------------------珀松
%figure,imshow(g2);title('pospng noise ')
% fp = spfilt(gp,'chmean',3,3,-1)
% figure,imshow(fp)


%%=========================分离RGB========================%%
rgb_se = diagram
% rgb_se = im2double(rgb_se)
fr = rgb_se(:,:,1)
fg = rgb_se(:,:,2)
fb = rgb_se(:,:,3)

R = rgb_se(:,:,1)
G = rgb_se(:,:,2)
B = rgb_se(:,:,3)
Y  = 16+(0.256789*R+0.504129*G+0.097906*B)
Cb = 128+(-0.148223*R-0.290992*G+0.439215*B)
Cr = 128+(0.439215*R-0.367789*G-0.071426*B)
% figure,imshow(Y);title('Y ')
% ycbcr = cat(3,Y,Cb,Cr)
% figure,imshow(ycbcr);title('Ycbcr ')
% figure,imshow(fr)   %--------------------------------------此时的不是红色,只是红色分量
% figure,imshow(fg)
% figure,imshow(fb)
% rgb_image = cat(3,fr,fg,fb) %------------------------------合并RGB分量
% figure,imshow(rgb_image)


%==========================提出R G B分量===================%%
a = diagram
[r,c,d]=size(a);

red=a;%提取红色分量
red(:,:,1)=a(:,:,1);
red(:,:,2)=zeros(r,c);%--------------------------------------将其他两组分量置位0
red(:,:,3)=zeros(r,c);
% red=unit8(red);
% red=uint8(red);
%subplot(131),imshow(red);title('red separation')
%提取绿色分量
green=zeros(r,c);
green(:,:,2)=a(:,:,2);
green(:,:,1)=zeros(r,c);
green(:,:,3)=zeros(r,c);
green=uint8(green);
%subplot(132),imshow(green);title('green separation')
%提取蓝色分量
blue=zeros(r,c);
blue(:,:,1)=zeros(r,c);
blue(:,:,2)=zeros(r,c);
blue(:,:,3)=a(:,:,3);
blue=uint8(blue);
%subplot(133),imshow(blue);title('blue separation')


%%===========================颜色空间转换=====================%%
rgb_image = diagram
rgb_image = im2double(rgb_image)
yiq_image = rgb2ntsc(rgb_image)  %---------------------------RGB  to NTSC
%figure,imshow(yiq_image);title('RGB to NTSC ')
ycbcr_image = rgb2ycbcr(rgb_image)%--------------------------RGB  to Ycbcr
% figure,imshow(ycbcr_image);title('RGB to Ycbcr ')
size(ycbcr_image)
%Here pick off the 256x256 luminance part of the ycbcr image
Y = ycbcr_image(:,:,1)
%figure, imshow(Y); title('Y part of Image');
size(Y)

%Here pick off the 256x256 Cb part of the ycbcr image
CB = ycbcr_image(:,:,2)
%figure, imshow(CB); title('Cb part of Image');
size(CB)

%Here pick off the 256x256 Cr part of the ycbcr image
CR = ycbcr_image(:,:,3)
%figure, imshow(CR); title('Cr part of Image');
size(CR)






人生天地之间,若白驹之过郤(隙),忽然而已
原文地址:https://www.cnblogs.com/xiabodan/p/4038635.html