Finding nearest color in RGB?Generate distinctly different RGB colors in graphsHow can I color Python logging output?Formula to determine brightness of RGB colorFinding nearest RGB colourCalculation of a mixed color in RGBHow to get different colored lines for different plots in a single figure?Understanding colors on Android (six characters)Programmatically Lighten or Darken a hex color (or rgb, and blend colors)RGB to Hex and Hex to RGBHex transparency in colors

As a 16 year old, how can I keep my money safe from my mother?

How to mark beverage cans in a cooler for a blind person?

Should I take out a personal loan to pay off credit card debt?

Does the United States guarantee any unique freedoms?

Ex-contractor published company source code and secrets online

Improving software when the author can see no need for improvement

Can you use the Fly spell to move underwater at a speed of 60 feet?

Why are physicists so interested in irreps if in their non-block-diagonal form they mix all components of a vector?

Dropdowns & Chevrons for Right to Left languages

What happen if I gain the control of aura that enchants an opponent's creature? Would the aura stop being attached?

Are there any financial disadvantages to living significantly "below your means"?

What is the best way to cause swarm intelligence to be destroyed?

What are good ways to improve as a writer other than writing courses?

Acceptable to cut steak before searing?

How quickly could a country build a tall concrete wall around a city?

Shabbat clothing on shabbat chazon

How can I tell if a flight itinerary is fake?

Best gun to modify into a monsterhunter weapon?

How to write "upright" integrals with automatic sizing

Why was CPU32 core created, and how is it different from 680x0 CPU cores?

Creating a new project with Laravel throws an exception

Colleagues speaking another language and it impacts work

How do we avoid CI-driven development...?

Why did the RAAF procure the F/A-18 despite being purpose-built for carriers?



Finding nearest color in RGB?


Generate distinctly different RGB colors in graphsHow can I color Python logging output?Formula to determine brightness of RGB colorFinding nearest RGB colourCalculation of a mixed color in RGBHow to get different colored lines for different plots in a single figure?Understanding colors on Android (six characters)Programmatically Lighten or Darken a hex color (or rgb, and blend colors)RGB to Hex and Hex to RGBHex transparency in colors






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have to find the nearest color. For example, I have two colors colorA1, colorA2 which are nearly same color. And also I have other color colorB1.
And I need such a method:
Color getNearestColor(colorA1, colorA2, colorB1). This method should give me the colorB2 which is calculated by using the difference of colorA1 and colorA2, then using their distance it should give me colorB2 which has the same distance as in colorA1 and colorA2.
Can you give some ideas how to implement it?










share|improve this question






























    0















    I have to find the nearest color. For example, I have two colors colorA1, colorA2 which are nearly same color. And also I have other color colorB1.
    And I need such a method:
    Color getNearestColor(colorA1, colorA2, colorB1). This method should give me the colorB2 which is calculated by using the difference of colorA1 and colorA2, then using their distance it should give me colorB2 which has the same distance as in colorA1 and colorA2.
    Can you give some ideas how to implement it?










    share|improve this question


























      0












      0








      0








      I have to find the nearest color. For example, I have two colors colorA1, colorA2 which are nearly same color. And also I have other color colorB1.
      And I need such a method:
      Color getNearestColor(colorA1, colorA2, colorB1). This method should give me the colorB2 which is calculated by using the difference of colorA1 and colorA2, then using their distance it should give me colorB2 which has the same distance as in colorA1 and colorA2.
      Can you give some ideas how to implement it?










      share|improve this question














      I have to find the nearest color. For example, I have two colors colorA1, colorA2 which are nearly same color. And also I have other color colorB1.
      And I need such a method:
      Color getNearestColor(colorA1, colorA2, colorB1). This method should give me the colorB2 which is calculated by using the difference of colorA1 and colorA2, then using their distance it should give me colorB2 which has the same distance as in colorA1 and colorA2.
      Can you give some ideas how to implement it?







      colors rgb






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 6:55









      Iriskul TurduevIriskul Turduev

      768 bronze badges




      768 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1














          To find the nearest colour, you need a definition of "near", so a metric.



          In Wikipedia you will find different metrics of color differences.



          Personally I would use the 2*R*R + 4*G*G + 3*B*B. (no need for square roots, you will just compare same metrics). Easy to calculate, you can use just integers (if you use 32 bit integers, you will have no overflow).



          Then find which colour has the smallest differences between your target colour.



          The other methods are more precise, but in that case "RGB" is not enough. You need to know which colour space are using (probably you are in sRGB).






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371390%2ffinding-nearest-color-in-rgb%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            To find the nearest colour, you need a definition of "near", so a metric.



            In Wikipedia you will find different metrics of color differences.



            Personally I would use the 2*R*R + 4*G*G + 3*B*B. (no need for square roots, you will just compare same metrics). Easy to calculate, you can use just integers (if you use 32 bit integers, you will have no overflow).



            Then find which colour has the smallest differences between your target colour.



            The other methods are more precise, but in that case "RGB" is not enough. You need to know which colour space are using (probably you are in sRGB).






            share|improve this answer





























              1














              To find the nearest colour, you need a definition of "near", so a metric.



              In Wikipedia you will find different metrics of color differences.



              Personally I would use the 2*R*R + 4*G*G + 3*B*B. (no need for square roots, you will just compare same metrics). Easy to calculate, you can use just integers (if you use 32 bit integers, you will have no overflow).



              Then find which colour has the smallest differences between your target colour.



              The other methods are more precise, but in that case "RGB" is not enough. You need to know which colour space are using (probably you are in sRGB).






              share|improve this answer



























                1












                1








                1







                To find the nearest colour, you need a definition of "near", so a metric.



                In Wikipedia you will find different metrics of color differences.



                Personally I would use the 2*R*R + 4*G*G + 3*B*B. (no need for square roots, you will just compare same metrics). Easy to calculate, you can use just integers (if you use 32 bit integers, you will have no overflow).



                Then find which colour has the smallest differences between your target colour.



                The other methods are more precise, but in that case "RGB" is not enough. You need to know which colour space are using (probably you are in sRGB).






                share|improve this answer













                To find the nearest colour, you need a definition of "near", so a metric.



                In Wikipedia you will find different metrics of color differences.



                Personally I would use the 2*R*R + 4*G*G + 3*B*B. (no need for square roots, you will just compare same metrics). Easy to calculate, you can use just integers (if you use 32 bit integers, you will have no overflow).



                Then find which colour has the smallest differences between your target colour.



                The other methods are more precise, but in that case "RGB" is not enough. You need to know which colour space are using (probably you are in sRGB).







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 11:55









                Giacomo CatenazziGiacomo Catenazzi

                2,7171 gold badge9 silver badges18 bronze badges




                2,7171 gold badge9 silver badges18 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55371390%2ffinding-nearest-color-in-rgb%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript