如何将图像分解为8 x 8像素块? [英] How can I decompose an image into 8 x 8 pixel blocks?
本文介绍了如何将图像分解为8 x 8像素块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I=imread('X.jpg');
[a b]=size(I);
figure;imshow(I);
j=rgb2ycbcr(I);
figure;
imshow(j);
ca=mat2cell(j,8*ones(1,size(j,1)/8),8*ones(1,size(j,2)/8),3);
p=1;
for c=1:size(ca,1)
for r=1:size(ca,2)
subplot(8,8,p);
imshow(ca{c,r});
p=p+1;
end
end
我收到以下错误:
Index超过子图的数量。
有什么想法吗?
i get the following error: Index exceeds number of subplots. Any thoughts?
推荐答案
之所以这样,是因为你有更多的图像块要显示,而不是你有子图空格绘图。改为将换成
循环代码改为:
The reason why is because you have more image blocks to show than you have subplot spaces when plotting. Change your for
loop code to this instead:
p = 1;
figure;
for c=1:size(ca,1)
for r=1:size(ca,2)
subplot(size(ca,1),size(ca,2),p); %// Change
imshow(ca{c,r});
p=p+1;
end
end
这样,您将拥有尽可能多的子图空间绘制,因为你有要显示的像素块。
This way, you will have as many subplot spaces to plot as you have pixel blocks to show.
这篇关于如何将图像分解为8 x 8像素块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文