Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
The title tells thanks

Réponse acceptée

Stephen23
Stephen23 le 18 Déc 2015
Here is the simplest way to convert a 2D image to a 3D image:
rgbImage = grayImage(:,:,[1,1,1]);
  2 commentaires
Image Analyst
Image Analyst le 18 Déc 2015
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 le 18 Déc 2015
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

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 18 Déc 2015
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);

Catégories

En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by