如何平移和缩放图像?

how to translate and scale the image?

我的图片是这样的:

给定的imrgb = 320*512*3 double; color_map = 64*3 双;使用后

[X, map] = rgb2ind(imrgb, color_map);

我得到 X = 320*512 uint8。图像太大,无法进一步处理。我的 问题是如何在不丢失重要信息的情况下将图像平移和缩放到32*32像素的标准尺寸(我的意思是图像的非黑色部分都是重要信息)?

这是一个解决方案,我将每个大脑图块制作成 32x32 图像。注释解释了代码。但基本思想是...

使用块处理

  1. 将大图分割成5x8的格子,因为它有5行脑8列脑。我将这些图像中的每一个都称为 tile

  2. 将每个图块调整为 32x32

使用 mat2cell

  1. 将新的小图块拆分成单独的图像并显示它们

这是代码

im = rgb2gray(imrgb);

max_rows = 32;
max_cols = 32;

%I assume every picture has 40 brains, 5 rows and 8 columns
rows_brains = 5;
cols_brains = 8;
[m n] = size(im);

%define the resize function to take the 'block_struct' image and resize
%it to max_rows x max_cols
fun = @(block_struct) imresize(block_struct.data,[max_rows max_cols]);

%blockproc will split the image into tiles. Each tile should hold one brain
%image. Then we resize that tile to a 32x32 tile using the resize function
%we defined earlier
I2 = blockproc(im,[m/rows_brains n/cols_brains],fun);

%split the image with small tiles into individual pictures
%each cell of indiv_brains will contain a 32x32 image of only one brain
indiv_brains = mat2cell(I2,max_rows*ones(1,rows_brains),max_cols*ones(1,cols_brains));

%displays all the brains
figure(1);

for ii=1:1:rows_brains
    for jj=1:1:cols_brains
        subplot(rows_brains, cols_brains, (ii-1)*cols_brains + jj);
        imshow(indiv_brains{ii,jj});
    end
end

结果,这些单独的图像中的每一个都是 32x32