Image How do I convert xyz coordinates into an image?

14 views (last 30 days)
I have the xyz cordinates of a surface obtained from a focus variation microscope. I want to convert those cordinates into image form using matlab and feed into another imaging processing software.
How do I go about this? I have tried using xyz2rgb() and rgb2gray() which give me a colour map.
  2 Comments
KSSV
KSSV on 26 Jun 2020
Okay you have tried is the problem solved?
Doyinsola Oduwole
Doyinsola Oduwole on 26 Jun 2020
I think my question is, is the result of trasnforming x,y,z cordinates a color map as shown?

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 26 Jun 2020
Colorimetric xyz has nothing at all to do with spatial xyz coordinates. They're entirely different things. You would definitely not use xyz2rgb().
What you want is to either just make the image from the xyz coordinates where z is a gray level
rows = ceil(max(y(:)))
columns = ceil(max(x(:)))
grayLevels = mat2gray(z(:))
grayImage = zeros(rows, columns, 'uint8')
for k = 1 : length(y)
row = ceil(x(k));
col = ceil(y(k));
grayImage(row, col) = grayLevels(k);
end
imshow(grayImage, []);
or use griddedInterpolant() or scatteredInterpolant() (demo attached).
  3 Comments
imran ahmed
imran ahmed on 5 May 2021
Edited: Image Analyst on 5 May 2021
To solve that error.
rows = ceil(max(y(:)))
columns = ceil(max(x(:)))
grayLevels = mat2gray(z(:))
grayImage = zeros(rows, columns, 'uint8')
for k = 1 : length(y)
row = ceil(x(k));
col = ceil(y(k));
if row<1
row=1;
end
if col<1
col=1;
end
grayImage(row, col) = grayLevels(k);
end
imshow(grayImage, []);
Image Analyst
Image Analyst on 5 May 2021
Another way would be to just specify how many rows and columns you want the image to be, and scale your x and y to go from one up to the dimension size:
rows = 1080; % HDTV
columns = 1920; % HDTV
grayLevels = mat2gray(z(:))
% Rescale x and y
% Convert scaled x and y to integers with round() because they are row and column
% indexes, which need to be integers.
x2 = round(rescale(x, 1, columns));
y2 = round(rescale(y, 1, rows));
grayImage = zeros(rows, columns, 'uint8')
for k = 1 : length(y2)
% Get the row and column for this y and x, respectively.
row = x2(k);
col = y2(k);
% Now assign the gray level at that location.
grayImage(row, col) = grayLevels(k);
end
imshow(grayImage, []);

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!