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
댓글 수: 0
채택된 답변
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
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
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
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);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!