protected override unsafe void OnUpdatePlaneImage(Bitmap bmp)
        {
            if (bmp.PixelFormat != PixelFormat.Format32bppArgb)
            {
                return;
            }
            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                         ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            ColorBgra *scan0 = (ColorBgra *)bd.Scan0;
            //draw plane image
            LAB curr = new LAB(_color.L, -128.0, 127.0);
            double
                delta_a = 255.0 / (double)bd.Width,
                delta_b = -255.0 / (double)bd.Height;

            for (int y = 0; y < bd.Height; y++, curr.a = -128.0, curr.b += delta_b)
            {
                for (int x = 0; x < bd.Width; x++, scan0++, curr.a += delta_a)
                {
                    scan0[0] = ColorBgra.FromArgb(curr.ToXYZ().ToRGB());
                }
            }
            //end
            bmp.UnlockBits(bd);
        }
Esempio n. 2
0
 /// <summary>Constructs a new BasicDatum with the given features and label.</summary>
 /// <param name="features">The features of the CRFDatum</param>
 /// <param name="label">The label of the CRFDatum</param>
 public CRFDatum(IList <FEAT> features, LAB label, IList <double[]> featureVals)
 {
     // featureVals holds the (optional) feature value for non-boolean features
     // such as the ones used in continuous vector space embeddings
     this.features    = features;
     this.label       = label;
     this.featureVals = featureVals;
 }
Esempio n. 3
0
            // constructor - takes a Color
            public LAB(Color col)
            {
                LAB temp = FromColor(col);

                l = temp.l;
                a = temp.a;
                b = temp.b;
            }
Esempio n. 4
0
        private void UpdatetbValue(TextBox skipupdate)
        {
            #region hsv textboxes

            HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
            if (skipupdate != tbHSV_H)
            {
                tbHSV_H.Text = (chsv.H * 360.0).ToString("0");
            }
            if (skipupdate != tbHSV_S)
            {
                tbHSV_S.Text = (chsv.S * 100.0).ToString("0");
            }
            if (skipupdate != tbHSV_V)
            {
                tbHSV_V.Text = (chsv.V * 100.0).ToString("0");
            }

            #endregion

            #region secondary textboxes

            if (_mode == Mode.HSV_RGB)
            {
                RGB crgb = InternalColor.ToRGB();
                if (skipupdate != tbSecond_1)
                {
                    tbSecond_1.Text = (crgb.R * 255.0).ToString("0");
                }
                if (skipupdate != tbSecond_2)
                {
                    tbSecond_2.Text = (crgb.G * 255.0).ToString("0");
                }
                if (skipupdate != tbSecond_3)
                {
                    tbSecond_3.Text = (crgb.B * 255.0).ToString("0");
                }
            }
            else             //(_mode==Mode.HSV_LAB)
            {
                LAB clab = LAB.FromXYZ(InternalColor);
                if (skipupdate != tbSecond_1)
                {
                    tbSecond_1.Text = clab.L.ToString("0");
                }
                if (skipupdate != tbSecond_2)
                {
                    tbSecond_2.Text = clab.a.ToString("0");
                }
                if (skipupdate != tbSecond_3)
                {
                    tbSecond_3.Text = clab.b.ToString("0");
                }
            }

            #endregion
        }
