示例#1
0
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan scan = inputArgs[0] as TScan;
            int offset = (int) options[0].Value;

            int width = (int) scan.Size.Width;
            int height = (int) scan.Size.Height;

            float[] data = scan.Data;

            double quadrat_sum = 0.0;
            unsafe {
                fixed (float* ptrData = data) {
                    float* src = ptrData;

                    for (int i = 0; i < width * height; i++) {
                        quadrat_sum += *src;
                        src++;
                    }
                }
            }

            double[] histogram = new double[offset];
            for (int o = 0; o < offset; o++) {
                for (int y = 0; y < height - o; y++) {
                    for (int x = 0; x < width - o; x++) {
                        histogram[o] += data[y * width + x] * data[(y + o) * width + (x + o)];
                    }
                }

                histogram[o] /= quadrat_sum;
            }

            return new IType[] { new THistogram(histogram) };
        }
示例#2
0
文件: Moments.cs 项目: jfreax/BAIMP
        public unsafe override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan tScan = inputArgs[0] as TScan;
            float[] data = tScan.Data;

            int width = (int) tScan.Size.Width;
            int height = (int) tScan.Size.Height;
            float max = data.Max();

            double M00 = 0, M10 = 0, M01 = 0;
            double M11 = 0, M20 = 0, M02 = 0;
            double M12 = 0, M21 = 0;
            double M30 = 0, M03 = 0;

            double InvM00 = 0;
            double CenterX = 0, CenterY = 0;

            for (int y = 0; y < height; y++) {
                double yNorm = (double)y / height;
                for (int x = 0; x < width; x++) {
                    double v = data[y * width + x] / max;

                    double xNorm = (double)x / width;

                    M00 += v;
                    M01 += yNorm * v;
                    M10 += xNorm * v;

                    M11 += xNorm * yNorm * v;
                    M02 += yNorm * yNorm * v;
                    M20 += xNorm * xNorm * v;

                    M21 += xNorm * xNorm * yNorm * v;
                    M12 += xNorm * yNorm * yNorm * v;

                    M30 += xNorm * xNorm * xNorm * v;
                    M03 += yNorm * yNorm * yNorm * v;
                }
            }

            InvM00 = 1f / M00;
            CenterX = M10 * InvM00;
            CenterY = M01 * InvM00;

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("M00", M00)
                    .AddFeature("M01", M01)
                    .AddFeature("M10", M10)
                    .AddFeature("M11", M11)
                    .AddFeature("M02", M02)
                    .AddFeature("M20", M20)
                    .AddFeature("M21", M21)
                    .AddFeature("M12", M12)
                    .AddFeature("M30", M30)
                    .AddFeature("M03", M03)
                    .AddFeature("CenterX", CenterX)
                    .AddFeature("CenterY", CenterY)
            };
        }
示例#3
0
文件: GLRLM.cs 项目: jfreax/BAIMP
        public unsafe override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            int bpp = (int) options[0].Value;
            int p = (int) Math.Pow(2, bpp);

            TScan tScan = inputArgs[0] as TScan;
            float[] data = tScan.DataAs(bpp);

            int height = (int) tScan.Size.Height;
            int width = (int) tScan.Size.Width;
            float[,] matrix = new float[p, width+1];

            int maxRunLength = 0;

            for (int y = 0; y < height; y++) {
                int runLength = 1;
                for (int x = 1; x < width; x++) {
                    int a = (int) data[width * y + (x - 1)];
                    int b = (int) data[width * y + x];

                    if (Math.Abs(a - b) <= float.Epsilon)
                        runLength++;
                    else {
                        matrix[a, runLength]++;
                        if (runLength > maxRunLength) {
                            maxRunLength = runLength;
                        }

                        runLength = 1;
                    }

                    if ((Math.Abs(a - b) <= float.Epsilon) && (x == width - 1)) {
                        matrix[a, runLength]++;
                        if (runLength > maxRunLength) {
                            maxRunLength = runLength;
                        }
                    }
                    if ((Math.Abs(a - b) > float.Epsilon) && (x == width - 1)) {
                        matrix[b, 1]++;
                    }
                }
            }

            //if (crop) { // make this an option?
            if (maxRunLength < width+1) {
                float[,] matrixTmp = new float[p, maxRunLength+1];
                for (int y = 0; y < maxRunLength+1; y++ ) {
                    for (int x = 0; x < p; x++) {
                        matrixTmp[x, y] = matrix[x, y];
                    }
                }

                matrix = matrixTmp;
            }
            //}

            IType[] ret = { new TMatrix(matrix) };
            return ret;
        }
