getColorArray() public method

public getColorArray ( ) : int[]
return int[]
コード例 #1
0
        public List<Bitmap> Apply(Bitmap srcimg)
        {
            int mw = srcimg.Width;
            int mh = srcimg.Height;
            int[] pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
            ColorHistogram colorHist = new ColorHistogram(pixels);
            int[] color_array = colorHist.getColorArray();
            List<bool[,]> img_list = new List<bool[,]>();
            for (int i = 0; i < color_array.Length; i++)
            {
                img_list.Add(new bool[mh, mw]);
                fg_count_list.Add(0);
                fg_idx_color_hash.Add(i, color_array[i]);
                fg_color_idx_hash.Add(color_array[i], i);
            }

            for(int i=0;i<mw;i++)
                for (int j = 0; j < mh; j++)
                {
                    int idx = (int)fg_color_idx_hash[pixels[j * mw + i]];
                    (img_list[idx])[j,i] = true;
                    fg_count_list[idx]++;
                }

            List<Bitmap> bitmap_list = new List<Bitmap>();
            for (int i = 0; i < img_list.Count; i++)
                bitmap_list.Add(ImageUtils.ArrayBool2DToBitmap(img_list[i]));
            return bitmap_list;
        }
コード例 #2
0
        public static int countUniqueColorNumber(String fullFilePath)
        {
            return 40;

            Bitmap srcimg = new Bitmap(fullFilePath);
            int[] pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
            ColorHistogram colorHist = new ColorHistogram(pixels);
            int[] color_array = colorHist.getColorArray();

            return color_array.Length;
        }
コード例 #3
0
        public Dictionary<int, Color> ApplyFast(String inputName, String saveName)
        {
            Dictionary<int, Color> tbl = new Dictionary<int, Color>();

            Bitmap srcimg = new Bitmap(inputName);

            List<int> fg_count_list = new List<int>();
            Hashtable fg_color_idx_hash = new Hashtable();

            int mw = srcimg.Width;
            int mh = srcimg.Height;
            int[] pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
            ColorHistogram colorHist = new ColorHistogram(pixels);
            int[] color_array = colorHist.getColorArray();
            List<int[,]> img_list = new List<int[,]>();
            List<Bitmap> bitmap_list = new List<Bitmap>();
            for (int i = 0; i < color_array.Length; i++)
            {
                bitmap_list.Add(new Bitmap(mw, mh));
                img_list.Add(new int[mh, mw]);
                fg_count_list.Add(0);
                fg_color_idx_hash.Add(color_array[i], i);
                tbl.Add(i, getColor(color_array[i]));
            }

            for (int i = 0; i < mw; i++)
            {
                for (int j = 0; j < mh; j++)
                {
                    int idx = (int)fg_color_idx_hash[pixels[j * mw + i]];
                    bitmap_list[idx].SetPixel(i, j, getColor(pixels[j * mw + i]));
                    fg_count_list[idx]++;
                }
            }

            for (int k = 0; k < img_list.Count; k++)
            {
                bitmap_list[k].Save(string.Format(saveName, k));
            }

            return tbl;
        }
コード例 #4
0
 public void ApplySaveInd(Bitmap srcimg, string dir, string fn)
 {
     int mw = srcimg.Width;
     int mh = srcimg.Height;
     int[] pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
     ColorHistogram colorHist = new ColorHistogram(pixels);
     int[] color_array = colorHist.getColorArray();
     //List<bool[,]> img_list = new List<bool[,]>();
     //for (int i = 0; i < color_array.Length; i++)
     //{
     //    img_list.Add(new bool[mh, mw]);
     //    fg_count_list.Add(0);
     //    fg_idx_color_hash.Add(i, color_array[i]);
     //    fg_color_idx_hash.Add(color_array[i], i);
     //}
     for (int c = 0; c < color_array.Length; c++)
     {
         int rgb = color_array[c];
         bool[,] bool_img = new bool[mh, mw];
         for (int i = 0; i < mw; i++)
             for (int j = 0; j < mh; j++)
             {
                 if(pixels[j * mw + i]==rgb)
                     bool_img[j, i] = true;
             }
         ImageUtils.ArrayBool2DToBitmap(bool_img).Save(dir + fn+c+".png");
     }
 }
コード例 #5
0
        public double[] getLayerColorHSV(string layerPath, int n)
        {
            Bitmap srcimg = new Bitmap(layerPath);
            int[] pixels = ImageUtils.BitmapToArray1DIntRGB(srcimg);
            ColorHistogram colorHist = new ColorHistogram(pixels);
            int[] color_array = colorHist.getColorArray();

            String st = color_array[1].ToString();

            Color c = getColor(int.Parse(st));
            //Hsv hsv = new Hsv(c.GetHue(),c.GetSaturation(),c.GetBrightness());
            //double[] f = { hsv.Hue, hsv.Satuation, hsv.Value };
            //double[] f = { c.GetHue(), c.GetSaturation() ,c.GetBrightness() };

            int max = Math.Max(c.R, Math.Max(c.G, c.B));
            int min = Math.Min(c.R, Math.Min(c.G, c.B));

            double hue = c.GetHue();
            double saturation = (max == 0) ? 0 : 1d - (1d * min / max);
            double value = max / 255d;

            double[] f = { hue, saturation * 100, value * 100 };
            return f;
        }