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 CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by