Beispiel #1
0
        static public HSI[,] BGR2HSI(BGR[,] Source)
        {
            int Height = Source.GetLength(0), Width = Source.GetLength(1);

            HSI[,] Result = new HSI[Height, Width];
            int X, Y;

            for (Y = 0; Y < Height; ++Y)
            {
                for (X = 0; X < Width; ++X)
                {
                    Result[Y, X] = Source[Y, X].ToHSI();
                }
            }
            return(Result);
        }
Beispiel #2
0
        static public BGR HSI2BGR(HSI Source)
        {
            double       R, G, B;
            const double P  = Math.PI / 180.0;
            double       I  = Source.I;
            double       S  = Source.S;
            double       H  = Source.H;
            double       SI = Source.I * Source.S;

            if (H < 120)
            {
                double cos1 = Math.Cos(H * P);
                double cos2 = Math.Cos((60 - H) * P);
                R = I + SI * cos1 / cos2;
                B = I - SI;
                G = 3 * I - R - B;
            }
            else if (H < 240)
            {
                double cos1 = Math.Cos((H - 120) * P);
                double cos2 = Math.Cos((180 - H) * P);
                R = I - SI;
                G = I + SI * cos1 / cos2;
                B = 3 * I - R - G;
            }
            else if (H < 360)
            {
                double cos1 = Math.Cos((H - 240) * P);
                double cos2 = Math.Cos((300 - H) * P);
                G = I - SI;
                B = I + SI * cos1 / cos2;
                R = 3 * I - G - B;
            }
            else
            {
                throw new ArgumentException("輸入HSI不正確", "HSI");
            }
            R *= 255;
            G *= 255;
            B *= 255;
            return(new BGR(DoubleToByte(R), DoubleToByte(G), DoubleToByte(B)));
        }
Beispiel #3
0
        static public HSIComplexImg BGR2HSI(BGRComplexImg Source)
        {
            HSIComplexImg Result = new HSIComplexImg(Source.Width, Source.Height);
            BGR           TmpBGR = new BGR();
            HSI           TmpHSI = null;
            int           X, Y;

            for (Y = 0; Y < Source.Height; ++Y)
            {
                for (X = 0; X < Source.Width; ++X)
                {
                    TmpBGR.R          = DoubleToByte(Source.R[Y, X].Re);
                    TmpBGR.B          = DoubleToByte(Source.B[Y, X].Re);
                    TmpBGR.G          = DoubleToByte(Source.G[Y, X].Re);
                    TmpHSI            = TmpBGR.ToHSI();
                    Result.H[Y, X].Re = TmpHSI.H;
                    Result.S[Y, X].Re = TmpHSI.S;
                    Result.I[Y, X].Re = TmpHSI.I;
                }
            }
            return(Result);
        }
Beispiel #4
0
        static public BGRComplexImg HSI2BGR(HSIComplexImg Source)
        {
            BGRComplexImg Result = new BGRComplexImg(Source.Width, Source.Height);
            HSI           TmpHSI = new HSI();
            BGR           TmpBGR = null;
            int           X, Y;

            for (Y = 0; Y < Source.Height; ++Y)
            {
                for (X = 0; X < Source.Width; ++X)
                {
                    TmpHSI.H          = Source.H[Y, X].Re;
                    TmpHSI.S          = Source.S[Y, X].Re;
                    TmpHSI.I          = Source.I[Y, X].Re;
                    TmpBGR            = TmpHSI.ToBGR();
                    Result.R[Y, X].Re = TmpBGR.R;
                    Result.G[Y, X].Re = TmpBGR.G;
                    Result.B[Y, X].Re = TmpBGR.B;
                }
            }
            return(Result);
        }
Beispiel #5
0
 static public BGR FromHSI(HSI Source)
 {
     return(ImgF.HSI2BGR(Source));
 }