필터 지우기
필터 지우기

overwrite pixel value in tiff

조회 수: 2 (최근 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에서 Image Data에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by