overwrite pixel value in tiff
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi,
I have a geo-referenced TIFF file in which the values of some pixels need to be replaced and I want to save the new image as a geo-referenced TIFF file that inherits some attributes of the original image (in particular GPSInfo and DateTime). Subsequent processing is done outside Matlab so it is imperative that the new file is formatted exactly as a geo-referenced TIFF. Any suggestions on how to do that?
Thanks
Raphael
0 commentaires
Réponses (1)
Milan Bansal
le 29 Sep 2023
Hi,
As per my understanding you want to change the pixel values of a geo-reference TIFF File and save the modified while retaining the spatial reference information.
Use the "readgeoraster" function to read the TIFF file. Also, get the "info" using "georasterinfo" function.
[originalImg,R] = readgeoraster('filename.tif');
info = georasterinfo("filename.tif");
"R" in the above code is the spatial reference.
Modify the image by changing the pixel values.
modifiedImage = A;
modifiedImage(modifiedImage < 100) = 200; % (example)
Get the Geo Tags.
geoTags = info.GeoTIFFTags.GeoKeyDirectoryTag;
Write the modified TIFF file as shown below. Set the spatial reference as the original image.
geotiffwrite("mod.tif",modifiedImage,R,'GeoKeyDirectoryTag',geoTags)
Refer to the below MathWorks documentation link to learn more about "readgeoraster" function.
Refer to the below MathWorks documentation link to learn more about "georasterinfo" function.
Refer to the below MathWorks documentation link to learn more about "geotiffwrite" function.
Hope it helps!
Voir également
Catégories
En savoir plus sur Import, Export, and Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!