Created
January 4, 2018 19:34
-
-
Save dpattison3/4c043bff1e2d145ecfb2eacbb67031f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% | |
% | |
% This is a script for reading the labelme annotations and outputing a | |
% dataset that can be used for training a CNN. It is specifically designed | |
% to work with KittiSeg network which uses annotation images with color | |
% masks denoting the labels. | |
% | |
%#ok<*AGROW> | |
% | |
%% Read the images and annotations | |
clear;close all;clc; | |
ANNOTATION_DIR = '../collection/Annotations/'; | |
IMAGE_DIR = '../collection/Images/'; | |
OUTPUT_DIR = '../dataset/ground_truth/'; | |
[D, XML] = LMdatabase(ANNOTATION_DIR); | |
%% Filter the images not annotated | |
% filter all images without any obects (ie. ones that have not been | |
% annotated) | |
database = []; | |
for i = 1 : length(D) | |
if isfield(D(i).annotation, 'object') | |
database = [database; D(i).annotation]; | |
end | |
end | |
%% Parse annotations and save annotated images | |
% red and purple are the default colors | |
for j = 1 : length(database) | |
[mask, class] = LMobjectmask(database(j), IMAGE_DIR); | |
[r,c,~] = size(mask); | |
mask_composite = false(r,c); | |
for i = 1 : length(class) | |
if strcmp(class(i),'line') || strcmp(class(i),'pothole') | |
mask_composite = mask_composite | mask(:,:,i); | |
end | |
end | |
annotation_image = cat(3, 255*ones(r,c), zeros(r,c,2)); | |
blue_mask = cat(3, false(r,c,2), mask_composite); | |
annotation_image(blue_mask) = annotation_image(blue_mask) + 255; | |
imwrite(annotation_image, strcat(OUTPUT_DIR, database(j).filename)); | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment