Creating a grayscale image from ascii file

7 次查看(过去 30 天)
Hi all,
Could anyone please help me how to create a grayscale image (map) from an ascii file (the file contains three columns: X coord, Y coord and intensity value). So the result of grayscale image will have a georeference coord and the grayscale represents the intensity value. Thank you in advance.
Henz.
I attached the small piece of the file as well from the total 300mb. The grid size is 5 cm and I was thinking to re-gridding with 10 cm or 15 cm of grid size, so the processing time would be not too long. But I don't know how to do that? I really appreciate your help. Thank you.
  6 个评论
Stephen23
Stephen23 2018-9-16
@hendra kurnia febriawan: are the data scattered or gridded?:
It would probably help if you uploaded the data file by clicking the paperclip button.
hendra kurnia febriawan
编辑:Walter Roberson 2018-9-16
Hi Stephen,
Thanks for the links. The ascii file has spatial spacing 5 cm, so it is a rectangular grid. The total file is very big (217 mb). I tried to assign the 1st row as x, 2nd row as y and 3rd row as z.
M = dlmread('file.txt',',');
x = M(:,1);
y = M(:,2);
z = M(:,3);
[X,Y,Z] = meshgrid(x,y,z);
But it showed following warning.
Error using repmat
Requested 493606x493606x493606 (896048273.5GB) array exceeds
maximum array size preference. Creation of arrays greater
than this limit may take a long time and cause MATLAB to
become unresponsive. See array size limit or preference panel
for more information.
Error in meshgrid (line 77)
xx = repmat(xx, ny, 1, nz);
Any suggestion for that?
Thanks.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-9-16
M = dlmread('file.txt',',');
x = M(:,1);
y = M(:,2);
z = M(:,3);
ux = uniquetol(x);
uy = uniquetol(y);
Z = reshape(z, length(ux), length(uy));
You might need
Z = reshape(z, length(uy), length(ux)) .';
  3 个评论
Stephen23
Stephen23 2018-9-16
编辑:Stephen23 2018-9-16
@hendra kurnia febriawan: some of the values are missing. You can check the sizes yourself:
  • ux has size 429x1
  • uy has size 1253x1
Now lets calculate how many Z values that would give:
>> 429*1253
ans = 537537
Does M have 537537 rows? No. Actually you have 493606 data values for each of X, Y, and Z. There is no way to reshape a 493606 element vector into a 537537 element matrix. I suspect that you will have to resample/interpolate your data, to get the gridded data that you require. I would love to help you, but your sample file simply repeats the same X and Y values like this (I copied the data verbatim):
4.063e+05,6.474e+06,75.828
4.063e+05,6.474e+06,75.982
4.063e+05,6.474e+06,75.443
4.063e+05,6.474e+06,75.029
4.063e+05,6.474e+06,74.431
4.063e+05,6.474e+06,74.651
4.063e+05,6.474e+06,74.873
4.063e+05,6.474e+06,76.198
...
and I doubt that that represents the real data values (are they really only stored to four/five significant figures?). Please:
  • create a file suitable for uploading,
  • check the file has useful values (not just 4 sigfig),
  • edit your question,
  • upload the file by clicking the paperclip button.
hendra kurnia febriawan
Hi Stephen,
Thanks for the comments. I apologize for the previous data since I only simply extracted and took a piece of row from the original file without checking first. I have re-uploaded the data. Actually, the grid resolution is 5cm so you can notice the values are only different after the comma since it shows in decimal meter.
Thank you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by