示例#4
0
文件: GLDM.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan scan = inputArgs[0] as TScan;
            int bpp = (int) options[0].Value;
            int dx = (int) options[1].Value;
            int dy = (int) options[2].Value;
            int p = (int) Math.Pow(2, bpp);

            TMatrix matrix;
            if (bpp > 10) {
                matrix = new TMatrix(new SparseMatrix<float>(p + 1, p + 1));
            } else {
                matrix = new TMatrix(new float[p + 1, p + 1]);
            }

            int width = (int) scan.Size.Width;
            int height = (int) scan.Size.Height;

            int startX = Math.Max(0, -dx);
            int startY = Math.Max(0, -dy);

            int endX = width - Math.Max(0, dx);
            int endY = height - Math.Max(0, dy);

            //			float[] data = scan.Data;
            //			double max = data.Max();
            //
            //			int offset = Math.Max(0, dx);
            //			if (max > 0.0) {
            //				unsafe {
            //					fixed (float* ptrData = data) {
            //						float* src = ptrData;
            //
            //						int oldProgress = 0;
            //						for (int y = startY; y < endY; y++) {
            //							for (int x = startX; x < endX; x++, src++) {
            //								int posWithOffset = ((y + dy) * width) + (x + dx);
            //
            //								int fromValue = (int) ((*src / max) * p);
            //								int toValue = (int) ((data[posWithOffset] / max) * p);
            //								matrix[fromValue, toValue] += increment;
            //
            //							}
            //							src += offset;
            //
            //							int progress = (int) (y * 100.0) / height;
            //							if (progress - oldProgress > 10) {
            //								oldProgress = progress;
            //								SetProgress(progress);
            //							}
            //						}
            //					}
            //				}
            //			}

            IType[] ret = { matrix };
            return ret;
        }
示例#5
0
文件: Census.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan scan = inputArgs[0] as TScan;
            byte[] scanData = scan.DataAs8bpp();

            int width = scan.Width;
            int height = scan.Height;

            return null;
        }
示例#6
0
文件: Writer.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            IType input = inputArgs[0];
            if (input.GetType() == typeof(TMatrix)) {
                TMatrix matrix = input as TMatrix;
                Console.WriteLine(matrix);
            }

            return null;
        }
示例#7
0
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            THistogram tHistogram = inputArgs[0] as THistogram;
            double[] histogram = tHistogram.Data;

            double mean = histogram.Mean();
            double s = histogram.StandardDeviation(mean);

            double skewness = 0.0;
            double kurtosis = 0.0;

            int lastValley = -1;
            int lastHill = -1;
            int hillCount = histogram[0] - histogram[1] > 0 ? 1 : 0;
            for (int i = 0; i < histogram.Length-1; i++) {
                skewness += Math.Pow(histogram[i] - mean, 3);
                kurtosis += Math.Pow(histogram[i] - mean, 4);

                double diff = histogram[i] - histogram[i + 1];

                if (diff > 0 && lastValley == -1) { // new valley begins here
                    lastValley = i;
                    lastHill = -1; // finished hill
                } else if (diff < 0 && lastHill == -1) { // new hill begins here
                    hillCount++;
                    lastHill = i;
                    if (lastValley != -1) { // there was a valley before
                        lastValley = -1; // finished valley
                    }
                }
            }

            skewness += Math.Pow(histogram[histogram.Length-1] - mean, 3);
            kurtosis += Math.Pow(histogram[histogram.Length-1] - mean, 4);
            skewness /= (histogram.Length - 1) * s * s * s;
            kurtosis /= (histogram.Length - 1) * s * s * s * s;

            double regularity = (double) hillCount / (histogram.Length / 2);

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("regularity", regularity)
                    .AddFeature("skewness", skewness)
                    .AddFeature("kurtosis", kurtosis)
                };
        }
