Exemple #1
0
        public Channel(int chNum)
        {
            this.chNum = chNum;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: wndShapeHist = new bool[2][ATRAC3P_SUBBANDS];
            wndShapeHist = RectangularArrays.ReturnRectangularBoolArray(2, ATRAC3P_SUBBANDS);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: gainDataHist = new AtracGainInfo[2][ATRAC3P_SUBBANDS];
            gainDataHist = RectangularArrays.ReturnRectangularAtracGainInfoArray(2, ATRAC3P_SUBBANDS);
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: tonesInfoHist = new WavesData[2][ATRAC3P_SUBBANDS];
            tonesInfoHist = RectangularArrays.ReturnRectangularWavesDataArray(2, ATRAC3P_SUBBANDS);
            for (int i = 0; i < 2; i++)
            {
                for (int sb = 0; sb < ATRAC3P_SUBBANDS; sb++)
                {
                    gainDataHist [i][sb] = new AtracGainInfo();
                    tonesInfoHist[i][sb] = new WavesData();
                }
            }

            wndShape      = wndShapeHist[0];
            wndShapePrev  = wndShapeHist[1];
            gainData      = gainDataHist[0];
            gainDataPrev  = gainDataHist[1];
            tonesInfo     = tonesInfoHist[0];
            tonesInfoPrev = tonesInfoHist[1];
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;
            width         = originalImage.Width;
            height        = originalImage.Height;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: visited = new bool[width][height];
            visited = RectangularArrays.ReturnRectangularBoolArray(width, height);

            int name = 1;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int color = (new Color(originalImage.getRGB(i, j))).Red;
                    if (color == 255)
                    {
                        visited[i][j] = true;
                    }
                    else
                    {
                        if (name > 3000)
                        {
                            return(originalImage);
                        }
                        BFS(i, j, name + "");
                        name++;
                    }
                }
            }

            return(originalImage);
        }
Exemple #3
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;
            width         = originalImage.Width;
            height        = originalImage.Height;

            prepare();

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: visited = new bool[height][width];
            visited = RectangularArrays.ReturnRectangularBoolArray(height, width);

            int color;
            int white = 255;

            for (int line = 0; line < linePositions.Length; line++)
            {
                for (int k = -1; k <= 1; k++)
                {
                    int i = linePositions[line] + k;
                    if (i == -1 || i == height)
                    {
                        continue;
                    }
                    //        for (int i = 0; i < height; i++) {

                    for (int j = 0; j < width; j++)
                    {
                        color = (new Color(originalImage.getRGB(j, i))).Red;
                        if (color == white)
                        {
                            visited[i][j] = true;
                        }
                        else
                        {
                            BFStraverseAndSave(i, j);
                        }
                    }
                }
            }
            return(originalImage);
        }
Exemple #4
0
        /// <summary>
        /// recognize the text on the image (document)
        /// </summary>
        public virtual void recognize()
        {
            int imageHeight = image.Height;
            int imageWidth  = image.Width;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: visited = new bool[imageHeight][imageWidth];
            visited = RectangularArrays.ReturnRectangularBoolArray(imageHeight, imageWidth);
            text    = "";

            for (int i = 0; i < textInformation.numberOfRows(); i++)
            {
                string rowText = recognizeRow(i);
                if (rowText.Length > 0)
                {
                    text += rowText + "\n";
                }
            }

            visited = null;             //prevent lottering
        }
Exemple #5
0
        /// <summary>
        /// radi otsu da dobije spojena crna slova i ra </summary>
        /// <param name="image"> </param>
        /// <returns>  </returns>
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: bool[][] matrix = new bool[width][height]; // black n white oolean matrix; true = blck, false = white
            bool[][] matrix = RectangularArrays.ReturnRectangularBoolArray(width, height);             // black n white oolean matrix; true = blck, false = white

            filteredImage = new BufferedImage(width, height, originalImage.Type);

            int[] histogram = imageHistogram(originalImage);

            int totalNumberOfpixels = height * width;

            int threshold = threshold(histogram, totalNumberOfpixels);

            int black = 0;
            int white = 255;

            int gray;
            int alpha;
            int newColor;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    gray = (new Color(originalImage.getRGB(i, j))).Red;

                    if (gray > threshold)
                    {
                        matrix[i][j] = false;
                    }
                    else
                    {
                        matrix[i][j] = true;
                    }
                }
            }

            int blackTreshold = letterThreshold(originalImage, matrix);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    gray  = (new Color(originalImage.getRGB(i, j))).Red;
                    alpha = (new Color(originalImage.getRGB(i, j))).Alpha;

                    if (gray > blackTreshold)
                    {
                        newColor = white;
                    }
                    else
                    {
                        newColor = black;
                    }

                    newColor = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor);
                    filteredImage.setRGB(i, j, newColor);
                }
            }

            return(filteredImage);
        }
