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!