필터 지우기
필터 지우기

画像を分割したい。 I want to divide an image

조회 수: 9 (최근 30일)
Senka Okamoto
Senka Okamoto 2018년 7월 12일
편집: Senka Okamoto 2018년 10월 11일
1枚の画像を分割して9枚や25枚にしたいのですが、どうすれば良いでしょうか?
I want to divide one image into nine or twenty-five sheets, what should I do?
  댓글 수: 1
Rena Berman
Rena Berman 2018년 10월 11일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

답변 (1개)

lattice
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
でどうでしょうか?

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!