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!
  1 件のコメント
Raphael
Raphael 2023 年 9 月 29 日
Thanks!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImport, 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