Exemple #1
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

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

            kernel = createKernel();

            int white = 255;
            int black = 0;

            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 == black)
                    {
                        convolve(i, j);
                    }
                    else
                    {
                        int alpha = (new Color(originalImage.getRGB(i, j))).Alpha;
                        int rgb   = ImageUtilities.colorToRGB(alpha, white, white, white);
                        filteredImage.setRGB(i, j, rgb);
                    }
                }
            }
            return(filteredImage);
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;
            int alpha;
            int red;
            int green;
            int blue;
            int gray;
            int width  = originalImage.Width;
            int height = originalImage.Height;

            filteredImage = new BufferedImage(width, height, originalImage.Type);
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    alpha = (new Color(originalImage.getRGB(i, j))).Alpha;
                    red   = (new Color(originalImage.getRGB(i, j))).Red;
                    green = (new Color(originalImage.getRGB(i, j))).Green;
                    blue  = (new Color(originalImage.getRGB(i, j))).Blue;

                    gray = (int)(0.21 * red + 0.71 * green + 0.07 * blue);

                    gray = ImageUtilities.colorToRGB(alpha, gray, gray, gray);

                    filteredImage.setRGB(i, j, gray);
                }
            }
            return(filteredImage);
        }
Exemple #3
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            double variance = sigma * sigma;

            originalImage = image;

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

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

            double a = 0.0;
            double b = 0.0;



            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    while (a == 0.0)
                    {
                        a = new Random(1).NextDouble();
                    }
                    b = new Random(2).NextDouble();

                    double x     = Math.Sqrt(-2 * Math.Log(a)) * Math.Cos(2 * Math.PI * b);
                    double noise = mean + Math.Sqrt(variance) * x;

                    //
                    //

                    int gray  = (new Color(originalImage.getRGB(i, j))).Red;
                    int alpha = (new Color(originalImage.getRGB(i, j))).Alpha;

                    double color = gray + noise;
                    if (color > 255)
                    {
                        color = 255;
                    }
                    if (color < 0)
                    {
                        color = 0;
                    }

                    int newColor = (int)Math.Round(color);

                    int rgb = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor);

                    filteredImage.setRGB(i, j, rgb);
                }         //j
            }             //i


            return(filteredImage);
        }
Exemple #4
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;



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

            filteredImage = new BufferedImage(width, height, originalImage.Type);
//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: imageMatrix = new int[width][height];
            imageMatrix = RectangularArrays.ReturnRectangularIntArray(width, height);

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

            mean = calculateMean();
            @var = calculateVariance();

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    double normalizedPixel = 0;
                    double squareError     = 0;

                    if (imageMatrix[i][j] > mean)
                    {
                        squareError     = (imageMatrix[i][j] - mean) * (imageMatrix[i][j] - mean);
                        normalizedPixel = (GOAL_MEAN_Renamed + Math.Sqrt(((GOAL_VARIANCE_Renamed * squareError / @var))));
                    }
                    else
                    {
                        squareError     = (imageMatrix[i][j] - mean) * (imageMatrix[i][j] - mean);
                        normalizedPixel = (GOAL_MEAN_Renamed - Math.Sqrt(((GOAL_VARIANCE_Renamed * squareError / @var))));
                    }

                    int alpha = (new Color(originalImage.getRGB(i, j))).Alpha;

                    int rgb = (int)-normalizedPixel;

                    int color = ImageUtilities.colorToRGB(alpha, rgb, rgb, rgb);

                    filteredImage.setRGB(i, j, color);
                }
            }


            return(filteredImage);
        }
