baidut
6/3/2017 - 1:39 AM

颜色失真评估,该实现价值不大,建议使用 TestImage

颜色失真评估,该实现价值不大,建议使用 TestImage

function evalColorAccuary(resultFiles, labelFile, varargin)
% gt --- result
% raw --- result

nMethod = 7%6;

% < Test

%%
% generate a list of filename and color distortion
rawImages = eachfile('datasets\ColourCharts\*.tiff');
files = eachfile('datasets\ColourCharts\*.PNG'); % 'ColourCharts\*.PNG'
fid = fopen('colormatchnessColourCharts_exp4.txt','w');
fid2 = fopen('colordistortionColourCharts_exp4.txt','w');
scores = zeros([1 numel(files)]);

labelData = ColorCheckerLabeler('datasets\ColourCharts\label.txt');

checkerboard = colorcheck.RGBvalue; %% need to load colorcheck.mat
checkerboard = im2double(reshape(checkerboard, [], 1, 3));

% checkerboard = rgb2hsv(checkerboard);
% checkerboard = checkerboard(:,:,1);

default.doWithRawFile = false;
param = ezInput(varargin, default);

for n = 1:numel(rawImages)
    
    if param.doWithRawFile
        rawImg = im2double(imread(rawImages{n}));

        s = labelData.readLine(n);
        centerPoints = labelData.get24Points(s.points);

        mask = false(size(rawImg));
        for p = 1:size(centerPoints, 1)
            x = centerPoints(p,1);
            y = centerPoints(p,2);
            %mask(y:(y+10),x:(x+10), :) = 1;
            mask(y,x,:) = 1;
        end
    end
    
    %disp(rawImages{n});
        
    for m = 1:nMethod
        %fprintf('%s',files{(n-1)*nMethod+m});
        enhancedImg = im2double(imread(files{(n-1)*nMethod+m}));
        enhancedImg = reshape(enhancedImg(mask), [], 1, 3);
        
        error = (rgb2norm(checkerboard)- rgb2norm(enhancedImg)).^2;
%         enhancedImg = rgb2hsv(enhancedImg);
%         enhancedImg = enhancedImg(:,:,1);
        
        %error = (checkerboard- enhancedImg).^2;
        
        %score = sum(error(:));
        % normError = exp (- error);
        normError = (exp (- error) ).^8;
        score = mean(normError(:));  %sum(normError(:)) / numel(normError);
        fprintf(fid, '%f\t', score);
        
        distortion = sum(error(:)) / numel(checkerboard);
        fprintf(fid2, '%f\t', distortion);
    end
    fprintf(fid, '\n');
    fprintf(fid2, '\n');
end

fclose all;

return;



% generate a list of filename and cni
rawImages = eachfile('datasets\ColourCharts\*.tiff');
files = eachfile('datasets\ColourCharts\*.PNG'); % 'ColourCharts\*.PNG'
fid = fopen('colordistortionColourCharts.txt','w');
scores = zeros([1 numel(files)]);

for n = 1:nMethod*10 %1:numel(files)
    file = files{n};
    rawImg = im2double(imread(rawImages{ceil(n/nMethod)}));
    enhancedImg = im2double(imread(file));
    
    error = (rgb2norm(rawImg)- rgb2norm(enhancedImg)).^2;
    normError = (exp (- error) ).^4;
    score = sum(normError(:)) / numel(rawImg);
    fprintf(fid, '%f\t', score);
    %fprintf('%f\t', score);
     
    if mod(n, nMethod) == 0
        fprintf(fid, '\n');
    end
end

%fclose(fid);
classdef TestColorChecker < Test
    % 24 color patch
    methods
        function on_color_checker(resultFiles, labelFile, varargin)
            % gt --- result
            % raw --- result
            
            % data proc
            % imread and resize to 1x24 
            
            nMethod = 7%6;
            
            % on_image
            % on_file
            % on_colorch
            
            % < Test
            
            %%
            % generate a list of filename and color distortion
            rawImages = eachfile('datasets\ColourCharts\*.tiff');
            files = eachfile('datasets\ColourCharts\*.PNG'); % 'ColourCharts\*.PNG'
            fid = fopen('colormatchnessColourCharts_exp4.txt','w');
            fid2 = fopen('colordistortionColourCharts_exp4.txt','w');
            scores = zeros([1 numel(files)]);
            
            labelData = ColorCheckerLabeler('datasets\ColourCharts\label.txt');
            
            checkerboard = colorcheck.RGBvalue; %% need to load colorcheck.mat
            checkerboard = im2double(reshape(checkerboard, [], 1, 3));
            
            % checkerboard = rgb2hsv(checkerboard);
            % checkerboard = checkerboard(:,:,1);
            
            default.doWithRawFile = false;
            param = ezInput(varargin, default);
            
            for n = 1:numel(rawImages)
                
                if param.doWithRawFile
                    rawImg = im2double(imread(rawImages{n}));
                    
                    s = labelData.readLine(n);
                    centerPoints = labelData.get24Points(s.points);
                    
                    mask = false(size(rawImg));
                    for p = 1:size(centerPoints, 1)
                        x = centerPoints(p,1);
                        y = centerPoints(p,2);
                        %mask(y:(y+10),x:(x+10), :) = 1;
                        mask(y,x,:) = 1;
                    end
                end
                
                %disp(rawImages{n});
                
                for m = 1:nMethod
                    %fprintf('%s',files{(n-1)*nMethod+m});
                    enhancedImg = im2double(imread(files{(n-1)*nMethod+m}));
                    enhancedImg = reshape(enhancedImg(mask), [], 1, 3);
                    
                    error = (rgb2norm(checkerboard)- rgb2norm(enhancedImg)).^2;
                    %         enhancedImg = rgb2hsv(enhancedImg);
                    %         enhancedImg = enhancedImg(:,:,1);
                    
                    %error = (checkerboard- enhancedImg).^2;
                    
                    %score = sum(error(:));
                    % normError = exp (- error);
                    normError = (exp (- error) ).^8;
                    score = mean(normError(:));  %sum(normError(:)) / numel(normError);
                    fprintf(fid, '%f\t', score);
                    
                    distortion = sum(error(:)) / numel(checkerboard);
                    fprintf(fid2, '%f\t', distortion);
                end
                fprintf(fid, '\n');
                fprintf(fid2, '\n');
            end
            
            fclose all;
            
            return;
            
            
            
            % generate a list of filename and cni
            rawImages = eachfile('datasets\ColourCharts\*.tiff');
            files = eachfile('datasets\ColourCharts\*.PNG'); % 'ColourCharts\*.PNG'
            fid = fopen('colordistortionColourCharts.txt','w');
            scores = zeros([1 numel(files)]);
            
            for n = 1:nMethod*10 %1:numel(files)
                file = files{n};
                rawImg = im2double(imread(rawImages{ceil(n/nMethod)}));
                enhancedImg = im2double(imread(file));
                
                error = (rgb2norm(rawImg)- rgb2norm(enhancedImg)).^2;
                normError = (exp (- error) ).^4;
                score = sum(normError(:)) / numel(rawImg);
                fprintf(fid, '%f\t', score);
                %fprintf('%f\t', score);
                
                if mod(n, nMethod) == 0
                    fprintf(fid, '\n');
                end
            end
            
            %fclose(fid);
            
        end
    end
end