示例#8
0
文件: Windower.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            int blockWidth = (int) options[0].Value;
            int blockHeight = (int) options[1].Value;
            Xwt.Size blockSize = new Xwt.Size(blockWidth, blockHeight);

            TScan scan = inputArgs[0] as TScan;

            int width = (int) scan.Size.Width;
            int height = (int) scan.Size.Height;

            float[] inputData = scan.Data;
            for (int y = 0; y < height-blockHeight; y += blockHeight) {
                for (int x = 0; x < width-blockWidth; x+= blockWidth) {
                    float[] data = new float[blockWidth*blockHeight];

                    bool empty = true;
                    for (int i = 0; i < blockWidth; i++) {
                        for (int j = 0; j < blockHeight; j++) {
                            float value = inputData[x + i + ((y + j) * width)];
                            data[i + (j * blockWidth)] = value;

                            if (value > 0.0) {
                                empty = false;
                            }
                        }
                    }

                    if (!empty) {
                        TScan block = new TScan(data, blockSize, scan.IsMultipleAccessModeOn);
                        Yield(new IType[] { block }, null);
                    }
                }
            }

            return null;
        }
示例#9
0
 /// <summary>
 /// Executes the algorithm.
 /// </summary>
 /// <param name="requestedData">Requested data.</param>
 /// <param name="options">User setted options</param>
 /// <param name="inputArgs">Input arguments.</param>
 /// <remarks>
 /// Return null, when no more data is available (important for sequential data output).
 /// Use Yield() function to return data when you want to output more then one result per input.
 /// </remarks>
 public abstract IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs);
示例#10
0
文件: Haralick.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TMatrix tMatrix = inputArgs[0] as TMatrix;
            if (tMatrix == null) {
                return null;
            }

            HaralickIntern h = new HaralickIntern(tMatrix);

            // features
            double asm = 0.0, contrast = 0.0, correlation, variance = 0.0, homogeneity = 0.0;
            double sumAverage = 0.0, sumVariance = 0.0, sumEntropy = 0.0, entropy = 0.0;
            double diffVariance = 0.0, diffEntropy = 0.0;
            double informationMeasure1 = 0.0, informationMeasure2 = 0.0;

            // temp variables
            double correlationStep = 0.0;
            double informationMeasure1Step = 0.0, informationMeasure2Step = 0.0;
            double[] xydiff = new double[Math.Max(h.InputMatrix.Width, h.InputMatrix.Height)];

            double mean = h.InputMatrix.Mean;
            // compute
            //Parallel.For(0, h.InputMatrix.GetLength(0), i => {
            for (int i = 0; i < h.InputMatrix.Width; i++) {
                for (int j = 0; j < h.InputMatrix.Height; j++) {
                    double value = h.InputMatrix[i, j];

                    xydiff[Math.Abs(i - j)] += h.InputMatrix[i, j];
                    correlationStep += (i * j) * h.InputMatrix[i, j];

                    informationMeasure1Step -= h.InputMatrix[i, j] * Math.Log(h.Px[i] * h.Py[j] + double.Epsilon, 2);
                    informationMeasure2Step -= h.Px[i] * h.Py[j] * Math.Log(h.Px[i] * h.Py[j] + double.Epsilon, 2);

                    asm += value * value;
                    variance += (i - mean) * h.InputMatrix[i, j];
                    homogeneity += h.InputMatrix[i, j] / (double) (1 + (i - j) * (i - j));
                }
            } //);

            correlation = (correlationStep - h.MeanX * h.MeanY) / (h.StandardDeviationX * h.StandardDeviationY);

            for (int n = 0; n < xydiff.Length; n++) {
                contrast += (n * n) * xydiff[n];
            }

            SetProgress(75);

            sumEntropy = h.Sums.Entropy(double.Epsilon);
            for (int i = 0; i < h.Sums.Length; i++) {
                sumAverage += i * h.Sums[i];
                sumVariance += (i - sumEntropy) * (i - sumEntropy) * h.Sums[i];
            }

            entropy = h.InputMatrix.Entropy(float.Epsilon);
            diffVariance = xydiff.Variance();
            diffEntropy = xydiff.Entropy(double.Epsilon);

            double entropyX = h.Px.Entropy(double.Epsilon);
            double entropyY = h.Py.Entropy(double.Epsilon);
            informationMeasure1 = (entropy - informationMeasure1Step) / Math.Max(entropyX, entropyY);

            informationMeasure2 = Math.Pow(1.0 - Math.Exp(-2 * (informationMeasure2Step - entropy)), 0.5);

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("asm", asm)
                    .AddFeature("contrast", contrast)
                    .AddFeature("correlation", correlation)
                    .AddFeature("variance", variance)
                    .AddFeature("homogeneity", homogeneity)
                    .AddFeature("sumAverage", sumAverage)
                    .AddFeature("sumVariance", sumVariance)
                    .AddFeature("sumEntropy", sumEntropy)
                    .AddFeature("entropy", entropy)
                    .AddFeature("diffVariance", diffVariance)
                    .AddFeature("diffEntropy", diffEntropy)
                    .AddFeature("informationMeasure1", informationMeasure1)
                    .AddFeature("informationMeasure2", informationMeasure2)
            };
        }
示例#11
0
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan tScan = inputArgs[0] as TScan;
            bool normalize = (bool) options[0].Value;

            float[] data = tScan.Data;

            int width = tScan.Width;
            int height = tScan.Height;

            if (normalize) {
                float mean = data.Mean();
                for (int y = 0; y < height; y++) {
                    for (int x = 0; x < width; x++) {
                        data[(y * width) + x] /= mean;
                    }
                }
            }

            float[,] l5e5d = new float[(width - 3), (height - 3)];
            float[,] l5s5d = new float[(width - 3), (height - 3)];
            float[,] l5r5d = new float[(width - 3), (height - 3)];
            float[,] e5e5d = new float[(width - 3), (height - 3)];
            float[,] e5s5d = new float[(width - 3), (height - 3)];
            float[,] e5r5d = new float[(width - 3), (height - 3)];
            float[,] e5l5d = new float[(width - 3), (height - 3)];
            float[,] s5l5d = new float[(width - 3), (height - 3)];
            float[,] s5e5d = new float[(width - 3), (height - 3)];
            float[,] s5r5d = new float[(width - 3), (height - 3)];
            float[,] s5s5d = new float[(width - 3), (height - 3)];
            float[,] r5r5d = new float[(width - 3), (height - 3)];
            float[,] r5e5d = new float[(width - 3), (height - 3)];
            float[,] r5s5d = new float[(width - 3), (height - 3)];
            float[,] r5l5d = new float[(width - 3), (height - 3)];
            for (int y = 2; y < height - 2; y++) {
                for (int x = 2; x < width - 2; x++) {
                    for (int i = -2; i <= 2; i++) {
                        for (int j = -2; j <= 2; j++) {
                            l5e5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * l5e5[i + 2, j + 2];
                            l5s5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * l5s5[i + 2, j + 2];
                            l5r5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * l5r5[i + 2, j + 2];
                            e5e5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * e5e5[i + 2, j + 2];
                            e5s5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * e5s5[i + 2, j + 2];
                            e5r5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * e5r5[i + 2, j + 2];
                            e5l5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * e5l5[i + 2, j + 2];
                            s5l5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * s5l5[i + 2, j + 2];
                            s5e5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * s5e5[i + 2, j + 2];
                            s5r5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * s5r5[i + 2, j + 2];
                            s5s5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * s5s5[i + 2, j + 2];
                            r5r5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * r5r5[i + 2, j + 2];
                            r5e5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * r5e5[i + 2, j + 2];
                            r5s5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * r5s5[i + 2, j + 2];
                            r5l5d[x - 2, y - 2] += data[((y + j) * width) + x + i] * r5l5[i + 2, j + 2];
                        }
                    }
                }
            }

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("L5E5/E5L5", l5e5d.AbsMean() / e5l5d.AbsMean())
                    .AddFeature("L5S5/S5L5", l5s5d.AbsMean() / s5l5d.AbsMean())
                    .AddFeature("L5R5/R5L5", l5r5d.AbsMean() / r5l5d.AbsMean())
                    .AddFeature("E5S5/S5E5", e5s5d.AbsMean() / s5e5d.AbsMean())
                    .AddFeature("E5R5/R5E5", e5r5d.AbsMean() / r5e5d.AbsMean())
                    .AddFeature("S5R5/R5S5", s5r5d.AbsMean() / r5s5d.AbsMean())
                    .AddFeature("E5E5", e5e5d.AbsMean())
                    .AddFeature("S5S5", s5s5d.AbsMean())
                    .AddFeature("R5R5", r5r5d.AbsMean())
                };
        }
