RAPID RADIOMETRIC ENHANCEMENT OF COLORED 3D POINT CLOUDS USING COLOR BALANCING

by

 

Modules for radiometric enhancement of colored 3D point clouds using color balancing

cbalanceTest.m
%
% Test file for the function ENHANCED = CBALANCE(CLOUDS,BASE,METHOD,...)
%

% Workspace
clc
clear all

% Build
fprintf('Building.......................');
if exist('cload','file') ~= 3
    if exist('cload.c','file') == 2
        mex cload.c
    else
        warning('LOAD is not fast enough for loading bulky point clouds. See also CLOAD.');
        cload = @load;
    end;
end;
fprintf('ok!\n');


% Filenames
fprintf('Locating point cloud files.....');
[infilelist, infilepath] = uigetfile({'*.xyz','Plain-files (*.xyz)'; '*.*',  'All Files (*.*)'}, 'Pick a file', 'MultiSelect', 'on');
fprintf('ok!\n');

% Files
fprintf('Loading point cloud files......');
if ~isequal(infilelist,0) && ~isequal(infilepath,0)
    % Full path
    if(iscell(infilelist))
        for n = 1:numel(infilelist)
            infilelist{n} = strrep([infilepath, infilelist{n}], '\', '/');
        end;
    else
        infilelist = {strrep([infilepath, infilelist], '\', '/')};
    end;

    % Data repository
    nfiles = numel(infilelist);
    clouds = cell(n,1);

    % Files
    message = 'Please wait...';
    h = waitbar(0,message,'Name','Loading files...');
    for n = 1:nfiles
        waitbar(n/nfiles,h,infilelist{n});
        data = cload(infilelist{n});
        if iscell(data) data = data{1}; end;
        clouds{n}.points = single(data(:,1:3));
        clouds{n}.colors = uint8(data(:,4:size(data,2)));
        clear data;
    end;
    delete(h);
end;
fprintf('ok!\n');

% Clean up
clear infilelist infilepath n nfiles message h

% Balance
fprintf('Balancing point clouds.........');
enhanced = cbalance(clouds,1,'random');
fprintf('ok!\n');

% Build
if exist('csave','file') ~= 3 && exist('csave.c','file') == 2
    mex csave.c
end;

% Display
if exist('csave','file') == 3
    % Save as wrl and display in browser
    fprintf('Saving as vrml and displaying..');
    csave(clouds,'clouds.wrl',0.10); web('clouds.wrl','-new');
    csave(enhanced,'clouds-enhanced.wrl',0.10); web('clouds-enhanced.wrl','-new');
    fprintf('ok!\n');
else
    % Display in matlab
    fprintf('Displaying as matlab figure....');
    maxnpoints = 10000;
    figure; hold on; axis equal;
    nclouds = numel(clouds);
    for n = 1:nclouds
        npoints = size(clouds{n}.points,1);
        maxnpointspercloud = min(maxnpoints,npoints)/n;
        subplot(1,2,1); r = randi(npoints,maxnpointspercloud,1); scatter3(clouds{n}.points(r,1),clouds{n}.points(r,2),clouds{n}.points(r,3),ones(maxnpointspercloud,1),double(clouds{n}.colors(r,:))/255);
        subplot(1,2,2); r = randi(npoints,maxnpointspercloud,1); scatter3(enhanced{n}.points(r,1),enhanced{n}.points(r,2),enhanced{n}.points(r,3),ones(maxnpointspercloud,1),double(enhanced{n}.colors(r,:))/255);
    end;
    hold off;
    fprintf('ok!\n');
    warning('SAVE is not fast enough for saving bulky point clouds. See also CSAVE.');
end;

% End of test file

Contact us