diving all images in folder into n horizental and vertical strips
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2021-7-26
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 个评论
Image Analyst
2021-7-28
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);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!