- 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
PLY/ RGB to 2D Grayscale Image
11 views (last 30 days)
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!
Rohit Pappu on 29 Dec 2020
Based on the above code,
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
Image Analyst on 29 Dec 2020
What does this show?
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.
If you need more help, attach ptCloud in a .mat file: