I ended up making an imagedatastore of the labelled images and then creating the categorical images and imwrite()'ing them in a parfor loop. It progressed at 500 images per second and did not slow down.
function y = convert_categorical(imds);
parfor r = 1:length(imds.Files);
[img, info] = imds.readimage(r);
[~, filename, ext] = fileparts(info.Filename);
if exist([path filename ext], 'file') == 0;
q = uint8(ones(227,227));
q(img(:,:,1) == 0 & img(:,:,2) == 0 & img(:,:,3) == 255) = 1;
q(img(:,:,1) == 255 & img(:,:,2) == 255 & img(:,:,3) == 255) = 2;
q(img(:,:,1) == 0 & img(:,:,2) == 255 & img(:,:,3) == 0) = 3;
imwrite(q,[path filename ext]);
end
end
end
