>> I=imread('hanabi.jpg');
I=rgb2gray(I);
D1=I;
D2=dct2(D1);
s=size(D1);
P=zeros(s);
>> P1=P;
>> P2=P;
>> P3=P;
>> P1(1:40,1:40)=D2(1:40,1:40);
>> P2(1:60,1:60)=D2(1:60,1:60);
>> P3(1:80,1:80)=D2(1:80,1:80);
>> D3=idct2(D2);
E1=idct2(P1);
E2=idct2(P2);
E3=idct2(P3);
subplot(2,3,1),imshow(D1);subplot(2,3,2),imshow(D2);subplot(2,3,3),image(D3);
subplot(2,3,4),image(E1);subplot(2,3,5),image(E2);subplot(2,3,6),image(E3);
2.4-2
>> I=imread('hayakawa.png');
I=rgb2gray(I);
>> [M,N]=size(I);
>> P=dctmtx(M);
>> Q=dctmtx(N);
>> I1=double(I);
>> Idct=P*I1*Q';
>> subplot(121),imshow(I),title('原始图像');
>> subplot(122),imshow(Idct),title('离散余弦变换后的图像');
2.4-1
>> RGB=imread('hazhipeng-shihou.jpg');
I= rgb2gray(RGB);
subplot(1,3,1),imshow(I),title('输入图像');
J=dct2(I);
subplot(1,3,2),imshow(log(abs(J)),[]),colormap(jet(64)),colorbar,title('余弦变换结果');
J(abs(J)<10)=0;
K=idct2(J);
subplot(1,3,3),imshow(K,[0,255]),title('压缩后的结果');
2.1-3
>> I=imread('layanjing.jpg');
I=rgb2gray(I);
subplot(141),imshow(I),title('原始图像');
X1=imrotate(I,30,'nearest');
subplot(142),imshow(uint8(X1));title('旋转30度');
X2=imrotate(I,-45,'nearest');
subplot(143),imshow(uint8(X2));title('旋转-45度');
X3=imrotate(I,60,'nearest');
subplot(144),imshow(uint8(X3));title('旋转60度');
2.1-1
>> I=imread('shiki.jpg');
I=rgb2gray(I);
X1=imresize(I,0.3);
X2=imresize(I,0.5);
figure,imshow(X1);
figure,imshow(X2);
图像的hough变换
2.2-1
>> RGB=imread('tomoyo.jpg');
figure
imshow(RGB);
Warning: Image is too big to fit on screen; displaying at 25%
> In imuitools\private\initSize at 72
In imshow at 259
>> I=rgb2gray(RGB);
BW=edge(I,'canny');
[H,T,R]=hough(BW,'RhoResolution',0.75,'ThetaResolution',0.75);
imshow(imadjust(mat2gray(H)),'XData',T,'YData',R,...
'InitialMagnification','fit');
xlabel('\theta'),ylabel('\rho');
>> axis on,axis normal,hold on;
>> colormap(hot);
>> P=houghpeaks(H,4);
>> x=T(P(:,2));y=R(P(:,1));
>> plot(x,y,'s','color','white');