Beispiel #1
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());
        }
Beispiel #2
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();
     }
 }
Beispiel #3
0
        /// <summary>
        /// Метод, предназначенный для замены яркости определенного кол-ва пикселей
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="percent"></param>
        /// <returns></returns>
        public static Bitmap RandomReplacePixel(Bitmap bitmap, int percent)
        {
            BufferedImage img = new BufferedImage(bitmap);
            int           n = img.getHeight() * img.getWidth() * percent / 100;
            int           maxWidth = img.getWidth(), maxHeight = img.getHeight();
            Random        random = new Random();

            for (int i = 0; i < n / 2; i++)
            {
                img.setRGB((int)((double)random.Next(0, 100) / 100 * maxWidth), (int)((double)random.Next(0, 100) / 100 * maxHeight), new Color(0, 0, 0).getRGB());
                img.setRGB((int)((double)random.Next(0, 100) / 100 * maxWidth), (int)((double)random.Next(0, 100) / 100 * maxHeight), new Color(255, 255, 255).getRGB());
            }
            return(img.getBitmap());
        }
        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);
        }
Beispiel #5
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);
        }
Beispiel #6
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());
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #10
0
 /// <summary>
 /// This method cleans input image by replacing all pixels with RGB values
 /// from -3092272 (light gray) to -1 (white) with white pixels and from
 /// -3092272 (light gray) to -16777216 (black) with black pixels
 /// </summary>
 /// <param name="image"> - input image that will be cleaned </param>
 /// <returns> - cleaned input image as BufferedImage </returns>
 public static BufferedImage blackAndLightGrayCleaning(BufferedImage image)
 {
     for (int j = 0; j < image.Height; j++)
     {
         for (int i = 0; i < image.Width; i++)
         {
             if (image.getRGB(i, j) > -4473925)
             {
                 image.setRGB(i, j, -1);
             }
             else
             {
                 image.setRGB(i, j, -16777216);
             }
         }
     }
     return(image);
 }
Beispiel #11
0
 /// <summary>
 /// This method cleans input image by replacing all pixels with RGB values
 /// from RGBcolor input (the input color) to -1 (white) with white pixels and
 /// from RGBcolor input (the input color) to -16777216 (black) with black
 /// pixels
 /// </summary>
 /// <param name="image"> - input image that will be cleaned </param>
 /// <param name="RGBcolor"> - input RGB value of wanted color as reference for
 /// celaning </param>
 /// <returns> - cleaned input image as BufferedImage </returns>
 public static BufferedImage colorCleaning(BufferedImage image, int RGBcolor)
 {
     for (int j = 0; j < image.Height; j++)
     {
         for (int i = 0; i < image.Width; i++)
         {
             if (image.getRGB(i, j) == RGBcolor)
             {
                 image.setRGB(i, j, -16777216);
             }
             else
             {
                 image.setRGB(i, j, -1);
             }
         }
     }
     return(image);
 }
Beispiel #12
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);
        }
Beispiel #13
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);
        }
Beispiel #14
0
        void HAL.Pixel(float x, float y, float r, float g, float b)
        {
            var x1 = Clamp(x, canvas.getWidth());
            var y1 = Clamp(y, canvas.getHeight());
            int r1 = Clamp(r, 256);
            int g1 = Clamp(g, 256);
            int b1 = Clamp(b, 256);

            canvas.setRGB(x1, y1, (0xFF << 24) | (r1 << 16) | (g1 << 8) | b1);

            int Clamp(float a, int b) => System.Math.Min(System.Math.Max((int)(a * b), 0), b - 1);
        }
Beispiel #15
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);
 }
Beispiel #16
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);
                }
            }
        }
Beispiel #17
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);
        }
Beispiel #18
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());
        }
Beispiel #19
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);
             }
         }
     }
 }
Beispiel #20
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);
        }
Beispiel #21
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);
        }
Beispiel #22
0
        /// <summary>
        /// Выполняет линейное контрастирование изображения
        /// </summary>
        /// <param name="bitmap">Передаваемое изображение</param>
        /// <returns></returns>
        public static Bitmap SetsContrans(Bitmap bitmap)
        {
            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));
                    int r = color.getRed();
                    int g = color.getGreen();
                    int b = color.getBlue();

                    if (r > 94)
                    {
                        r = 94;
                    }
                    else if (r < 28)
                    {
                        r = 28;
                    }
                    if (g > 94)
                    {
                        g = 94;
                    }
                    else if (g < 28)
                    {
                        g = 28;
                    }
                    if (b > 94)
                    {
                        b = 94;
                    }
                    else if (b < 28)
                    {
                        b = 28;
                    }

                    img.setRGB(i, j, new Color(r, g, b).getRGB());
                }
            }
            return(img.getBitmap());
        }