示例#12
0
文件: LBP.cs 项目: jfreax/BAIMP
        public unsafe override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan scan = inputArgs[0] as TScan;
            int blockSize = (int) Math.Pow(2, (int) options[0].Value);
            bool normalize = (bool) options[1].Value;
            bool rotationInvariant = (bool) options[2].Value;
            bool uniformLBP = (bool) options[3].Value;

            if (uniformLBP) {
                rotationInvariant = true;
            }

            byte[] scanData = scan.DataAs8bpp();

            int width = scan.Width;
            int height = scan.Height;

            int[] nPatterns = new int[height * width];

            fixed (byte* ptrData = scanData) {
                fixed (int* ptrNPatterns = nPatterns) {
                    // skip the first line
                    byte* data = ptrData + width;
                    int* neighbor = ptrNPatterns + width;

                    for (int y = 1; y < height - 1; y++) {

                        // and skip first column
                        data++;
                        neighbor++;

                        for (int x = 1; x < width - 1; x++, data++, neighbor++) {
                            byte n11 = *(data + width + 1);
                            byte n12 = *(data + 1);
                            byte n13 = *(data - width + 1);
                            byte n21 = *(data + width);
                            byte n22 = *data;
                            byte n23 = *(data - width);
                            byte n31 = *(data + width - 1);
                            byte n32 = *(data - 1);
                            byte n33 = *(data - width - 1);

                            int sum = 0;
                            if (n22 < n11)
                                sum += 1 << 0;
                            if (n22 < n12)
                                sum += 1 << 1;
                            if (n22 < n13)
                                sum += 1 << 2;
                            if (n22 < n21)
                                sum += 1 << 3;
                            if (n22 < n23)
                                sum += 1 << 4;
                            if (n22 < n31)
                                sum += 1 << 5;
                            if (n22 < n32)
                                sum += 1 << 6;
                            if (n22 < n33)
                                sum += 1 << 7;

                            if (rotationInvariant && sum != 0) {
                                while ((sum & 0x80) == 0) {
                                    sum <<= 1;
                                }
                            }

                            *neighbor = sum;
                        }

                        neighbor++;
                        data++;
                    }
                }
            }

            int numberOfBlocksH = width / blockSize;
            int numberOfBlocksV = height / blockSize;

            // compute histogram
            double[] histogram;
            if (uniformLBP) {
                histogram = new double[6 * numberOfBlocksH * numberOfBlocksV];
                int blockNumber = 0;
                for (int y = 0; y < height; ) {
                    for (int x = 0; x < width; ) {
                        switch (nPatterns[x + y * width]) {
                        case 0: // flat
                            histogram[6 * blockNumber]++;
                            break;
                        case 255: // flat
                            histogram[1 + 6 * blockNumber]++;
                            break;
                        case 128: // line end
                            histogram[2 + 6 * blockNumber]++;
                            break;
                        case 224: // edge
                            histogram[3 + 6 * blockNumber]++;
                            break;
                        case 252: // corner
                            histogram[4 + 6 * blockNumber]++;
                            break;
                        default:
                            histogram[5 + 6 * blockNumber]++;
                            break;
                        }

                        x++;
                        if (x % blockSize == 0) {
                            blockNumber++;
                        }
                    }

                    y++;
                    if (y % blockSize != 0) {

                        blockNumber -= numberOfBlocksH;
                    }
                }

            } else {
                histogram = new double[256];
                for (int y = 0; y < height; y++) {
                    for (int x = 0; x < width; x++) {
                        histogram[nPatterns[x + y * width]]++;
                    }
                }
                histogram[0] = 0d;
            }

            double histogramMax = histogram.Max();

            TFeatureList<double> featureList = new TFeatureList<double>();
            for (int i = 0; i < histogram.Length; i++) {
                if (normalize) {
                    histogram[i] /= histogramMax;
                }

                featureList.AddFeature("LBP#" + i, histogram[i]);
            }
            return new IType[] {
                featureList,
                new THistogram(histogram)
            };
        }
