Image Quantiser for FLXTBL writer

by

 

Used in conjunction with the 'write_flex_material_table.m'

quantise_image(I,CMap)
function Q = quantise_image(I,CMap)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   Title:          Quantise Image
%
%   Description:    Quantises image to values in colourmap
%   Author:         WAI
%   Date:           01/03/2012
%   Version:        1.0                                                   
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   Loop through each pixel, choose closest colour
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% I = imread('q4ebsd_thr.tif')

% Get size
[NumX NumY Dum] = size(I);



% Preallocate
Q = zeros(NumX,NumY);

% Loop through pixels
for XIndex = 1 : NumX
    
    for YIndex = 1 : NumY
        
        % Get colour vect
        PixelColour = squeeze(I(XIndex,YIndex,:));
        
        % Get distance to each point on CMap
        Dist = ((CMap(:,1) - PixelColour(1)).^2 +...
                (CMap(:,2) - PixelColour(2)).^2 +...
                (CMap(:,3) - PixelColour(3)).^2).^0.5;
            
        % Find shortest distance and assign colour from map
        [Dum CIndex] = min(Dist);
        Q(XIndex,YIndex) = CIndex;
        
    end;
    
end;

Contact us