I = imread('outside.jpg');
hFig2 = figure, hAxesLidar = pcshow(pt,'MarkerSize',50);
dcm1 = datacursormode(hFig1);
dcm1.UpdateFcn = @myfunction;
dcm2 = datacursormode(hFig2);
dcm2.UpdateFcn = @myfunction;
imgIndex = hAxesImg.UserData;
lidarIndex = hAxesLidar.Children(1).UserData;
[rowImage,colImage] = ind2sub([size(I,1) size(I,2)],imgIndex);
Iout = insertMarker(I,[colImage rowImage],'o','Size',80);
Intensity = im2double(pt.Intensity);
[rowLidar,colLidar] = ind2sub([size(locs,1) size(locs,2)],lidarIndex);
scatter3(x(lidarIndex),y(lidarIndex),z(lidarIndex),...
xImage = [-size(I,2)/2 size(I,2)/2;-size(I,2)/2 size(I,2)/2]/100;
zImage = [size(I,1)/2 size(I,1)/2; -size(I,1)/2 -size(I,1)/2]/100;
xImage3D = (colImage-size(I,2)/2)/100;
zImage3D = -(rowImage-size(I,1)/2)/100;
yImage3D = 80*ones(size(xImage3D));
surf(xImage,yImage,zImage,...
'FaceColor','texturemap');
plot3([xImage3D x(lidarIndex)]',...
[yImage3D y(lidarIndex)]',...
[zImage3D z(lidarIndex)]',...
'LineWidth',1,'Color','red');
showMatchedFeatures(I,Intensity,[colImage rowImage],[colLidar rowLidar],'montage');
tform = fitgeotrans([colImage rowImage],[colLidar rowLidar],'projective');
Jregistered = imwarp(I,tform,'OutputView',imref2d([size(locs,1) size(locs,2)]));
ptCol = pointCloud(locs,'Color',Jregistered);
figure, pcshow(ptCol,'MarkerSize',80);
[xq,yq] = meshgrid(1:size(locs,2),1:size(locs,1));
F1 = scatteredInterpolant(colLidar,rowLidar,colImage-colLidar,'natural','linear');
F2 = scatteredInterpolant(colLidar,rowLidar,rowImage-rowLidar,'natural','linear');
Jregistered2 = imwarp(I,D);
figure, image(Jregistered2);
ptCol = pointCloud(locs,'Color',Jregistered2);
figure, pcshow(ptCol,'MarkerSize',30);
pcwrite(ptCol,'outside_colorized.ply');