How I can view this .tif file?

조회 수: 212 (최근 30일)
BN
BN 2020년 4월 13일
I have a tif file which represents the altitude for a country, I can simply open it in Esri's ArcGIS (Arc Map), Here is the result from ArcMap:
You can see the High and Low elevations are shown by a color range. I used this code below to open this tif file in Matlab:
x = imread('DEM_30s.tif', 'tif');
imshow(x)
But I see a figure like this:
So, If anyone could tell me how I can read my tif file in Matlab with a color bar that specifies high and low elevations (like Arcmap picture above), I would be so grateful.
Note: Since the size of the file is 7 MB, I split it into the 2 part then attach here; I also upload the .tif in my google drive in this link and compressed version of it (.zip) (just one part) here in my google drive.
Thank you
  댓글 수: 8
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 4월 13일
편집: KALYAN ACHARJYA 2020년 4월 13일
BN
BN 2020년 4월 13일

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 4월 13일
편집: Ameer Hamza 2020년 4월 13일
First, the problem is somewhat related to the encoding of your tiff file. The data values are encoded as single-precision numbers, and the background points are encoded as 0xff7fffff in hexadecimal (equal to -3.40282346639e+38, minimum possible number in IEEE754 single-precision floating-point format).
Second, the tiff file only has 1 channel, and have no color information, so you need to create your colormap.
Both problems can be solved by converting the loaded matrix from single to uint16. Note that we are converting the values, not typecasting. Converting to uint16 will convert the background pixels from -3.40282346639e+38 to 0. The elevation values lie in the range [0 - 10000], uint16 is sufficient to hold these values. The integer values will make it an indexed image that can take value from a colormap. Try the following code
[A,R] = readgeoraster('DEM_30s.tif', 'OutputType', 'double');
low_single = typecast(uint8([255 255 127 255]), 'single');
mask = low_single==A;
A = A - min(A(~mask), [], 'all');
% creating colormap changing from white to brown as shown in image in the question
brown_color = [0.8 0.2 0.1];
light_brown = [0.95 0.9 0.8];
t = linspace(0, 1, max(A,[],'all'))';
cmap = t.*brown_color + (1-t).*white;
gs = geoshow(A, cmap, R);
gs.CData(repmat(mask,1,1,3)) = 255;
  댓글 수: 5
Ameer Hamza
Ameer Hamza 2020년 4월 13일
I am glad to be of help.
Diego Mauricio Beramendi Ortega
Diego Mauricio Beramendi Ortega 2022년 6월 28일
Hi Ameer Hamza,
Your solution is great, I have a question related. How do you add a colorbar to the plot with the colormap you defined?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Blue에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by