示例#13
0
文件: Galloway.cs 项目: jfreax/BAIMP
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TMatrix matrix = inputArgs[0] as TMatrix;
            if (matrix == null) {
                return null;
            }

            double numberOfRuns = matrix.Sum; // R_G

            double sre = 0.0, lre = 0.0, lgre = 0.0, hlre = 0.0;
            double gln = 0.0, rln = 0.0;

            int n = 0; // number of pixels in original image
            for (int i = 0; i < matrix.Width; i++) {
                double glnInner = 0.0;
                for (int j = 0; j < matrix.Height; j++) {
                    if (matrix[i, j] >= double.Epsilon) {
                        glnInner += matrix[i, j];

                        if (j > 0) {
                            n += (int) (matrix[i, j] * j);
                            sre += matrix[i, j] / (j * j);
                            lre += matrix[i, j] * (j * j);
                        }
                        if (i > 0) {
                            lgre += matrix[i, j] / (i * i);
                            hlre += matrix[i, j] * (i * i);
                        }
                    }
                }
                gln += glnInner * glnInner;
            }

            SetProgress(50);

            for (int j = 0; j < matrix.Height; j++) {
                double rlnInner = 0.0;
                for (int i = 0; i < matrix.Width; i++) {
                    rlnInner += matrix[i, j];
                }
                rln += rlnInner * rlnInner;
            }

            sre /= numberOfRuns;
            lre /= numberOfRuns;
            gln /= numberOfRuns;
            rln /= numberOfRuns;

            double rp = numberOfRuns / n;

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("shortRunEmphasis", sre)
                    .AddFeature("longRunEmphasis", lre)
                    .AddFeature("grayLevelNonUniformity", gln)
                    .AddFeature("runLengthNonUniformity", rln)
                    .AddFeature("runPercentage", rp)
                    .AddFeature("lowGrayLevelRunEmphasis", lgre)
                    .AddFeature("highGrayLevelRunEmphasis", hlre)
            };
        }
