画像の上に画像を貼り付ける

20 views (last 30 days)
akasa
akasa on 22 Jun 2021
Commented: akasa on 22 Jun 2021
あるフルスクリーンの画像の上にもう一つの画像を貼り付けたいと考えているのです
が、そのような関数はありますでしょうか?
また、貼り付ける画像のサイズや場所を変更できると嬉しいです。

Accepted Answer

Hernia Baby
Hernia Baby on 22 Jun 2021
Edited: Hernia Baby on 22 Jun 2021
基本的に各座標に255までの数字をいれているだけなので、座標と範囲が分かれば貼り付け可能です。
貼り付けというより、上書きに近いです。
--------------
■こちら参考にしてみてください。
■画像の大きさを変更する場合は imresize を参照ください。
---------------
…少々、不親切なので例を入れておきます。
画像は愛犬とmatlabのアイコンです。
Step1. 写真を読み込みます
clc,clear,close all;
dog = imread('chacha.jpeg');
icon = imread('matlab_icon.png');
[xe_d,ye_d,~] = size(dog);
[xe_i,ye_i,~] = size(icon);
dog1 = dog;
montage({dog,icon});
Step2. 範囲を決めます(今回は右下に貼り付けます)
xs = xe_d - xe_i;
ys = ye_d - ye_i;
xe = xs + xe_i;
ye = ys + ye_i;
Step3. 上書きします
dog1(xs+1:xe,ys+1:ye,:) = icon;
imshow(dog1);
  4 Comments
Hernia Baby
Hernia Baby on 22 Jun 2021
Atsushi Uenoさん、代わりにありがとうございます。
おっしゃる通り、基本的なimread, imshow, imwrite関数はデフォルトで使えます。
Step3の上書きはmatlabでの通常の動作になります。
A = zeros(9);
A(3:5,4:6) = 1
A = 9×9
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0~255云々が画像になるについて
まずは適当な数字を書きます
x = linspace(255,0,12);
x = uint8(x);
I =reshape(x,[3,4])
I = 3×4
255 185 116 46 232 162 93 23 209 139 70 0
それを図示します。
imshow(I)
小さいので拡大すると以下のようになります。
imshow(I,'InitialMagnification','fit')
0は黒、255が白というのがわかります。
これがRed, Green, Blueの3セット分入るとRGBカラーで表示されます。
akasa
akasa on 22 Jun 2021
お二方ご回答ありがとうございます。。
まだmatlabを使い始めて日が浅いので分からないことだらけなのですが、丁寧にご指摘いただき感謝します。

Sign in to comment.

More Answers (0)

Categories

Find more on Display Image in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!