Beispiel #23
0
        public virtual void fillFilteredImage(int i, int j, int[][] Nmatrix)
        {
            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++)
                {
                    int alpha = (new Color(originalImage.getRGB(x, y))).Alpha;
                    int color = Nmatrix[xx][yy];
                    int rgb   = ImageUtilities.colorToRGB(alpha, color, color, color);
                    yy++;
                    filteredImage.setRGB(x, y, rgb);
                }
                xx++;
                yy = 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[] 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);
        }
Beispiel #25
0
 public void imageEnd()
 {
     lock (lockObj)
     {
         // copy buffer
         image.setRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
         repaint();
         // update stats
         t.end();
         seconds += t.seconds();
         frames++;
         if (seconds > 1)
         {
             // display average fps every second
             frame.setTitle(string.Format("Sunflow v{0} - {1} fps", SunflowAPI.VERSION, frames / seconds));
             frames  = 0;
             seconds = 0;
         }
     }
 }
        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);
        }
Beispiel #28
0
        ///
        /// <summary>
        /// Inverts the image colors from negative to positive
        /// </summary>
        /// <returns> the image with inverted colors </returns>
        public static BufferedImage invertImage(string imageName)
        {
            // read the image file
            BufferedImage inputFile = null;

            try
            {
                inputFile = ImageIO.read(new File(imageName));
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }

            // go through image pixels and reverse their color
            for (int x = 0; x < inputFile.Width; x++)
            {
                for (int y = 0; y < inputFile.Height; y++)
                {
                    int   rgba = inputFile.getRGB(x, y);
                    Color col  = new Color(rgba, true);
                    col = new Color(255 - col.Red, 255 - col.Green, 255 - col.Blue);
                    inputFile.setRGB(x, y, col.RGB);
                }
            }

            //write the image to a file blackandwhite.png
            try
            {
                File outputFile = new File("blackandwhite.png");
                ImageIO.write(inputFile, "png", outputFile);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            return(inputFile);
        }
        private static void MPIWorker()
        {
            ArrayList <ImageIcon> imageChunksIcon = Communicator.world.Receive <ArrayList <ImageIcon> >(0, 0);
            int mask = Communicator.world.Receive <int>(0, 0);

            ArrayList <BufferedImage> imageChunks = new ArrayList <BufferedImage>();

            foreach (ImageIcon image in imageChunksIcon)
            {
                imageChunks.Add(convertToBufferedImage(image.getImage()));
            }

            List <BufferedImage> results = new List <BufferedImage>(20);

            int k = 0;

            foreach (BufferedImage imageChunk in imageChunks)
            {
                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);
                    }
                }
                results.Add(colorImage);
            }

            ArrayList <ImageIcon> resultsIcons = new ArrayList <ImageIcon>(20);

            for (int i = 0; i < results.Count; i++)
            {
                resultsIcons.Add(new ImageIcon(results[i]));
            }
            Communicator.world.Send(resultsIcons, 0, 0);
        }
        private void displayWeight(List <double?> currentKernel)
        {
            JFrame frame = new JFrame("Weight Visualiser: ");

            frame.setSize(400, 400);

            JLabel    label = new JLabel();
            Dimension d     = new Dimension(kernel.Width * RATIO, kernel.Height * RATIO);

            label.Size          = d;
            label.PreferredSize = d;

            frame.ContentPane.add(label, BorderLayout.CENTER);
            frame.pack();
            frame.Visible = true;

            BufferedImage image = new BufferedImage(kernel.Width, kernel.Height, BufferedImage.TYPE_BYTE_GRAY);

            int[] rgb = convertWeightToRGB(currentKernel);
            image.setRGB(0, 0, kernel.Width, kernel.Height, rgb, 0, kernel.Width);
            label.Icon = new ImageIcon(image.getScaledInstance(kernel.Width * RATIO, kernel.Height * RATIO, Image.SCALE_SMOOTH));
        }