Exemple #6
0
        private void fillImage(int startH, int startW, int endH, int endW)
        {
            // fill the image with white color
            int alpha    = (new Color(originalImage.getRGB(width / 2, height / 2))).Red;
            int whiteRGB = ImageUtilities.colorToRGB(alpha, 255, 255, 255);

            for (int i = 0; i < newHeight; i++)
            {
                for (int j = 0; j < newWidth; j++)
                {
                    filteredImage.setRGB(j, i, whiteRGB);
                }
            }

            // fill black pixels

            int oldCenterH = (startH + endH) / 2;
            int oldCenterW = (startW + endW) / 2;

            int newCenterH = newHeight / 2;
            int newCenterW = newWidth / 2;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: bool[][] visited = new bool[newHeight][newWidth];
            bool[][] visited = RectangularArrays.ReturnRectangularBoolArray(newHeight, newWidth);

            LinkedList <string> queue = new LinkedList <string>();
            string pos = newCenterH + " " + newCenterW + " " + oldCenterH + " " + oldCenterW;

            queue.AddLast(pos);
            visited[newCenterH][newCenterW] = true;
            try
            {
                while (queue.Count > 0)
                {
                    string tmp = queue.RemoveFirst();
                    int    nh  = Convert.ToInt32(tmp.Split(" ", true)[0]);
                    int    nw  = Convert.ToInt32(tmp.Split(" ", true)[1]);
                    int    oh  = Convert.ToInt32(tmp.Split(" ", true)[2]);
                    int    ow  = Convert.ToInt32(tmp.Split(" ", true)[3]);

                    filteredImage.setRGB(nw, nh, originalImage.getRGB(ow, oh));

                    for (int i = -1; i <= 1; i++)
                    {
                        for (int j = -1; j <= 1; j++)
                        {
                            int n_tmpH = nh + i;
                            int n_tmpW = nw + j;
                            int o_tmpH = oh + i;
                            int o_tmpW = ow + j;
                            if (!visited[n_tmpH][n_tmpW])
                            {
                                visited[n_tmpH][n_tmpW] = true;
                                queue.AddLast(n_tmpH + " " + n_tmpW + " " + o_tmpH + " " + o_tmpW);
                            }
                        }
                    }
                }
            }
            catch (System.IndexOutOfRangeException)
            {
            }
        }
Exemple #7
0
        // Returns total number of
        // palindrome substring of
        // length greater then equal to 2
        public static int CountPS(char[] str, int n)
        {
            // create empty 2-D matrix that counts
            // all palindrome substring. dp[i][j]
            // stores counts of palindromic
            // substrings in st[i..j]
            int[][] rectangularIntArray = RectangularArrays.ReturnRectangularIntArray(n, n);

            // P[i][j] = true if substring str[i..j]
            // is palindrome, else false
            bool[][] rectangularBoolArray = RectangularArrays.ReturnRectangularBoolArray(n, n);

            // palindrome of single length
            for (int i = 0; i < n; i++)
            {
                rectangularBoolArray[i][i] = true;
            }

            // palindrome of length 2
            for (int i = 0; i < n - 1; i++)
            {
                if (str[i] == str[i + 1])
                {
                    rectangularBoolArray[i][i + 1] = true;
                    rectangularIntArray[i][i + 1]  = 1;
                }
            }

            // Palindromes of length more then 2.
            // This loop is similar to Matrix Chain Multiplication.
            // We start with a gap of length 2 and fill DP table in a way that gap between starting and
            // ending indexes increases one by one by outer loop.
            for (int gap = 2; gap < n; gap++)
            {
                // Pick starting point for current gap
                for (int i = 0; i < n - gap; i++)
                {
                    // Set ending point
                    int j = gap + i;

                    // If current string is palindrome
                    if (str[i] == str[j] && rectangularBoolArray[i + 1][j - 1])
                    {
                        rectangularBoolArray[i][j] = true;
                    }

                    // Add current palindrome substring
                    // ( + 1) and rest palindrome substring
                    // (dp[i][j-1] + dp[i+1][j]) remove common
                    // palindrome substrings (- dp[i+1][j-1])
                    if (rectangularBoolArray[i][j] == true)
                    {
                        rectangularIntArray[i][j] = rectangularIntArray[i][j - 1] + rectangularIntArray[i + 1][j]
                                                    + 1 - rectangularIntArray[i + 1][j - 1];
                    }
                    else
                    {
                        rectangularIntArray[i][j] = rectangularIntArray[i][j - 1] + rectangularIntArray[i + 1][j]
                                                    - rectangularIntArray[i + 1][j - 1];
                    }
                }
            }

            // return total palindromic substrings
            return(rectangularIntArray[0][n - 1]);
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

            filteredImage = new BufferedImage(width, height, originalImage.Type);

            int centerI = width / 2;
            int centerJ = height / 2;

            int lengthI = width / 4;
            int lengthJ = height / 6;

            int startI = centerI - lengthI / 2;
            int goalI  = centerI + lengthI / 2;

            int startJ = centerJ - lengthJ / 2;
            int goalJ  = centerJ + lengthJ / 2;

            bool[][] visited;
//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: visited = new bool[width][height];
            visited = RectangularArrays.ReturnRectangularBoolArray(width, height);
            int color;

            for (int i = startI; i < goalI; i++)
            {
                for (int j = startJ; j < goalJ; j++)
                {
                    color = (new Color(originalImage.getRGB(i, j))).Red;
                    if (color == 0)
                    {
                        if (!visited[i][j])
                        {
                            BFS(i, j, visited);
                        }
                    }
                }
            }

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int alpha = (new Color(originalImage.getRGB(i, j))).Alpha;
                    if (!visited[i][j])
                    {
                        int white = 255;
                        color = ImageUtilities.colorToRGB(alpha, white, white, white);
                        filteredImage.setRGB(i, j, color);
                    }
                    else
                    {
                        int black = 0;
                        color = ImageUtilities.colorToRGB(alpha, black, black, black);
                        filteredImage.setRGB(i, j, color);
                    }
                }
            }

            return(filteredImage);
        }
