Search code examples
imagematlabimage-processingcoordinatespoint-clouds

How to I change an n-by-n matrix to a point cloud matrix?


I have a 1265x1777 matrix with the intensity values of an image. I need to develop a point cloud file in MATLAB for the same. Just like a 3D scatter where x, y and z coordinates are stored in a variable; x, y should represent the pixel location; and z corresponds to the intensity of that pixel.


Solution

  • Edit: Updated according to OP's comment.

    Assuming your 1265x1777 matrix is called 'img':

    x = 1:size(img,2);
    y = 1:size(img,1);
    [X,Y] = meshgrid(x,y);
    
    xyz_matrix = [X(:), Y(:), img(:)];