Class TDirectionalityParamCalculator

  • All Implemented Interfaces:
    IParamCalculator

    public class TDirectionalityParamCalculator
    extends Object
    implements IParamCalculator
    This class is designed to compute Tamura Directionality parameter of each patch of the given BufferedImage, based on a MatLab implementation which is copied below:

    function Fdir = Tamura_Directionality(Im),
    [gx,gy] = gradient(Im);
    [t,r] = cart2pol(gx,gy);
    nbins = 125;
    r(r<.15.*max(r(:))) = 0;
    t0 = t;
    t0(abs(r)<1e-4) = 0;
    r = r(:)';
    t0 = t0(:)';
    Hd = hist(t0,nbins);
    nrm = hist(r(:).^2 + t0(:).^2, nbins);
    fmx = find(Hd==max(Hd));
    ff = 1:length(Hd);
    fmxNew = ones(size(ff)) .* fmx; %added by me
    %ff2 = (ff - fmx).^2;
    ff2 = (ff - fmxNew).^2; %added by me
    Fdir = sum(Hd.*ff2)./sum(nrm);
    Fdir = abs(log(Fdir+eps));
    return;


    Note: Unlike what was assumed in the several implementations of this parameter, the histogram of the images after having the Gradient filter on, does not have one single prominent peak. The histogram seems to be almost exactly symmetric (when all angles from -PI to PI are considered) with at least 5 clear peaks (for 125 bins). Therefore, instead of finding the global max in the histogram, all peaks (local max) are identified and their corresponding index-weights are constructed to have a correct implementation of Directionality parameter.

    For further investigation the following sources are recommended:
    • Original paper: "Textural Features Corresponding Visual Perception" by Hideyuki Tamura, Shunji Mori, Takashi Yamawaki
    • Another Matlab implementation: Tamura.m
    • A C++ implementation: NA
    • Good explanation: CBIR

    Note: Implementation of Gradient is based on the Matlab function, see: gradient.
    Note: To obtain a histogram of an array, the Histogram class from the Smile package is used: Histogram.
    This method (Histogram.histogram) returns a 3-by-k matrix whose last row contains the frequencies. The first row is the lower bound of bins, the second row is the upper bound of bins.

    Author:
    Azim Ahmadzadeh, Data Mining Lab, Georgia State University
    • Constructor Detail

      • TDirectionalityParamCalculator

        public TDirectionalityParamCalculator​(IMeasures.PatchSize patchSize,
                                              IGradientCalculator gradientCalculator,
                                              IPeakDetector peakDetector,
                                              int quantizationLevel)
        Parameters:
        patchSize -
        gradientCalculator - Calculator for gradient of pixel values in the image being processed.
        peakDetector - The class that finds local maxima in arrays
        quantizationLevel - Quantization level for the continuous spectrum of the angles. this is the number of bins in the histogram of the angles. (See the formula for Directionality)
    • Method Detail

      • calculateParameter

        public double[][] calculateParameter​(double[][] image)
        Description copied from interface: IParamCalculator
        This polymorphic method is designed to compute any of the 10 parameters at a time. It iterates over the given image, patch by patch, and then in every patch, pixel by pixel, to compute the parameter value for each patch.
        Note: In all the classes, matrices are read and write, row by row.
        Note: It is required that each class works independently, meaning that they must rely on their own computations. Therefore, some calculations (e.g. mean intensity value) might be calculated several times for different parameters (e.g. once for skewness and another time for std. deviation).
        Note: No fixed range for the color intensity values of the given images is assumed. (colors do not have to be within the range [0,255].)
        Specified by:
        calculateParameter in interface IParamCalculator
        Parameters:
        image - a 2D array representing the input image for which the parameter should be computed.
        Returns:
        a 2D matrix whose each entry corresponds to the calculated parameter for one particular patch of the image.