这个例子是一个函数
文件名与函数名相同
控制台输入t2(“football.jpg”)
function t2(filename)
w0=imread(filename);
uint16 t;
[a,b,~]= size(w0);
w0=rgb2gray(w0); %灰度处理
for i=1:2
for j=1:2
B{
i,j}= w0((i-1)*a/2+1:a/2*i,(j-1)*b/2+1:j*b/2,:);
end
end
z=1;
for i=1:2
for j=1:2
subplot(2,2,z)
imshow(B{
i,j});
z=z+1;
end
end
D{
1}=B{
1,1};
B{
1,1}=B{
2,2};
B{
2,2}=D{
1};
D{
1}=B{
1,2};
B{
1,2}=B{
2,1};
B{
2,1}=D{
1};
d=cell2mat(B);
hold on;
figure;imshow(d);
end