Small Satellites

Home » Featured » Distance Transform Path Planning Algorithm

Distance Transform Path Planning Algorithm

clc;close all;clear all;

Input Map

RGB = imread('Mapn.png');
figure('Position',[600 0 600 1000],'color','k');
image(RGB);
hold on;
axis off
axis image
hold off;
% Convert to binary image matrix and inverse matrix values
I = rgb2gray(RGB);
binaryImage = im2bw(RGB, 0.3);
binaryImage = 1-binaryImage;
% Inital pose
xs = 540; ys = 750;
% Goal Pose
xg = 150; yg = 150;

dist_01

Distance to Goal

sz  = size(binaryImage);
for i = 1:sz(1)
    for j = 1:sz(2)
       rg(i,j) = sqrt((i-yg)^2 +(j - xg)^2);
      end
end
% Pose Matrix
pose = zeros(sz(1),sz(2));
pose(ys,xs) = 1;
pose(yg,xg) = 1;
Di = 15; % Distance of influence of the obstacles
% Compute for every pixel the distance to the nearest obstacle(non zero
% elements which after inversion corespondent to the obstacles)
[D,IDX] = bwdist(binaryImage);
for i = 1:sz(1)
    for j = 1:sz(2)
        rd = D(i,j);
        if (rd <= Di)
            rg(i,j)  = 1e6;
        end
    end
end

Distance Transform Path Planning Algorithm

figure('Position',[600 0 600 1000],'color','k');
hold on;
image(RGB);
colormap gray
contour(rg,15);
spy(pose,'*r');
axis off
axis image
title('Distance Transform Path Planning Algorithm','color','w');
x = xs; y = ys;
last = rg(y-1,x-1);
while (x ~= xg)||(y ~= yg)
    dis =[ rg(y-1,x-1), rg(y-1,x),rg(y-1,x+1);
        rg(y,x-1), rg(y,x) ,rg(y,x+1);
        rg(y+1,x-1), rg(y+1,x),rg(y+1,x+1)];
     m = min(dis(:));
     [r,c] = find(dis == m);
   rg(y,x) = 1E6;
   y = y-2+r;
   x = x-2+c;
   pose(y,x) = 1;
  end
spy(pose,'.r');
set(gcf, 'InvertHardCopy', 'off');
hold off;

dist_02

Advertisements

2 Comments

  1. Eng.Emad says:

    please i need the Mapn.png that used with these examples
    Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Recent Post

%d bloggers like this: