Resampling mask and restoration in one matrix

I am new to this forum, so please bear with me. I have been working on this Matlab problem for a long time:

I have a digital elevation model (DEM) new_sub (x, y) in tif format. So this is an x-by-y matrix containing heights (z). I want to redo parts of this DEM in different resolutions and restore it in a different matrix. So far I have been working with loops to change the resolution of various areas of the DEM, and then writing the results to an xyz file:

xyz 1 1 123 1 2 233 1 3 231 2 1 235 2 2 531 2 3 452

etc. Here is the code:

xmax = size(new_sub,2);
ymax = size(new_sub,1);

for k=1:200 % y
    for l=1:xmax % x
        fprintf(fid, '%d %d %d \n',l,xmax+1-k,new_sub(k,l));
    end
end

% 1:4
for k=200/2+1:size(new_sub,1)/2
    for l=1:size(new_sub,2)/2
        fprintf(fid, '%d %d %d \n',l*2,ymax+2-k*2,new_sub(k*2,l*2));
    end
end

It works, but it seems rather complicated. Moreover, it does not allow me to save the tried areas in the same matrix inside Matlab.

, , , ? repmap, !

!

Theo

+1
2

Matlab:

, M:

M = [1  2  3  4  5; 
     6  7  8  9  10; 
     11 12 13 14 15; 
     16 17 18 19 20; 
     21 22 23 24 25];

n- , :

m = M(1:n:end, 1:n:end)

, n=2

m = 1  3  5
    11 13 15
    21 23 25

matlab, matlab

, "xyz", , meshgrid X Y.

[X, Y] = meshgrid(1:n:size(M,1), 1:n:size(M,2))

n downsample X Y. :

final = [X(:), Y(:), m(:)]

, , help save help dlmwrite Matlab promt final

+1

imresize. I. :

I = imread('my.tiff'); % read
section = I(1:200, :); % cut the first 200 rows and all columns
sectionResized = imresize(section, [numrows numcols]) % resample
imwrite(sectionResized, 'mynew.tiff'); % save
0

All Articles