如何在matlab中将图像分成8x8和32x32块

时间:2014-04-21 22:14:39

标签: matlab block

image' lena.tif'它必须分为2块,大小为8x8。在每个块中应计算平均值和标准差,之后将这些结果保存在一个大小为32x32的图像中。可视化图像并解释结果?

请帮我完整解决方案,因为我是matlab的初学者

1 个答案:

答案 0 :(得分:1)

我想你的意思是:将256x256图像分成8x8块;对于每个计算均值和标准差;并将结果保存为32x32矩阵。

使用blockproc

可以非常轻松地完成此操作
%// Load image
im = double(imread('lena.png')); %// 256x256 grayscale image

%// Compute block mean and std
m = blockproc(im, [8 8], @(b) mean(b.data(:))); %// 32x32 matrix of block means
s = blockproc(im, [8 8], @(b) std(b.data(:))); %// 32x32 matrix of block std's

%// Normalize to [0,1]
m = m-min(m(:));
m = m./max(m(:));
s = s-min(s(:));
s = s./max(s(:));

%// Write
N = 256; %// number of levels for writing m and s
imwrite(m*N, gray(N), 'lena_mean.png') %// save m as N-level grayscale image
imwrite(s*N, gray(N), 'lena_std.png') %// save s as N-level grayscale image

产生的图像:

  • 平均数

    enter image description here

  • 标准差

    enter image description here