May i know is it possible to convert an image from 101 x 101 uint8 to 101 x 101 x 3 unit8
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
ken ken
am 18 Dez. 2015
Kommentiert: Steven Lord
am 18 Dez. 2015
The title tells thanks
0 Kommentare
Akzeptierte Antwort
Stephen23
am 18 Dez. 2015
Here is the simplest way to convert a 2D image to a 3D image:
rgbImage = grayImage(:,:,[1,1,1]);
2 Kommentare
Image Analyst
am 18 Dez. 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
am 18 Dez. 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
Weitere Antworten (1)
Image Analyst
am 18 Dez. 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);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!