overwrite pixel value in tiff

4 次查看(过去 30 天)
Raphael
Raphael 2022-1-23
评论: Raphael 2023-9-29
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

回答(1 个)

Milan Bansal
Milan Bansal 2023-9-29
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!

类别

Help CenterFile Exchange 中查找有关 Import, Export, and Conversion 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by