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
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.
回答(1 个)
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
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!