Exemple #5
0
 public void imageBegin(int w, int h, int bucketSize)
 {
     lock (lockObj)
     {
         if (image != null && w == image.getWidth() && h == image.getHeight())
         {
             // dull image if it has same resolution (75%)
             for (int y = 0; y < h; y++)
             {
                 for (int x = 0; x < w; x++)
                 {
                     int rgb = image.getRGB(x, y);
                     image.setRGB(x, y, ((uint)(rgb & 0x00FEFEFE) >> 1) + ((uint)(rgb & 0x00FCFCFC) >> 2));//>>>
                 }
             }
         }
         else
         {
             // allocate new framebuffer
             image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
             // center
             this.w = w;
             this.h = h;
             xo     = yo = 0;
         }
         repaintCounter = NanoTime.Now;
         repaint();
     }
 }
 /// <summary>
 /// This method scans image pixels until it finds the first black pixel (TODO: use foreground color which is black by default).
 /// When it finds black pixel, it sets cropTopY and returns true. if it reaches end of image and does not find black pixels,
 /// it sets endOfImage flag and returns false. </summary>
 /// <returns> - returns true when black pixel is found and cropTopY value is changed, and false if cropTopY value is not changed </returns>
 private bool findCropTopY()
 {
     for (int y = cropBottomY; y < imageWithChars.Height; y++)  // why cropYDown? - for multiple lines of text using cropBottomY from previous line above; for first line its zero
     {
         for (int x = cropLeftX; x < imageWithChars.Width; x++) // scan starting from the previous left crop position - or it shoud be right???
         {
             if (imageWithChars.getRGB(x, y) == -16777216)      // if its black rixel (also consider condition close to black or not white or different from background)
             {
                 this.cropTopY = y;                             // save the current y coordiante
                 return(true);                                  // and return true
             }
         }
     }
     endOfImage = true;        //sets this flag if no black pixels are found
     return(false);            // and return false
 }
        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);
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;
            int width  = originalImage.Width;
            int height = originalImage.Height;

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

            int radius = kernel.Length / 2;

            if (normalize)
            {
                normalizeKernel();
            }

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    double result = convolve(x, y, radius);
                    int    gray   = (int)Math.Round(result);
                    int    alpha  = (new Color(originalImage.getRGB(x, y))).Alpha;
                    int    rgb    = ImageUtilities.colorToRGB(alpha, gray, gray, gray);
                    filteredImage.setRGB(x, y, rgb);
                }
            }

            return(filteredImage);
        }
 /// <summary>
 /// This method reads the input image from the input from start pixel height
 /// (y1) until it reads the first next row where all pixel are white by
 /// height and return that value
 /// </summary>
 /// <param name="Img"> - input image that will be read </param>
 /// <param name="y1"> - input start height pixel of image </param>
 /// <returns> - returns the value of height when conditions are true </returns>
 private static int trimLockdown(BufferedImage img, int y1)
 {
     for (int j = y1 + 1; j < img.Height; j++)
     {
         int counterWhite = 0;
         for (int i = 0; i < img.Width; i++)
         {
             if (img.getRGB(i, j) == -1)
             {
                 counterWhite++;
             }
         }
         if (counterWhite == img.Width)
         {
             //this is a chek for dots over the letters i and j
             //so they wont be missread as dots
             if (j > (img.Height / 2))
             {
                 return(j);
             }
         }
         if (j == img.Height - 1)
         {
             return(j + 1);
         }
     }
     return(0);
 }
Exemple #10
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

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

            int[] arrayOfPixels;
            int   median;
            int   alpha;
            int   newColor;

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    arrayOfPixels = getArrayOfPixels(i, j);
                    median        = findMedian(arrayOfPixels);
                    alpha         = (new Color(originalImage.getRGB(i, j))).Alpha;

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

            return(filteredImage);
        }
Exemple #11
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

            int oldWidth  = image.Width;
            int oldHeight = image.Height;

            int width  = image.Width - 2 * radius;
            int height = image.Height - 2 * radius;



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

            createKernel();


            for (int i = radius; i < oldWidth - radius; i++)
            {
                for (int j = radius; j < oldHeight - radius; j++)
                {
                    int alpha    = (new Color(originalImage.getRGB(i, j))).Alpha;
                    int newColor = getNewColor(i, j);
                    int rgb      = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor);

                    int x = i - radius;
                    int y = j - radius;
                    filteredImage.setRGB(x, y, rgb);
                }
            }


            return(filteredImage);
        }
Exemple #12
0
        /// <summary>
        /// Calculate the width histogram for single row. <br/>
        /// Make the rectangle with: <br/>
        /// width = width of the image<br/>
        /// height = predicted height of letter<br/>
        /// It scans this rectangle by width, start from left to right and finds all black
        /// pixels in each column. Method returns array which length is width of the image.
        /// Every element in array corresponds to number of black pixels in the column of
        /// the rectangle. </summary>
        /// <param name="image"> input image with multiple lines and letters </param>
        /// <param name="row"> pixel position of the row. It should be center of the single row.
        /// This number can be calculated by method findRowPixels </param>
        /// <param name="letterHeight"> predicted letter size (above and below row) </param>
        /// <returns>  </returns>
        public static int[] widthRowHistogram(BufferedImage image, int row, int letterHeight)
        {
            int width  = image.Width;
            int height = image.Height;
            int color;
            int black = 0;

            int[] histogram = new int[width];
            for (int i = 0; i < width; i++)
            {
                for (int j = row - (letterHeight / 2); j <= row + (letterHeight / 2); j++)
                {
                    if (j < 0 || j >= height)
                    {
                        continue;
                    }
                    color = (new Color(image.getRGB(i, j))).Red;
                    if (color == black)
                    {
                        histogram[i]++;
                    }
                }
            }
            return(histogram);
        }
