필터 지우기
필터 지우기

PLY/ RGB to 2D Grayscale Image

조회 수: 3 (최근 30일)
Wookie
Wookie 2020년 12월 7일
답변: Image Analyst 2020년 12월 29일
I have a PLY from a stereo vision sensor (1024 x 1280). The PLY gives:
- Location (X,Y,Z) [1310442 x 3]
- Color (R, G, B) [1310442 x 3] and
- XLimits, YLimits, ZLimits.
I am trying to convert the Color into a grayscale image/matrix. My attempt has been the following:
Image = ptCloud.Color(:,:,1);
R = double(Image(:,1));
G = double(Image(:,2));
B = double(Image(:,3));
I = 0.2989 * R + 0.5870 * G + 0.1140 * B; % For grayscale
%
% Since the matrix size does not equal 1024 x 1280, I add zeros to the end of I to compensate
%
Image_2d = reshape (I, 1024, 1280)
The image on the left is by plotting the PLY with MatLab's pcshow feature. This is what I want to obtain as an image/matrix but instead by following the above code... I get the image on the right which does not look correct!

답변 (2개)

Rohit Pappu
Rohit Pappu 2020년 12월 29일
Based on the above code,
  • Image stores the Color Matrix of just the Red channel
  • R, G, B refer to the values of first, second and third column of Image matrix respectively
A plausible workaround could be
Image = ptCloud.Color; %% Store the entire m-by-n-by-3 color matrix in Image
%% Extract the Red , Green and Blue Channels
R = double(Image(:,:,1));
G = double(Image(:,:,2));
B = double(Image(:,:,3));
%% the rest of the code is same
  댓글 수: 1
Image Analyst
Image Analyst 2020년 12월 29일
Or
[R, G, B] = imsplit(Image);
Or
grayImage = rgb2gray(Image);

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2020년 12월 29일
What does this show?
whos Image
Assuming Image is an RGb image and you want grayscale, you can do
grayImage = rgb2gray(Image);
I'd recommend agains using Image as the name of your image since image is the name of a built-in function.
From the pseudocolored image on the right, it looks like you're using imagesc() which applies a colormap by default that is usually not wanted or helpful. I never use that. I use imshow(). So just use imshow() with no colormap.
imshow(grayImage);
If you need more help, attach ptCloud in a .mat file:
save('answers.mat', 'ptCloud');

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by