Surface from level curves of unkown levels in MATLAB

Viewed 189

I want to obtain a n*m matrix with a approximated "height" at each discrete point. The input is a picture (see link below) of the contours from a map, each contourline represents an 5m increase or decrease of the height.

My thoughts:

  • I imported the picture as a logical png to a matrix called A which means that every contourline in the matrix is a connected strip of '1's and everything else is just 0.
  • My initial thought was to just start in the upper left corner of the matrix, set that height to zero, declare a new matrix 'height' and start with figuring out height(:,1) by adding 5 meters each time we meet a '1' in the A matrix. Knowing the whole first colonn I now for each row start from the left and add 5 m each time we meet a '1'.
  • I quickly realized however that this wouldn't work since there is no way for the algorithm to understand whether it should add or subtract height, i.e if we are running uphill or downhill.
  • If I somehow could approximate the gradient from the intensity of contourlines that would be great even though it would always be possible for a uphill to be a downhill and vice versa but then I could manually decide which is true of these two cases.

Picture: https://i.stack.imgur.com/pRkiY.jpg

1 Answers

WORK IN PROGRESS

%% Read and binarize the image
I=imread('https://i.stack.imgur.com/pRkiY.jpg'); 
I=rgb2gray(I);
I=I>graythresh(I)*255;

%% Get skeleton, i.e. the lines!
sk=bwmorph(~I,'skel',Inf);

%% lines are too thin, dilate them
dilated=~imdilate(sk, strel('disk', 2, 4));

%% label the image!
test=bwlabel(dilated,8);

imshow(test,[]); colormap(plasma); % use colormap parula if you prefer.

enter image description here

Missing: label each adjacent area with a number +1 (or -1) its neighbours (No idea how to do this)

Missing: Interpolate flat areas. This should be doable once the altitudes are known. One can set the pixels in the skeleton image to the altitudes and interpolate the rest using griddata, which will be slow, but still doable.


Disclaimer: not full answer yet, feel free to edit or reuse the code in this answer to further it!

Related