Exemple #13
0
        /// <summary>
        /// Метод, предназначенный для вырезания части изображения и увеличения его в 4 раза
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Bitmap FragmentCut(Bitmap bitmap, int x1 = 160, int y1 = 160, int x2 = 240, int y2 = 240, int n = 4)
        {
            BufferedImage img    = new BufferedImage(bitmap);
            int           width  = x2 - x1;
            int           height = y2 - y1;
            BufferedImage newImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

            for (int i = x1, ik = 0; i < x2; i++, ik++)
            {
                for (int j = y1, jk = 0; j < y2; j++, jk++)
                {
                    Color color = new Color(img.getRGB(i, j));
                    newImg.setRGB(ik, jk, color.getRGB());
                }
            }
            BufferedImage resizeNewImg = new BufferedImage(width * n, height * n, BufferedImage.TYPE_INT_RGB);

            for (int i = 0, i1 = 0; i < width; i++, i1 += 4)
            {
                for (int j = 0, j1 = 0; j < height; j++, j1 += 4)
                {
                    Color color = new Color(newImg.getRGB(i, j));
                    for (int k = 0; k < n; k++)
                    {
                        resizeNewImg.setRGB(i1 + k, j1 + k, color.getRGB());
                    }
                }
            }
            return(resizeNewImg.getBitmap());
        }
Exemple #14
0
        /// <summary>
        /// Метод, предназначенный для квантования изображения
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Bitmap Quantization(Bitmap bitmap, int n)
        {
            BufferedImage img = new BufferedImage(bitmap);
            Color         color;

            for (int i = 0; i < img.getWidth(); i++)
            {
                for (int j = 0; j < img.getHeight(); j++)
                {
                    color = new Color(img.getRGB(i, j));
                    if (color.getRed() % n != 0 && color.getRed() != 0)
                    {
                        img.setRGB(i, j, new Color(newColor(color.getRed(), n), color.getGreen(), color.getBlue()).getRGB());
                    }
                    if (color.getBlue() % n != 0 && color.getBlue() != 0)
                    {
                        img.setRGB(i, j, new Color(color.getRed(), color.getGreen(), newColor(color.getBlue(), n)).getRGB());
                    }
                    if (color.getGreen() % n != 0 && color.getGreen() != 0)
                    {
                        img.setRGB(i, j, new Color(color.getRed(), newColor(color.getGreen(), n), color.getBlue()).getRGB());
                    }
                }
            }
            return(img.getBitmap());
        }
Exemple #15
0
        public virtual int letterThreshold(BufferedImage original, bool[][] matrix)
        {
            double sum   = 0;
            int    count = 0;

            for (int i = 0; i < original.Width; i++)
            {
                for (int j = 0; j < original.Height; j++)
                {
                    if (matrix[i][j] == true)
                    {
                        int gray = (new Color(original.getRGB(i, j))).Red;
                        sum += gray;
                        count++;
                    }
                }
            }

            if (count == 0)
            {
                return(0);
            }

            return((int)Math.Round((sum * 3) / (count * 2)));             // 3 i 2 su plinkove konstnte
        }
Exemple #16
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

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

            int[] histogram = imageHistogram(originalImage);

            int totalNumberOfpixels = height * width;

            int treshold = treshold(histogram, totalNumberOfpixels);

            int black = 0;
            int white = 255;

            int alpha;
            int gray;
            int newColor;

            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 > treshold)
                    {
                        newColor = white;
                    }
                    else
                    {
                        newColor = black;
                    }

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

            return(filteredImage);
        }
