Creating a grayscale image from ascii file
Mostrar comentarios más antiguos
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 comentarios
Walter Roberson
el 16 de Sept. de 2018
Do the X and Y form a rectangular grid?
From your mention of georeference it would not surprise me if X and Y are a lat/long grid that might perhaps have equal lat and long divisions but not equal linear divisions because of curvature of the Earth. If that is the case, do you need the map to be in lat/long coordinates (so, before map projection, not something that can be directly displayed as an image) or in linear coordinates (that is, after map projection)
hendra kurnia febriawan
el 16 de Sept. de 2018
Walter Roberson
el 16 de Sept. de 2018
Okay, but are they scattered or do they form a rectangular grid?
If they form a rectangular grid, then you can read the intensity values and reshape() them, and possibly a transpose is needed too, depending on the order they are input. The edge vectors would then be uniquetol(X) and uniquetol(Y)
hendra kurnia febriawan
el 16 de Sept. de 2018
Stephen23
el 16 de Sept. de 2018
@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
el 16 de Sept. de 2018
Editada: Walter Roberson
el 16 de Sept. de 2018
Respuestas (1)
Walter Roberson
el 16 de Sept. de 2018
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 comentarios
hendra kurnia febriawan
el 16 de Sept. de 2018
@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
el 16 de Sept. de 2018
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!