Exemple #9
0
        private void createImagesWithLetters()
        {
            int cropWidth  = letterInformation.CropWidth;
            int cropHeight = letterInformation.CropHeight;
            int tmpWidth   = 3 * cropWidth;
            int tmpHeight  = 3 * cropHeight;
            int trashSize  = letterInformation.TrashSize;

            OCRExtractLetter extractionLetter = new OCRExtractLetter(tmpWidth, tmpHeight, trashSize);

            int letterSize  = letterInformation.LetterSize;
            int imageHeight = image.Height;
            int imageWidth  = image.Width;

//JAVA TO C# CONVERTER NOTE: The following call to the 'RectangularArrays' helper class reproduces the rectangular array initialization that is automatic in Java:
//ORIGINAL LINE: bool[][] visited = new bool[imageHeight][imageWidth];
            bool[][] visited = RectangularArrays.ReturnRectangularBoolArray(imageHeight, imageWidth);
            Color    white   = Color.WHITE;
            Color    color;
            int      seqNum = 0;

            for (int line = 0; line < textInformation.numberOfRows(); line++)
            {
                //==============================================================================
                for (int j = 0; j < imageWidth; j++)
                {
                    for (int k = -(letterSize / 4); k < (letterSize / 4); k++)
                    {
                        int rowPixel = textInformation.getRowAt(line);
                        int i        = rowPixel + k;
                        if (i < 0 || i >= imageHeight)
                        {
                            continue;
                        }
                        //==============================================================================
                        //                   fornja verzija radi, ova ima gresku
                        //            for (int k = -(letterSize / 4); k < (letterSize / 4); k++) {
                        //                int rowPixel = textInformation.getRowAt(line);
                        //                int i = rowPixel + k;
                        //                if (i < 0 || i >= imageHeight) {
                        //                    continue;
                        //                }
                        //                for (int j = 0; j < imageWidth; j++) {
                        //==============================================================================
                        color = new Color(image.getRGB(j, i));
                        if (color.Equals(white))
                        {
                            visited[i][j] = true;
                        }
                        else if (visited[i][j] == false)
                        {
                            BufferedImage letter = extractionLetter.extraxtLetter(image, visited, i, j);                             // OCRUtilities.extraxtCharacterImage(image, visited, i, j, tmpWidth, tmpHeight, letterInformation.getTrashSize());
                            if (letter != null)
                            {
                                OCRCropLetter crop      = new OCRCropLetter(letter, cropWidth, cropHeight);
                                BufferedImage croped    = crop.processImage();
                                string        character = trainingText[seqNum] + "";
                                string        name      = character + "_" + seqNum;
                                OCRUtilities.saveToFile(croped, folderPath, name, imageExtension);
                                seqNum++;
                            }
                        }
                    }
                }
            }
        }