Exemple #17
0
        /// <summary>
        /// Crop the part of an image with a white rectangle
        /// </summary>
        /// <returns> A cropped image File </returns>
        public virtual File crop(BufferedImage image)
        {
            // this will be coordinates of the upper left white pixel
            int upperLeftCornerx = int.MaxValue;
            int upperLeftCornery = int.MaxValue;
            //this will be coordinates of the lower right white pixel
            int lowerRightCornerx = int.MinValue;
            int lowerRightCornery = int.MinValue;

            //find the minimum and maximum white pixel coordinates
            for (int i = 0; i < image.Width; i++)
            {
                for (int j = 0; j < image.Height; j++)
                {
                    if (image.getRGB(i, j) == WHITE.RGB && (i < upperLeftCornerx && j < upperLeftCornery) || (i <= upperLeftCornerx && j < upperLeftCornery) || (i < upperLeftCornerx && j <= upperLeftCornery))
                    {
                        upperLeftCornerx = i;
                        upperLeftCornery = j;
                    }
                    if (image.getRGB(i, j) == WHITE.RGB && ((i > lowerRightCornerx && j >= lowerRightCornery) || (i >= lowerRightCornerx && j > lowerRightCornery) || (i > lowerRightCornerx && j >= lowerRightCornery)))
                    {
                        lowerRightCornerx = i;
                        lowerRightCornery = j;
                    }
                }
            }
            //crop the image to the white rectangle size
            BufferedImage croppedImage = image.getSubimage(upperLeftCornerx, upperLeftCornery, lowerRightCornerx - upperLeftCornerx, lowerRightCornery - upperLeftCornery);
            //make a file from that cropped image
            File cropFile = new File("croppedimage.png");

            try
            {
                ImageIO.write(croppedImage, "png", cropFile);
            }
            catch (IOException ex)
            {
//JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method:
                Logger.getLogger(typeof(OcrDemo).FullName).log(Level.SEVERE, null, ex);
            }
            return(cropFile);
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

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

            int[] histogram = imageHistogram(originalImage);

            int[] histogramCumulative = new int[histogram.Length];

            histogramCumulative[0] = histogram[0];
            for (int i = 1; i < histogramCumulative.Length; i++)
            {
                histogramCumulative[i] = histogramCumulative[i - 1] + histogram[i];
            }

            int G = 256;
            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;
                    alpha = (new Color(originalImage.getRGB(i, j))).Alpha;

                    newColor = (G - 1) * histogramCumulative[gray] / (width * height);     //zaokruziti izbeci celobrojno deljenje


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

            return(filteredImage);
        }
Exemple #19
0
        public virtual double [][] createM(int i, int j)
        {
//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: double[][] M = new double [N_Renamed][N_Renamed];
            double[][] M  = RectangularArrays.ReturnRectangularDoubleArray(N_Renamed, N_Renamed);
            int        xx = 0;
            int        yy = 0;

            for (int x = i * N_Renamed; x < i * N_Renamed + N_Renamed; x++)
            {
                for (int y = j * N_Renamed; y < j * N_Renamed + N_Renamed; y++)
                {
                    M[xx][yy] = (new Color(originalImage.getRGB(x, y))).Red - 128;
                    yy++;
                }
                xx++;
                yy = 0;
            }
            return(M);
        }
