# Using X,Y,Z coordinates and grayscale values of pixels to reconstruct an image

21 views (last 30 days)
John Smith on 25 Oct 2021
Answered: yanqi liu on 26 Oct 2021
I am working on a project where I am given the X,Y,Z coordinates of each pixel and the grayscale value of each pixel. The grayscale value is how bright or dark each pixel is (darker pixel is lower value and brighter pixel is higher value). The given Y-coordinate values are zero.
What lines of code would you recommend using to proceed? I have already imported the data.

Image Analyst on 25 Oct 2021
Do the xyz values correspond to voxel locations? If so, simply use a for loop to stuff the value into the appropriate voxel.
maxCol = max(x); % x, y, and z are N row by 1 column vectors.
maxRow = max(y);
maxSlice = max(z);
image3d = zeros(maxRow, maxCol, maxSlice, 'uint8'); % or uint16
for k = 1 : length(x)
image3d(y(k), x(k), z(k)) = grayLevel(k);
end
If x, y, and z are floating point or have values way different than the number of voxel dimensions you want, then you can use round(rescale()) to turn them into voxel coordinates before passing to image3d as indexes.

yanqi liu on 26 Oct 2021
sir，may be use .off、.obj and so on to generate 3D file，such as

### Community Treasure Hunt

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

Start Hunting!

Translated by