示例#14
0
文件: Tamura.cs 项目: jfreax/BAIMP
        public unsafe override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            TScan tScan = inputArgs[0] as TScan;
            float[] data = tScan.Data;

            int nrOfBins = (int) options[0].Value;

            int width = (int) tScan.Size.Width;
            int height = (int) tScan.Size.Height;

            double coarsness = 0.0, contrast = 0.0, directionality = 0.0;

            float[,] sumAreaTable = SumAreaTable(data, width, height);

            float mean = data.Mean();
            float sigma = data.StandardDeviation(mean);
            double moment4 = 0.0;

            double[] histogram = new double[nrOfBins];
            double binWindow = (histogram.Length - 1) / Math.PI;
            int bin = -1;

            int oldProgress = 0;
            for (int y = 0; y < height; y++) {
                for (int x = 0; x < width; x++) {
                    moment4 += Math.Pow(data[y * width + x] - mean, 4);

                    if (x > 0 && y > 0) {
                        coarsness += Math.Pow(2, Sopt(sumAreaTable, x, y));

                        if (x < width - 1 && y < height - 1) {
                            double v = DeltaV(data, width, x, y);
                            double h = DeltaH(data, width, x, y);
                            if (h > 0.0 && v > 0.0) {
                                bin = (int) ((Math.PI / 2 + Math.Atan(v / h)) * binWindow);
                                histogram[bin]++;
                            }
                        }
                    }
                }

                int progress = (int) (y * 100.0) / height;
                if (progress - oldProgress > 5) {
                    oldProgress = progress;
                    SetProgress(progress);
                }
            }

            coarsness /= height * width;

            if (sigma > 0) { // sigma <= 0 only if image is complete black
                double alpha4 = moment4 / (Math.Pow(sigma, 4));
                contrast = sigma / Math.Pow(alpha4, 0.25);
            }

            double histSum = histogram.Sum();
            for (int i = 0; i < histogram.Length; i++) {
                histogram[i] /= histSum;
            }

            int lastValley = -1;
            int lastHill = -1;
            int hillCount = 0; // n_p
            for (int i = 0; i < histogram.Length-1; i++) {
                double diff = histogram[i] - histogram[i + 1];

                if (diff > 0 && lastValley == -1) { // new valley begins here
                    lastValley = i;
                    lastHill = -1; // finished hill
                } else if (diff < 0 && lastHill == -1) { // new hill begins here
                    hillCount++;
                    lastHill = i;
                    if (lastValley != -1) { // there was a valley before
                        for (int j = lastValley; j < i; j++) {
                            directionality += Math.Pow(j - i, 2) * (histogram[j]);
                        }

                        lastValley = -1; // finished valley
                    }
                } else if (diff < 0) { // it still goes down
                    directionality += Math.Pow(i - lastHill, 2) * (histogram[i]);
                }
            }

            directionality = 1 - (binWindow * hillCount * directionality);

            return new IType[] {
                new TFeatureList<double>()
                    .AddFeature("coarsness", coarsness)
                    .AddFeature("contrast", contrast)
                    .AddFeature("directionality", directionality),
                new THistogram(histogram)
            };
        }
示例#15
0
        public override IType[] Run(Dictionary<RequestType, object> requestedData, BaseOption[] options, IType[] inputArgs)
        {
            ScanCollection scans = requestedData[RequestType.ScanCollection] as ScanCollection;
            int size = scans.Count;

            bool maskedOnly = (bool) options[0].Value;

            int i = 0;
            foreach (BaseScan scan in scans) {
                if (IsCanceled) {
                    break;
                }

                IType[] data = new IType[1];
                if ((maskedOnly && scan.HasMask) || !maskedOnly) {
                    if (scan.AvailableScanTypes().Contains(scanTypeComboBox.Value)) {
                        data[0] =
                            new TScan(scan, scanTypeComboBox.Value.ToString(), maskedOnly: maskedOnly).Preload();

                        Yield(data, scan);
                    }
                }

                i++;

                SetProgress((i * 100) / size);
            }

            return null;
        }