Reputation: 243
My image looks like this:
The given imrgb = 320*512*3 double; color_map = 64*3 double; after using
[X, map] = rgb2ind(imrgb, color_map);
I get X = 320*512 uint8. The image is too big for the further processing. My question is how to translate and scale the image to a standard size of 32*32 pixels without losing the important information ( I mean the non-black part of the image are all important information)?
Upvotes: 0
Views: 573
Reputation: 2469
Here is one solution where I make each brain tile a 32x32
image. The comments explain the code. But the basic idea is...
using block proc
to split the large image into a 5x8 grid, because it has 5 rows of brains and 8 columns of brains. I call each of these images a tile
Resize each tile to 32x32
using mat2cell
Here is the code
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
and the result, each of these individual images is 32x32
Upvotes: 2