www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/ConvertPGMImageToMapExample.m
%% Convert PGM Image to Map % This example shows how to convert a |.pgm| file which contains a ROS map % into a |BinaryOccupancyGrid| map for use in MATLAB. %% % Import image using |imread|. The image is quite large and % should be cropped to the relevant area. image = imread(fullfile(matlabroot,'examples','robotics','playpen_map.pgm')); imageCropped = image(750:1250,750:1250); imshow(imageCropped) %% % Unknown areas (gray) should be removed and treated as free space. Create % a logical matrix based on a threshold. Depending on your image, this value % could be different. Occupied space should be set as 1 (white in image). imageBW = imageCropped < 100; imshow(imageBW) %% % Create |BinaryOccupancyGrid| object using adjusted map image. map = robotics.BinaryOccupancyGrid(imageBW); show(map)