Esempio n. 5
0
    public static LAB XyzToLab(XYZ xyz)
    {
        LAB lab = new LAB();

        double tmp = fXYZ(xyz.Y);                                 // Чтобы три раза не считать, а только один

        lab.L = 116 * tmp - 16;
        lab.A = 500 * (fXYZ(xyz.X / 0.9505) - tmp);
        lab.B = 200 * (tmp - fXYZ(xyz.Z / 1.089));

        return(lab);
    }
        public Color GetColor(double position, ColorScaleInterpolationMode mode = ColorScaleInterpolationMode.RGB)
        {
            if (_stops.Length == 1)
            {
                return(_stops[0].Color);
            }
            if (position <= 0)
            {
                return(_stops[0].Color);
            }
            else if (position >= 1)
            {
                return(_stops[_stops.Length - 1].Color);
            }
            int lowerIndex = 0;

            for (int i = 0; i < _stops.Length; i++)
            {
                if (_stops[i].Position <= position)
                {
                    lowerIndex = i;
                }
            }
            int upperIndex = lowerIndex + 1;

            if (upperIndex >= _stops.Length)
            {
                upperIndex = _stops.Length - 1;
            }
            double scalePosition = (position - _stops[lowerIndex].Position) * (1.0 / (_stops[upperIndex].Position - _stops[lowerIndex].Position));

            switch (mode)
            {
            case ColorScaleInterpolationMode.LAB:
                LAB leftLAB   = ColorUtils.RGBToLAB(_stops[lowerIndex].Color, false);
                LAB rightLAB  = ColorUtils.RGBToLAB(_stops[upperIndex].Color, false);
                LAB targetLAB = ColorUtils.InterpolateLAB(leftLAB, rightLAB, scalePosition);
                return(ColorUtils.LABToRGB(targetLAB, false).Denormalize());

            case ColorScaleInterpolationMode.XYZ:
                XYZ leftXYZ   = ColorUtils.RGBToXYZ(_stops[lowerIndex].Color, false);
                XYZ rightXYZ  = ColorUtils.RGBToXYZ(_stops[upperIndex].Color, false);
                XYZ targetXYZ = ColorUtils.InterpolateXYZ(leftXYZ, rightXYZ, scalePosition);
                return(ColorUtils.XYZToRGB(targetXYZ, false).Denormalize());

            default:
                return(ColorUtils.InterpolateRGB(_stops[lowerIndex].Color, _stops[upperIndex].Color, scalePosition));
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Get pixel
        /// </summary>
        private void picInput_MouseMove(object sender, MouseEventArgs e)
        {
            Graphics g   = picInput.CreateGraphics();
            Bitmap   img = (Bitmap)picInput.Image;
            Point    pix = new Point();

            if (e.Button == MouseButtons.Left && !rdbSimNone.Checked)
            {
                g.DrawEllipse(Pens.Red, e.X, e.Y, 1, 1);
                pix = TransformPosition(img, e.Location);
                rgb = new RGB(img.GetPixel(pix.X, pix.Y));
                lab = LAB.FromRGB(rgb);
                hsv = HSV.FromRGB(rgb);
                rgbs.Add(rgb);
                labs.Add(lab);
                hsvs.Add(hsv);

                if (picOutput.Image != null)
                {
                    picOutput.Image.Dispose();
                }

                if (rdbSimRGB.Checked)
                {
                    picOutput.Image = TakakuraImplement.Similiar_RGB((Bitmap)picInput.Image, _rect, rgbs, trackBarSimilarity.Value);
                }
                else if (rdbSimRGBAver.Checked)
                {
                    picOutput.Image = TakakuraImplement.Similiar_RGBAver((Bitmap)picInput.Image, _rect, rgbs, trackBarSimilarity.Value);
                }
                else if (rdbSimLAB.Checked)
                {
                    picOutput.Image = TakakuraImplement.Similiar_LAB((Bitmap)picInput.Image, _rect, labs, trackBarSimilarity.Value);
                }
                else if (rdbSimLABAver.Checked)
                {
                    picOutput.Image = TakakuraImplement.Similiar_LABAver((Bitmap)picInput.Image, _rect, labs, trackBarSimilarity.Value);
                }
                else
                {
                    picOutput.Image = TakakuraImplement.Similiar_HSV((Bitmap)picInput.Image, _rect, hsvs, trackBarSimilarity.Value);
                }
            }
            g.Dispose();
        }
Esempio n. 8
0
    public static XYZ LabToXyz(LAB lab)
    {
        XYZ xyz = new XYZ();

        xyz.Y = (lab.L + 16.0) / 116.0;
        xyz.X = lab.A / 500.0 + xyz.Y;
        xyz.Z = xyz.Y - lab.B / 200.0;

        xyz.X = oXYZ(xyz.X);
        xyz.Y = oXYZ(xyz.Y);
        xyz.Z = oXYZ(xyz.Z);

        xyz.X = 95.047 * xyz.X;
        xyz.Y = 100 * xyz.Y;
        xyz.Z = 108.883 * xyz.Z;

        return(xyz);
    }
        protected override unsafe void OnUpdateFaderImage(Bitmap bmp)
        {
            if (bmp.PixelFormat != PixelFormat.Format32bppArgb)
            {
                return;
            }
            BitmapData bd = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
                                         ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            ColorBgra *scan0 = (ColorBgra *)bd.Scan0;
            //draw fader image
            LAB    curr    = new LAB(0.0, _color.a, _color.b);
            double delta_L = 100.0 / (double)bd.Width;

            for (int x = 0; x < bd.Width; x++, scan0++, curr.L += delta_L)
            {
                scan0[0] = ColorBgra.FromArgb(curr.ToXYZ().ToRGB());
            }
            //end
            bmp.UnlockBits(bd);
        }
Esempio n. 10
0
            // static function for converting from Color to LABColor
            public static LAB FromColor(Color c)
            {
                float D65x    = 0.9505f;
                float D65y    = 1.0f;
                float D65z    = 1.0890f;
                float rLinear = c.r;
                float gLinear = c.g;
                float bLinear = c.b;
                //float r = (rLinear > 0.04045f) ? Mathf.Pow((rLinear + 0.055f) / (1f + 0.055f), 2.2f) : (rLinear / 12.92f);
                //float g = (gLinear > 0.04045f) ? Mathf.Pow((gLinear + 0.055f) / (1f + 0.055f), 2.2f) : (gLinear / 12.92f);
                //float b = (bLinear > 0.04045f) ? Mathf.Pow((bLinear + 0.055f) / (1f + 0.055f), 2.2f) : (bLinear / 12.92f);

                // 2.2f => 2.4f ???何で?? python版のskimageのconvertがそうなってた
                float r = (rLinear > 0.04045f) ? Mathf.Pow((rLinear + 0.055f) / (1f + 0.055f), 2.4f) : (rLinear / 12.92f);
                float g = (gLinear > 0.04045f) ? Mathf.Pow((gLinear + 0.055f) / (1f + 0.055f), 2.4f) : (gLinear / 12.92f);
                float b = (bLinear > 0.04045f) ? Mathf.Pow((bLinear + 0.055f) / (1f + 0.055f), 2.4f) : (bLinear / 12.92f);
                float x = (r * 0.4124f + g * 0.3576f + b * 0.1805f);
                float y = (r * 0.2126f + g * 0.7152f + b * 0.0722f);
                float z = (r * 0.0193f + g * 0.1192f + b * 0.9505f);

                x = (x > 0.9505f) ? 0.9505f : ((x < 0f) ? 0f : x);
                y = (y > 1.0f) ? 1.0f : ((y < 0f) ? 0f : y);
                z = (z > 1.089f) ? 1.089f : ((z < 0f) ? 0f : z);
                LAB   lab = new LAB(0f, 0f, 0f);
                float fx  = x / D65x;
                float fy  = y / D65y;
                float fz  = z / D65z;

                fx    = ((fx > 0.008856f) ? Mathf.Pow(fx, (1.0f / 3.0f)) : (7.787f * fx + 16.0f / 116.0f));
                fy    = ((fy > 0.008856f) ? Mathf.Pow(fy, (1.0f / 3.0f)) : (7.787f * fy + 16.0f / 116.0f));
                fz    = ((fz > 0.008856f) ? Mathf.Pow(fz, (1.0f / 3.0f)) : (7.787f * fz + 16.0f / 116.0f));
                lab.l = 116.0f * fy - 16f;
                lab.a = 500.0f * (fx - fy);
                lab.b = 200.0f * (fy - fz);
                return(lab);
            }
Esempio n. 11
0
            // static function for converting from LABColor to Color
            public static Color ToColor(LAB lab)
            {
                float D65x  = 0.9505f;
                float D65y  = 1.0f;
                float D65z  = 1.0890f;
                float delta = 6.0f / 29.0f;
                float fy    = (lab.l + 16f) / 116.0f;
                float fx    = fy + (lab.a / 500.0f);
                float fz    = fy - (lab.b / 200.0f);
                float x     = (fx > delta) ? D65x * (fx * fx * fx) : (fx - 16.0f / 116.0f) * 3f * (delta * delta) * D65x;
                float y     = (fy > delta) ? D65y * (fy * fy * fy) : (fy - 16.0f / 116.0f) * 3f * (delta * delta) * D65y;
                float z     = (fz > delta) ? D65z * (fz * fz * fz) : (fz - 16.0f / 116.0f) * 3f * (delta * delta) * D65z;
                float r     = x * 3.2410f - y * 1.5374f - z * 0.4986f;
                float g     = -x * 0.9692f + y * 1.8760f - z * 0.0416f;
                float b     = x * 0.0556f - y * 0.2040f + z * 1.0570f;

                r = (r <= 0.0031308f) ? 12.92f * r : (1f + 0.055f) * Mathf.Pow(r, (1.0f / 2.4f)) - 0.055f;
                g = (g <= 0.0031308f) ? 12.92f * g : (1f + 0.055f) * Mathf.Pow(g, (1.0f / 2.4f)) - 0.055f;
                b = (b <= 0.0031308f) ? 12.92f * b : (1f + 0.055f) * Mathf.Pow(b, (1.0f / 2.4f)) - 0.055f;
                r = (r < 0) ? 0 : r;
                g = (g < 0) ? 0 : g;
                b = (b < 0) ? 0 : b;
                return(new Color(r, g, b));
            }
Esempio n. 12
0
 // static function for linear interpolation between two LABColors
 public static LAB Lerp(LAB a, LAB b, float t)
 {
     return(new LAB(Mathf.Lerp(a.l, b.l, t), Mathf.Lerp(a.a, b.a, t), Mathf.Lerp(a.b, b.b, t)));
 }
Esempio n. 13
0
        private void tbValue_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
        {
            if (!(sender is TextBox))
            {
                return;
            }
            if (e.KeyCode == Keys.Return)
            {
                UpdatetbValue(null);
                e.Handled = true;
                return;
            }
            double value;

            if (!double.TryParse(((TextBox)sender).Text,
                                 System.Globalization.NumberStyles.Integer,
                                 null, out value))
            {
                return;
            }

            #region hsv  textboxes

            if (sender == tbHSV_H)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.H        = value / 360.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_S)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.S        = value / 100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            else if (sender == tbHSV_V)
            {
                HSV chsv = HSV.FromRGB(InternalColor.ToRGB());
                chsv.V        = value / 100.0;
                InternalColor = XYZ.FromRGB(chsv.ToRGB());
            }
            #endregion
            #region secondary textboxes

            else if (_mode == Mode.HSV_RGB)
            {
                RGB crgb = InternalColor.ToRGB();
                if (sender == tbSecond_1)
                {
                    crgb.R = value / 255.0;
                }
                else if (sender == tbSecond_2)
                {
                    crgb.G = value / 255.0;
                }
                else                 //sender==tbSecond_3
                {
                    crgb.B = value / 255.0;
                }
                InternalColor = XYZ.FromRGB(crgb);
            }
            else if (_mode == Mode.HSV_LAB)
            {
                LAB clab = LAB.FromXYZ(InternalColor);
                if (sender == tbSecond_1)
                {
                    clab.L = value;
                }
                else if (sender == tbSecond_2)
                {
                    clab.a = value;
                }
                else                 //sender==tbSecond_3
                {
                    clab.b = value;
                }
                InternalColor = clab.ToXYZ();
            }

            #endregion

            //update ui
            _module.XYZ       = InternalColor;
            lblColorOut.Color = InternalColor.ToRGB();
            UpdatetbValue((TextBox)sender);
        }
Esempio n. 14
0
 // static function for returning the color difference in a normalized colorspace (Delta-E)
 public static float Distance(LAB a, LAB b)
 {
     return(Mathf.Sqrt(Mathf.Pow((a.l - b.l), 2f) + Mathf.Pow((a.a - b.a), 2f) + Mathf.Pow((a.b - b.b), 2f)));
 }
Esempio n. 15
0
 // static function for interpolation between two Unity Colors through normalized colorspace
 public static Color Lerp(Color a, Color b, float t)
 {
     return((LAB.Lerp(LAB.FromColor(a), LAB.FromColor(b), t)).ToColor());
 }
Esempio n. 16
0
 public static Color Lab2Color(LAB lab)
 {
     return(lab.ToColor());
 }
Esempio n. 17
0
 // function for converting an instance of LABColor to Color
 public Color ToColor()
 {
     return(LAB.ToColor(this));
 }
Esempio n. 18
0
 public static Color LabToRgb(LAB lab)
 {
     return(XyzToRgb(LabToXyz(lab)));
 }
Esempio n. 19
0
        public ActionResult DoctorCommissionSetting(DoctorCommissionSetting obj, DoctorCommissiondgv objdgv, OPDDGV objOPDDGV, IPDDGV objIPD, LAB objLABDgv, FormCollection fc)
        {
            //   obj.OPDdgv[] = obj1;

            try
            {
                //string OPDDGV = Request.Form["ServiceNamedgv"].ToString();
                string DoctorID = fc["DoctorID"];
                if (fc["DoctorID"] != "")
                {
                    //objOPDDGV.ModeDgvOPD = fc["ModeDgvOPD"];
                    string tick = fc["tick"];
                    string m    = fc["Mode"];
                    (obj.doc) = (DoctorID);


                    if (m == "Edit")
                    {
                        obj.Mode = m;
                    }
                    else
                    {
                        obj.Mode = "Add";
                    }
                    Buisness_Logic.Master.BL_DoctorCommissionSetting BLobj = new Buisness_Logic.Master.BL_DoctorCommissionSetting();
                    if (tick == null)
                    {
                        obj.CheckRow = "0";
                    }
                    else
                    {
                        obj.CheckRow = (tick);
                    }
                    var id = obj.DoctorCommissionSettingID;
                    if (BLobj.Save(obj, objdgv, objOPDDGV, objIPD, objLABDgv))
                    {
                        if (id == 0)
                        {
                            TempData["Msg"] = "Record Saved Successfully";
                            return(RedirectToAction("DoctorCommissionSetting", "DoctorCommissionSetting"));
                        }
                        else
                        {
                            TempData["Msg"] = "Record Updated Successfully";
                            return(RedirectToAction("DoctorCommissionSetting", "DoctorCommissionSetting"));
                        }
                    }
                }
                TempData["Msg"] = "Select DoctorName";
            }
            catch (Exception ex)
            {
                TempData["Msg"] = ex.Message;
                return(RedirectToAction("DoctorCommissionSetting", "DoctorCommissionSetting"));
            }
            return(RedirectToAction("DoctorCommissionSetting", "DoctorCommissionSetting"));
        }
Esempio n. 20
0
    protected void Button_find_diamonds_Click(object sender, EventArgs e)
    {
        List <string> list_shapes   = new List <string>();
        List <string> list_clarity  = new List <string>();
        List <string> list_color    = new List <string>();
        List <string> list_cut      = new List <string>();
        List <string> list_polish   = new List <string>();
        List <string> list_symmetry = new List <string>();
        List <string> list_lab      = new List <string>();
        double        weightMin;
        double        weightMax;
        double        priceMin;
        double        priceMax;
        string        name;


        #region SHAPE
        List <string> list_shapes_ = s.readfromyDS("Shape");
        foreach (var S in list_shapes_)
        {
            var chk_SHAPE = (HtmlInputCheckBox)SAHPE.FindControl("ShapeCB_" + S.ToString());


            if (chk_SHAPE.Checked == true)
            {
                list_shapes.Add(S.ToString());
            }
        }


        #endregion

        #region Weight

        HtmlInputGenericControl weightMin_control = (HtmlInputGenericControl)WEIGHT.FindControl("weightMin");
        if (weightMin_control.Value == "".ToString())
        {
            weightMin_control.Value = "0.1";
        }
        weightMin = Convert.ToDouble(weightMin_control.Value);

        HtmlInputGenericControl weightMax_control = (HtmlInputGenericControl)WEIGHT.FindControl("weightMax");
        if (weightMax_control.Value == "".ToString())
        {
            weightMax_control.Value = "0.1";
        }
        weightMax = Convert.ToDouble(weightMax_control.Value);

        #endregion

        #region Price

        HtmlInputGenericControl priceMin_control = (HtmlInputGenericControl)WEIGHT.FindControl("priceMin");
        if (priceMin_control.Value == "".ToString())
        {
            priceMin_control.Value = "1";
        }
        priceMin = Convert.ToDouble(priceMin_control.Value.ToString());

        HtmlInputGenericControl priceMax_control = (HtmlInputGenericControl)WEIGHT.FindControl("priceMax");
        if (priceMax_control.Value == "".ToString())
        {
            priceMax_control.Value = "1";
        }
        priceMax = Convert.ToDouble(priceMax_control.Value.ToString());

        #endregion

        #region CLARITY
        List <string> list_clarity_ = s.readfromyDS("Clarity");
        foreach (var C in list_clarity_)
        {
            CheckBox chk_CLARITY = (CheckBox)CLARITY.FindControl("ClarityCB_" + C.ToString());
            if (chk_CLARITY.Checked == true)
            {
                list_clarity.Add(C.ToString());
            }
        }

        #endregion

        #region COLOR
        List <string> list_color_ = s.readfromyDS("Color");
        foreach (var CR in list_color_)
        {
            CheckBox chk_COLOR = (CheckBox)COLOR.FindControl("ColorCB_" + CR.ToString());
            if (chk_COLOR.Checked == true)
            {
                list_color.Add(CR.ToString());
            }
        }

        #endregion

        #region CUT
        List <string> list_cut_ = s.readfromyDS("Cut");
        foreach (var CU_ in list_cut_)
        {
            CheckBox chk_CUT = (CheckBox)CUT.FindControl("CutCB_" + CU_.ToString());
            if (chk_CUT.Checked == true)
            {
                list_cut.Add(CU_.ToString());
            }
        }
        #endregion

        #region POLISH
        List <string> list_polish_ = s.readfromyDS("Polish");
        foreach (var P in list_polish_)
        {
            CheckBox chk_P = (CheckBox)POLISH.FindControl("PolishCB_" + P.ToString());
            if (chk_P.Checked == true)
            {
                list_polish.Add(P.ToString());
            }
        }
        #endregion

        #region SYMMETRY
        List <string> list_symmetry_ = s.readfromyDS("Symmetry");
        foreach (var SYM in list_symmetry_)
        {
            CheckBox chk_SYM = (CheckBox)SYMMETRY.FindControl("SymmetryCB_" + SYM.ToString());
            if (chk_SYM.Checked == true)
            {
                list_symmetry.Add(SYM.ToString());
            }
        }

        #endregion

        #region LAB
        List <string> list_lab_ = s.readfromyDS("Lab");
        foreach (var LAB_ in list_lab_)
        {
            CheckBox chk_LAB = (CheckBox)LAB.FindControl("LabCB_" + LAB_.ToString());
            if (chk_LAB.Checked == true)
            {
                list_lab.Add(LAB_.ToString());
            }
        }

        #endregion

        #region Name

        HtmlInputText txt_name = (HtmlInputText)NAME.FindControl("Search_By_ID".ToString());
        name = txt_name.Value;

        #endregion

        addproducts_after_filter(list_shapes,
                                 list_clarity,
                                 list_color,
                                 list_cut,
                                 list_polish,
                                 list_symmetry,
                                 list_lab,
                                 weightMin,
                                 weightMax,
                                 priceMin,
                                 priceMax,
                                 name);
    }