Ejemplo n.º 1
0
        public static void Luminancia(int[,,] src, int H, int W)
        {
            int r, g, b, gs;

            for (int y = 0; y < H; y++)
            {
                for (int x = 0; x < W; x++)
                {
                    HsiToRgb.convert(src[x, y, 0], src[x, y, 1], src[x, y, 2], out r, out g, out b);
                    gs = (int)(r * 0.2990 + g * 0.5870 + b * 0.1140);
                    RgbToHsi.convert(gs, gs, gs, out src[x, y, 0], out src[x, y, 1], out src[x, y, 2]);
                }
            }
        }
Ejemplo n.º 2
0
        public unsafe static void miniaturaHSI(Bitmap src, Bitmap h, Bitmap s, Bitmap i)
        {
            int        W          = src.Width;
            int        H          = src.Height;
            BitmapData bmpDataSrc = src.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            BitmapData bmpDataH = h.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpDataS = s.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            BitmapData bmpDataI = i.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int    padding = bmpDataSrc.Stride - (W * 3);
            int    r, g, b;
            byte * psrc = (byte *)bmpDataSrc.Scan0.ToPointer();
            byte * ph   = (byte *)bmpDataH.Scan0.ToPointer();
            byte * ps   = (byte *)bmpDataS.Scan0.ToPointer();
            byte * pi   = (byte *)bmpDataI.Scan0.ToPointer();
            double v;

            for (int y = 0; y < H; y++)
            {
                for (int x = 0; x < W; x++)
                {
                    b       = *(psrc++);
                    g       = *(psrc++);
                    r       = *(psrc++);
                    v       = RgbToHsi.matiz(r, g, b);
                    *(ph++) = (byte)v;
                    *(ph++) = (byte)v;
                    *(ph++) = (byte)v;

                    v       = RgbToHsi.saturacao(r, g, b);
                    *(ps++) = (byte)v;
                    *(ps++) = (byte)v;
                    *(ps++) = (byte)v;

                    v       = RgbToHsi.intensidade(r, g, b);
                    *(pi++) = (byte)v;
                    *(pi++) = (byte)v;
                    *(pi++) = (byte)v;
                }
                psrc += padding;
                ph   += padding;
                ps   += padding;
                pi   += padding;
            }
            src.UnlockBits(bmpDataSrc);
            h.UnlockBits(bmpDataH);
            s.UnlockBits(bmpDataS);
            i.UnlockBits(bmpDataI);
        }
Ejemplo n.º 3
0
        public unsafe static void bmpToHsi(Bitmap src, int [,,] dest)
        {
            int        W       = src.Width;
            int        H       = src.Height;
            BitmapData bmpData = src.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            byte *ptr     = (byte *)bmpData.Scan0.ToPointer();
            int   padding = bmpData.Stride - (W * 3);

            int b, g, r, h, s, i;

            for (int y = 0; y < H; y++)
            {
                for (int x = 0; x < W; x++)
                {
                    b = *(ptr++);
                    g = *(ptr++);
                    r = *(ptr++);
                    RgbToHsi.convert(r, g, b, out dest[x, y, 0], out dest[x, y, 1], out dest[x, y, 2]);
                }
                ptr += padding;
            }
            src.UnlockBits(bmpData);
        }
Ejemplo n.º 4
0
        public unsafe static string getInfo(Bitmap img, int X, int Y)
        {
            int        W          = img.Width;
            int        H          = img.Height;
            BitmapData bmpDataImg = img.LockBits(new Rectangle(0, 0, W, H), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            int        padding    = bmpDataImg.Stride - (W * 3);
            byte *     pos        = (byte *)bmpDataImg.Scan0.ToPointer();

            pos = getPos(pos, X, Y, W, padding);
            int b = *(pos++);
            int g = *(pos++);
            int r = *(pos++);

            img.UnlockBits(bmpDataImg);

            //RGB
            string info = "RGB[";

            info += r.ToString("D" + 3) + " , ";
            info += g.ToString("D" + 3) + " , ";
            info += b.ToString("D" + 3) + "] ";

            //CMY
            info += "CMY[";
            info += (255 - r).ToString("D" + 3) + " , ";
            info += (255 - g).ToString("D" + 3) + " , ";
            info += (255 - b).ToString("D" + 3) + "] ";

            //HSI
            info += "HSI[";
            info += (int)RgbToHsi.matiz(r, g, b) + " , ";
            info += (int)RgbToHsi.saturacao(r, g, b) + " , ";
            info += (int)RgbToHsi.intensidade(r, g, b) + "] ";

            return(info);
        }