画像データの軸プロパティについて質問です。

21 views (last 30 days)
KO
KO on 13 Jun 2021
Commented: KO on 13 Jun 2021
imreadで読み込んだ画像データは,添付のように,元画像データのままx=560,y=380の座標軸で表示されますが,これをx=1000,y=1000の座標平面の中心に置くことはできますか?
画像データはx=560,y=380のサイズのままで,外枠を余白にしたいです.つまり,1000×1000の座標平面で,画像データをx方向に220,y方向に310平行移動したいです.
ご存知の方,よろしくお願いいたします。

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 13 Jun 2021
下記の様に画像データは行列データと同様に操作出来ます。型がuint8(0:黒~255:白)で、RGB3色分ある点に注意です。
img = imread('img.jpg');
image(img)
[h w ~] = size(img); % h=380, w=560
w2 = 1000;
h2 = 1000;
x = (w2-w)/2; % x=220 平行移動量
y = (h2-h)/2; % y=310 垂直移動量
bgd = uint8(ones(w2,h2,3)*255); % bgdは1000×1000の座標平面
bgd(y:y+h-1,x:x+w-1,:) = img; % 座標平面の中心にimg.jpgを置く
image(bgd)
  1 Comment
KO
KO on 13 Jun 2021
すごくわかりやすいです.画像も行列データということが分かれば理解しやすいですね.
いつも本当にありがとうございます。

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!