如何翻译和缩放图像?

时间:2015-06-02 20:57:28

标签: image matlab image-processing computer-vision vision

我的图片如下:

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

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

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

1 个答案:

答案 0 :(得分:2)

这是一个解决方案,我将每个大脑平铺为32x32图像。评论解释了代码。但基本的想法是......

使用block proc

  1. 将大图像分割成5x8网格,因为它有5行大脑和8列大脑。我将这些图片中的每一个称为瓷砖

  2. 将每个磁贴调整为32x32

  3. 使用mat2cell

    1. 将新的小图块拆分为单个图像并显示它们
    2. 这是代码

      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

      enter image description here