Borrar filtros
Borrar filtros

How can I divide a image of 1500*1500 into different blocks of 32*32 and save all the images in a folder with different subfolders in it.

1 visualización (últimos 30 días)
I have a folder in which i have sub folders of different image groups. Each image is 1500*1500, How can I divide it into different blocks of 32*32 and save all the images in that folder with different subfolders in it.
  2 comentarios
Walter Roberson
Walter Roberson el 29 de Nov. de 2017
1500 = 46*32 + 28 -- that is, you would have partial blocks of 28 at the end. What do you want to do with those blocks?
NEHA SINGH
NEHA SINGH el 29 de Nov. de 2017
Editada: NEHA SINGH el 29 de Nov. de 2017
hello Sir, I want a total of 2116 blocks of 32*32. I am attaching my code where I want input image size of 32 *32 for classification. I have different subfolders of different granite tile images of 1500*1500. I want 2116 blocks of each images and save in a different folder.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 29 de Nov. de 2017
%divide into blocks
temp = cell2mat(YourImage, [32 * ones(1, 46), 28], [32 * ones(1, 46), 28]);
separate_blocks = temp(1:end-1, 1:end-1);
%create output folder, making sure we do not overwrite any existing folder
while true
foldername = tempdir('.');
if ~exist(foldername, 'dir'); break; end
end
mkdir(foldername);
%write the images
for K = 1 : numel(separate_blocks)
filename = fullfile(foldername, sprintf('%04d.bmp', K));
imwrite(filename, separate_blocks{K});
end

Más respuestas (0)

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by