Exemple #20
0
        //mouse released//
        private void jPanel2MouseReleased(MouseEvent evt)
        {
            currentX = evt.X;
            currentY = evt.Y;


            const double  SCALE = 0.1;
            BufferedImage bi    = new BufferedImage(32, 32, BufferedImage.TYPE_BYTE_GRAY);

            Graphics2D grph = (Graphics2D)bi.Graphics;

            grph.scale(SCALE, SCALE);

            grph.drawImage(canvas, 0, 0, null);
            grph.dispose();

            newPix = new double[32 * 32];
            pixels = bi.getRGB(0, 0, 32, 32, pixels, 0, 32);

            for (int i = 0; i < pixels.Length; i++)
            {
                newPix[i]  = 255 - (pixels[i] & 0xff);
                newPix[i] /= 255;
            }


            long start = DateTimeHelperClass.CurrentUnixTimeMillis();

            network.Input = newPix;
            network.calculate();
            Console.WriteLine("Execution time: " + (DateTimeHelperClass.CurrentUnixTimeMillis() - start) + " milliseconds");

            try
            {
                ImageIO.write(bi, "png", new File("number.png"));
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            double[] networkOutput = network.Output;
            int      maxNeuronIdx  = Utils.maxIdx(networkOutput);

            ClassificationResult max = new ClassificationResult(maxNeuronIdx, networkOutput[maxNeuronIdx]);


            Console.WriteLine("New calculation:");
            Console.WriteLine("Class: " + max.ClassIdx);
            Console.WriteLine("Probability: " + max.NeuronOutput);

            label.Text = Convert.ToString(max.ClassIdx);
        }
Exemple #21
0
        public virtual int getNewColor(int x, int y)
        {
            if (!checkConditios(x, y))
            {
                return((new Color(originalImage.getRGB(x, y))).Red);
            }

            int size = 2 * radius + 1;

//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: double[][] matrix = new double [size][size];
            double[][] matrix = RectangularArrays.ReturnRectangularDoubleArray(size, size);

            int newI = 0;
            int newJ = 0;

            for (int i = x - radius; i <= x + radius; i++)
            {
                for (int j = y - radius; j <= y + radius; j++)
                {
                    //System.out.println("size:" +size+", radius:"+radius+", x:"+x+",y:"+y+", i:"+i+",j:"+j+ ", newI:"+newI+"newJ:"+newJ);
                    int oldColor = (new Color(originalImage.getRGB(i, j))).Red;
                    matrix[newI][newJ] = oldColor * kernel[newI][newJ];
                    newJ++;
                }
                newI++;
                newJ = 0;
            }

            double sum = 0;

            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[0].Length; j++)
                {
                    sum = sum + matrix[i][j];
                }
            }

            return((int)Math.Round(sum));
        }
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;

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

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

            OtsuBinarizeFilter obf       = new OtsuBinarizeFilter();
            BufferedImage      tempImage = obf.processImage(originalImage);

            int gray;
            int alpha;
            int discreteColor;
            int newColor;
            int white = 255;

            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;

                    discreteColor = (new Color(tempImage.getRGB(i, j))).Red;
                    if (discreteColor == white)
                    {
                        newColor = gray;
                    }
                    else
                    {
                        newColor = white;
                    }
                    newColor = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor);
                    filteredImage.setRGB(i, j, newColor);
                }
            }

            return(filteredImage);
        }
        public virtual BufferedImage getUnsharpMask(BufferedImage originalImage, BufferedImage bluredImage)
        {
            int width  = originalImage.Width;
            int height = originalImage.Height;

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

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    int originalColor = (new Color(originalImage.getRGB(i, j))).Red;
                    int blurColor     = (new Color(bluredImage.getRGB(i, j))).Red;
                    int alpha         = (new Color(originalImage.getRGB(i, j))).Alpha;
                    int newColor      = originalColor - blurColor;
                    int rgb           = ImageUtilities.colorToRGB(alpha, newColor, newColor, newColor);
                    unsharpMask.setRGB(i, j, rgb);
                }
            }
            return(unsharpMask);
        }
 /// <summary>
 /// This method reads the image pixels until it reads the first black pixel
 /// by height and then returns that value
 /// </summary>
 /// <param name="Img"> - input image that will be read </param>
 /// <returns> - returns the value of height when conditions are true </returns>
 private static int trimLockup(BufferedImage img)
 {
     for (int j = 0; j < img.Height; j++)
     {
         for (int i = 0; i < img.Width; i++)
         {
             if (img.getRGB(i, j) == -16777216)
             {
                 return(j);
             }
         }
     }
     return(0);
 }
 /// <summary>
 /// This method cleans input image by replacing all non black pixels with
 /// white pixels TODO: some should be used here
 /// </summary>
 /// <param name="image"> - input image that will be cleaned </param>
 /// <returns> - cleaned input image as BufferedImage </returns>
 public static BufferedImage blackAndWhiteCleaning(BufferedImage image)
 {
     for (int j = 0; j < image.Height; j++)
     {
         for (int i = 0; i < image.Width; i++)
         {
             if (image.getRGB(i, j) != -16777216)
             {
                 image.setRGB(i, j, -1);
             }
         }
     }
     return(image);
 }
