MATLAB Answers

George
0

Convert Grayscale image to XYZ file..

Asked by George
on 11 Apr 2013
Latest activity Answered by Image Analyst
on 18 Apr 2019
How i can convert a GrayScale image to XYZ file ?

  0 Comments

Sign in to comment.

2 Answers

Answer by Image Analyst
on 11 Apr 2013

You have row, columns, and at every (row, column) (= (y, x)) location you have a gray level. What are you referring to as "Z"? What does your Z represent? Gray level? If so, then the image array is already what you want. Or were you looking to display the image with surf()?

  6 Comments

They should not. See my demo code below. I'd have to see it to believe it.
grayImage = imread('moon.tif');
[height, width] = size(grayImage)
[X, Y] = meshgrid(1:width, 1:height);
numberOfPixels = length(X(:))
points = [X(:) Y(:) grayImage(:)];
whos X Y points
height =
537
width =
358
numberOfPixels =
192246
Name Size Bytes Class Attributes
X 537x358 1537968 double
Y 537x358 1537968 double
points 192246x3 576738 uint8
By the way, don't use image as the name of a variable since it's already the name of a built-in function.
Look at variable editor-points 'X' it stop to 255 not at 358 and 'Y' it stop to 255 not at 537. That's my problem. Thanks
how can I get the Z coordinate form this code?

Sign in to comment.


Answer by Image Analyst
on 18 Apr 2019

See my attached code. It produces a CSV text file with x,y,gray level.

  0 Comments

Sign in to comment.