画像を分割したい。 I want to divide an image
9 ビュー (過去 30 日間)
古いコメントを表示
1枚の画像を分割して9枚や25枚にしたいのですが、どうすれば良いでしょうか?
I want to divide one image into nine or twenty-five sheets, what should I do?
回答 (1 件)
lattice
2018 年 7 月 12 日
2重ループでカッコ悪いですが...
img = imread('/path/to/the/img.tif'); %画像の読み込み
[a, b, ~] = size(img); %画像のサイズチェック
div = 3; % 3 by 3 に分割するとして
a = round(a/div);%分割後の画像の縦
b = round(b/div);%分割後の画像の横
img(a*div, b*div, :) = 0; %3 by 3 でピッタリ割り切れないところは0で埋めておく
img2 = uint8(zeros(a, b, 3, div^2));%分割ごとに4次元の画像データとする
count = 1;
%2重ループが不恰好ですが
for i = 1:div
for j = 1:div
img2(:,:,:,count) = img((a2*(i-1)+1):i*a2, (b2*(j-1)+1):j*b2, :);
%figure, imshow(img2(:,:,:,count)); %一枚ずつ表示したいなら
count = count + 1;
end
end
でどうでしょうか?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で 近傍処理とブロック処理 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!