Convert Grayscale image to XYZ file..

Risposte (2)

Image Analyst
Image Analyst il 11 Apr 2013

0 voti

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 Commenti

George
George il 11 Apr 2013
thanks for your interest Image Analyst!! i have a grayscale image and i want to export a txt file with XYZ coordinates.. (X,Y)= pixels coordinates and Z= Gray level
by any chance, do you have access to ArcGIs. If yes, then have a look at http://shreshai.blogspot.ch/2011/01/converting-raster-dataset-to-xyz-in.html
If not, you can still do it in MALTAB. Some f the function that will help is meshgrid, transpose. Try yourself first.
[height, width] = size(image);
[X, Y] = meshgrid(1:width, 1:height);
points = [X(:) Y(:) image(:)]
*i write this but i have a problem with photos larger than 255*255 pixels
because the values X,Y stop to 255*
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.
George
George il 5 Giu 2013
Modificato: George il 5 Giu 2013
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?

Accedi per commentare.

Image Analyst
Image Analyst il 18 Apr 2019

0 voti

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

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Richiesto:

il 11 Apr 2013

Risposto:

il 18 Apr 2019

Community Treasure Hunt

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

Start Hunting!

Translated by