diving all images in folder into n horizental and vertical strips
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mujtaba Tahir
el 26 de Jul. de 2021
Comentada: Image Analyst
el 28 de Jul. de 2021
i have 500 images and i want to divide all of them into 4 equal parts automatically and get stored to a new location. i have a code which can devide a image into n number of horizental and vertical strips but i want to use that code on all the images and store the cropped new 4 images to a seperate folder
0 comentarios
Respuesta aceptada
Image Analyst
el 26 de Jul. de 2021
You can get the rows and columns like this
[rows, columns, numberOfColorChannels] = size(yourImage);
r = ceil(rows/4);
c = ceil(c/4);
dividingRows = 1 : r : rows;
dividingColumns = 1 : c : columns
for k = 1 : length(dividingRows)
row1 = dividingRows(k);
row2 = row1 + r;
if row2 >= rows
row2 = rows
end
thisBand = yourImage(row1:row2, :, :);
% etc.
end
% Similar for columns.
for k = 1 : length(dividingColumns)
col1 = dividingColumns(k);
col2 = col1 + c;
if col2 >= columns
col2 = columns
end
thisBand = yourImage(:, col1:col2, :);
end
6 comentarios
Image Analyst
el 28 de Jul. de 2021
You're not changing the name at all. You're just using the same name for all images you save. To fix it try this:
[~, baseNameNoExt, ext] = fileparts(baseInputFileName);
baseOutputFileName = sprintf('%s, row %2.2d, col %2.2d.png', baseNameNoExt, row, col);
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!