diving all images in folder into n horizental and vertical strips
1 回表示 (過去 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!