画像ファイルの次元数の拡張

2 views (last 30 days)
Yumi Iwakami
Yumi Iwakami on 26 Jun 2017
Commented: Yumi Iwakami on 26 Jun 2017
2値画像に赤で線を入れたいと考えています. その場合,元の2値画像は高さと幅の2次元ですが,RGB情報を入れるため,3次元に拡張が必要だと思うのですが,2値画像情報を保持したまま,2次元の行列を3次元に拡張する方法があったら教えてください.

Accepted Answer

Tohru Kikawada
Tohru Kikawada on 26 Jun 2017
repmat を使うと2次元から3次元への拡張が容易に行えます。ご参考まで。
% 2値化画像を適当に作成
BW = false(128,128);
[X,Y] = meshgrid(1:128,1:128);
ind = sqrt((X-64).^2+(Y-64).^2) < 30;
BW(ind) = true;
% 表示
figure, imshow(BW);
% 3次元方向に3つ繰り返して拡張
RGB = repmat(im2double(BW),[1 1 3]);
% 赤線を引く(横)
RGB(64,32:96,1) = 1;
RGB(64,32:96,2:3) = 0;
% 赤線を引く(縦)
RGB(32:96,64,1) = 1;
RGB(32:96,64,2:3) = 0;
% 表示
figure, imshow(RGB);
  1 Comment
Yumi Iwakami
Yumi Iwakami on 26 Jun 2017
ありがとうございます!助かりました.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!