フィルターのクリア

May i know is it possible to convert an image from 101 x 101 uint8 to 101 x 101 x 3 unit8

1 回表示 (過去 30 日間)
The title tells thanks

採用された回答

Stephen23
Stephen23 2015 年 12 月 18 日
Here is the simplest way to convert a 2D image to a 3D image:
rgbImage = grayImage(:,:,[1,1,1]);
  2 件のコメント
Image Analyst
Image Analyst 2015 年 12 月 18 日
Interesting trick. I didn't expect that. I would have expected that when you tried to access the [1,1,1] plane when the third dimension does not yet exist would have thrown an error like this does:
a = [1,2;3,4]
b = a(:,:, 42);
Index exceeds matrix dimensions.
Error in test3 (line 2)
b = a(:,:, 42);
but it doesn't. I guess it's because you're using 1, and specifying a third index (dimension) to a 2D array is okay as long as it's exactly 1.
Steven Lord
Steven Lord 2015 年 12 月 18 日
Just about every array in MATLAB has trailing singleton dimensions. [There are a few exceptions, like some objects that overload and specialize indexing as well as function handles.] So the third dimension does exist, but it's usually not shown. That doesn't prevent you from explicitly asking for the SIZE in that dimension, or indexing with page indices from 1:size(a, 3) [which in this case is 1:1.]
x = 5;
size(x, 1234567) % returns 1
Here's an indexing example. Since I don't want to type over a million 1's I'll use a comma-separated list.
ind = repmat({1}, 1, 1234567);
x(ind{:}) % returns 5
A slightly smaller example, where I will type all the 1's:
x(1, 1, 1, 1, 1, 1, 1, 1, 1, 1) % also returns 5

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2015 年 12 月 18 日
Yes. Let's call your gray scale image grayImage. Then, to get a 3-D RGB image from it, use cat():
rgbImage = cat(3, grayImage, grayImage, grayImage);
If you want to do it while applying a colormap at the same time (which I don't think you do), then use ind2rgb():
rgbImage = ind2rgb(grayImage, yourColorMap);

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by