Exemple #26
0
        private void resampleFrameFile(Sector sector, BufferedImage srcImage, BufferedImage destImage, int frameNumber,
                                       PixelTransformer pt)
        {
            int frameULX = pixelColumn(0, frameNumber, this.frameStructure.getPixelRowsPerFrame(),
                                       this.frameStructure.getPolarFrames());
            int frameULY = pixelRow(0, frameNumber, this.frameStructure.getPixelRowsPerFrame(),
                                    this.frameStructure.getPolarFrames());

            int width  = destImage.getWidth();
            int height = destImage.getHeight();

            double deltaLon = (sector.getMaxLongitude().degrees - sector.getMinLongitude().degrees) / width;
            double deltaLat = (sector.getMaxLatitude().degrees - sector.getMinLatitude().degrees) / height;

            // unbundle these values that are used in the nested loop below -- its compute intensive enough...
            double minLon        = sector.getMinLongitude().degrees;
            double minLat        = sector.getMinLatitude().degrees;
            double polarConstant = this.frameStructure.getPolarPixelConstant();
            int    srcWidth      = srcImage.getWidth();
            int    srcHeight     = srcImage.getHeight();

            for (int y = 0; y < height; y++)
            {
                double lat = minLat + y * deltaLat;
                for (int x = 0; x < width; x++)
                {
                    double lon = minLon + x * deltaLon;

                    int pixelX = pt.latLon2X(lat, lon, polarConstant);
                    int pixelY = pt.latLon2Y(lat, lon, polarConstant);
                    int i      = pixelX - frameULX;
                    int j      = frameULY - pixelY;

                    if (i < 0 || i >= srcWidth || j < 0 || j >= srcHeight)
                    {
                        continue;
                    }

                    int color = srcImage.getRGB(i, j);

                    // Remove black trim known to be present in these maps....
                    if ((color & 0x00FFFFFF) == 0)
                    {
                        color = 0;
                    }
                    destImage.setRGB(x, height - 1 - y, color);
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// Изменение размера изображения
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="n"></param>
        /// <returns></returns>
        public static Bitmap DecreaseImageResolution(Bitmap bitmap, int n)
        {
            BufferedImage img    = new BufferedImage(bitmap);
            BufferedImage newImg = new BufferedImage(bitmap.Width / n, bitmap.Height / n, BufferedImage.TYPE_INT_RGB);

            for (int i = 0, ik = 0; ik < img.getWidth(null); i++, ik += n)
            {
                for (int j = 0, jk = 0; jk < img.getHeight(null); j++, jk += n)
                {
                    Color color = new Color(img.getRGB(ik, jk));
                    newImg.setRGB(i, j, color.getRGB());
                }
            }
            return(newImg.getBitmap());
        }
Exemple #28
0
        private void createColorImageThreadTask(BufferedImage imageChunk, int mask, ArrayList <BufferedImage> resultList, int index)
        {
            BufferedImage colorImage = new BufferedImage(imageChunk.getWidth(),
                                                         imageChunk.getHeight(), imageChunk.getType());

            for (int x = 0; x < imageChunk.getWidth(); x++)
            {
                for (int y = 0; y < imageChunk.getHeight(); y++)
                {
                    int pixel = imageChunk.getRGB(x, y) & mask;
                    colorImage.setRGB(x, y, pixel);
                }
            }
            resultList.Add(colorImage);
        }
Exemple #29
0
 private void convolve(int i, int j)
 {
     for (int x = i - 2; x <= i + 2; x++)
     {
         for (int y = j - 2; y <= j + 2; y++)
         {
             if (x >= 0 && y >= 0 && x < width && y < height)
             {
                 int black = 0;
                 int alpha = (new Color(originalImage.getRGB(x, y))).Alpha;
                 int rgb   = ImageUtilities.colorToRGB(alpha, black, black, black);
                 filteredImage.setRGB(x, y, rgb);
             }
         }
     }
 }
Exemple #30
0
        public virtual BufferedImage processImage(BufferedImage image)
        {
            originalImage = image;
            Attributes    = image;
            int width  = originalImage.Width;
            int height = originalImage.Height;

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

            int[][] filter1 = new int[][] { new int[] { -1, 0, 1 }, new int[] { -2, 0, 2 }, new int[] { -1, 0, 1 } };
            int[][] filter2 = new int[][] { new int[] { 1, 2, 1 }, new int[] { 0, 0, 0 }, new int[] { -1, -2, -1 } };

            for (int y = 1; y < height - 1; y++)
            {
                for (int x = 1; x < width - 1; x++)
                {
                    // get 3-by-3 array of colors in neighborhood
//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: int[][] gray = new int[3][3];
                    int[][] gray = RectangularArrays.ReturnRectangularIntArray(3, 3);
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            gray[i][j] = (int)lum(new Color(originalImage.getRGB(x - 1 + i, y - 1 + j)));
                        }
                    }

                    // apply filter
                    int gray1 = 0, gray2 = 0;
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            gray1 += gray[i][j] * filter1[i][j];
                            gray2 += gray[i][j] * filter2[i][j];
                        }
                    }
                    // int magnitude = 255 - truncate(Math.abs(gray1) + Math.abs(gray2));
                    int   magnitude = 255 - truncate((int)Math.Sqrt(gray1 * gray1 + gray2 * gray2));
                    Color grayscale = new Color(magnitude, magnitude, magnitude);
                    filteredImage.setRGB(x, y, grayscale.RGB);
                }
            }
            return(filteredImage);
        }