Clear Filters
Clear Filters

how to create and save a georeferenced image in .tif format?

6 views (last 30 days)
Hi! I have 3 arrays 318x2000: the first one contains the pixel values of a grayscale image I and the others the lat and lon values of each pixel. I have to save a georeferenced image in a .tif format but I don't know how to save the position. Shoul I use geotiffwrite? To visualize the image I have written
Z=zeros(num_ping,2*Nbins);
figure(19)
surf(lon_SSS,lat_SSS,Z,I,'EdgeColor','none')
colormap gray
and it works. If I use geoshow the gray levels are brighter. Thank you

Answers (1)

Abhishek Chakram
Abhishek Chakram on 29 Apr 2024
Hi Valeria Leto,
To save a georeferenced grayscale image in MATLAB using the pixel values and corresponding latitude and longitude arrays, “geotiffwrite” is indeed the function you would typically use. However, before you can use “geotiffwrite”, you need to ensure that you have the necessary spatial referencing information ready, which tells the function how the pixel values in the image array correspond to locations on the Earth's surface.
You will need to create a “georasterref” object that describes the spatial extent and resolution of the data. This object will then be passed to “geotiffwrite” along with the image data to create the georeferenced TIFF.
Here is an example for the same:
% Assuming I, lat_SSS, and lon_SSS are already defined
% Create a geographic raster reference object
% You need to determine the latitude and longitude limits of your data
latlim = [min(lat_SSS(:)), max(lat_SSS(:))];
lonlim = [min(lon_SSS(:)), max(lon_SSS(:))];
% Assuming that lat_SSS and lon_SSS are linearly spaced (adjust if not)
numRows = size(I, 1);
numCols = size(I, 2);
R = georasterref('RasterSize', [numRows numCols], ...
'LatitudeLimits', latlim, ...
'LongitudeLimits', lonlim);
% Now you can write the geotiff
% Replace 'your_geotiff.tif' with your desired output file name
geotiffwrite('your_geotiff.tif', I, R);
You can refer to the following documentation to know more about functions used:
Best Regards,
Abhishek Chakram

Categories

Find more on Images in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!