4 kyu

Photoshop like - Magic Wand (select pixels by threshold)

Description
Loading description...
Image Processing
Algorithms
  • Please sign in or sign up to leave a comment.
  • biinniit Avatar

    No information is given about the order of checking the pixels. Each person can assume a completely different search order and arrive and completely different answers because of this line: "summing the differences between... the pixel that was matched last with the new candidate pixel."

    The order matters.

  • KayleighWasTaken Avatar

    Test output is currently absolutely disgusting because at least it was better than the unintelligible mess that was the old one.

    Raising this issue so that people can yell at me if I don't fix it eventually.

  • KayleighWasTaken Avatar

    JS fork

    • Markdown description
    • Updates to Chai + assert
    • Improves test runtime
    • Removes weird nonsense from solution setup
    • Removes console.log spam in the tests
  • dfhwze Avatar

    This one sample test is not enough for users to figure out what to do. I'm passing the sample test, but fail on every random test. I find this recursive behavior explanation very fishy. It seems that depending on the order of recursion, other results can be provided. Or should we be able to reiterate existing pixels in case we can make new progress? This spec is very unclear to me.

  • Blind4Basics Avatar

    it should be told to the user that the x/y axis aren't those used usually for 2D arrays indexing (for now, there is only an hint about it far, far away from the top of the description...)

    • dfhwze Avatar

      how do you mean, y is rows and x is columns, seems normal, no?

    • Blind4Basics Avatar

      that convention should always be made crystal clear in descriptions. Some people use x,y notation for row,col, like indexing, but some others see that as horizontal,vertical, like in canvas coordinates.

  • Voile Avatar

    Approved ;-)

  • smile67 Avatar

    There are problems/errors with your testcases - output of your testcode (your functions) is:

    TypeError: Cannot read property '0' of null
        at getColorDistance
        at findNextPixel
        at magicWandR
            at begin
        at it
            at /runner/frameworks/javascript/cw-2.js:159:11
        at Promise._execute
        at Promise._resolveFromExecutor
        at new Promise
        at describe
                at Object.handleError
        at [eval]:4:18
    

    By the way for a kata which is a little bit more difficult (more than 7 or 6 kyu) it's really bad practice to publish it without example tests... So i had to build my own tests from your description. I don't know if everyone wants to do this or is able to do this... The output for your tests is not the best too, it's always better to show expected results and not only "not what expected". But ok, seems to me there are no random test too (and this is one reason to show no results), sorry but again "bad practice";-)... Probably it's one reason nobody solved this generally interesting (but not completely new) kata last time. So a little bit work for you - i think;-)!

    • MichaelSel Avatar

      I added an example test, I forgot to put one. Sorry about that. As for the rest of your comments, I am a little confused:

      1. I am showing the failed result vs. the expected result in this format:


      2. I do have random automated tests:

      70 to be exact

    • MichaelSel Avatar

      Lastly, There was a "," missing in the color array. I added it back in. Should now work.

      Issue marked resolved by MichaelSel 8 years ago
    • MichaelSel Avatar

      One last thing. I am new in this community. I officially joined a year ago, but wasn't active until about 2 weeks ago. I am trying to create nice puzzeles for people to solve. Your comment was a little too toxic for what it should have been. There's much I can learn about creating katas, and would love to get help. But please, don't scold users trying to contribute. Even if they make mistakes.

    • smile67 Avatar

      Thanks for your reply - i think you misunderstand, there's no intension to be toxic or something like that (if you think "...bad practice..." is a sign for toxic?). It was s description what happens to me solving your kata. And at the moment (perhaps i have to refresh some things again) i get the same error messages as yesterday. Perhaps this is the problem because i couldn't see any random tests, i always get some errors caused by functions of your tests. I tried it yesterday evening so perhaps my comment was a little bit "short" (is this toxic too?)... Generally my points are "normal points" if something isn't working - and there were some other points too, i haven't mentioned. So at the end it's your kata and if you don't need any comment, leave it as it is but don't wonder if you don't get solutions;-).

    • smile67 Avatar

      Again i get the same errors, probably because i deleted all the unnecessary functions/vars at the beginning of your initial solution (better to put it into the preload part and not into the initial solution): Example output of my function and output of your testcases:

      [ { x: 0, y: 0 },
        { x: 0, y: 1 },
        { x: 0, y: 2 },
        { x: 0, y: 3 },
        { x: 0, y: 4 },
        { x: 0, y: 5 },
        { x: 0, y: 6 },
        { x: 0, y: 7 } ]
      TypeError: Cannot read property '0' of null
          at getColorDistance
          at findNextPixel
          at magicWandR
              at begin
          at it
              at /runner/frameworks/javascript/cw-2.js:159:11
          at Promise._execute
          at Promise._resolveFromExecutor
          at new Promise
          at describe
                  at Object.handleError
          at [eval]:4:18
      
    • smile67 Avatar

      Your basic tests work now, but not the part later on:

      Time: 436ms Passed: 1 Failed: 0
      Test Results:
       Solution
       Sample test
      Completed in 20ms
      You have passed all of the tests! :)
      
    • MichaelSel Avatar

      I preloaded drawRes() as per your suggestion. I re-ran the kata, and it seems to work perfectly for me. I cannot seem to reproduce the issue you are experiencing. I also get 70 automated tests, which you don't. Not sure what's the cause, but I definitely added random tests.

    • smile67 Avatar

      Often such errors occur if you are using internal vars inside your code which aren't used or defined by/for user (code). As you can see, your functions ("at getColorDistance, at findNextPixel, at magicWandR") throw these errors, not my. Another possibility is: i give you totally wrong results/outputs which your functions can't handle (wrong types or somethink like that)... But i don't think that my output is too bad (see my older example);-), maybe wrong content, but no reason to throw some "system errors";-)...

    • MichaelSel Avatar

      I re-ran everything. I made sure there are no vars that are needed.

      Works for me like a charm.

      In my solution there is nothing outside of :

      var magicWand = function (arr,point,t) { //arr=the image, point=starting point, t=threshold
        //my code
        return result 
      }

      And it passes for all 71 tests.

      Perhaps you have an "old" cached version?

      Are you sure your output is an array of objects such as: [ {x:x1,y:y1}, {x:x2,y:y2}, ... {x:xn,y:yn} ]

    • smile67 Avatar

      Yes, same form of output (checked it via console.log and everything looks fine). So first of all thanks for your testing, i'm a little bit busy now, so i will check later once again... You can see my basic test result (i added your description- example, so two basic tests - i did a "reset" before):

      Test Results:
       Solution
       Sample test
       Log
      expected
       x |  |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
       x |   |   |   |   |   |
      Test Passed: Value deep equals [{ x: 0, y: 0 }, { x: 0, y: 1 }, { x: 0, y: 2 }, { x: 0, y: 3 }, { x: 0, y: 4 }, { x: 0, y: 5 }, { x: 0, y: 6 }, { x: 0, y: 7 }]
       Log
      expected
       x | x | x |
         | x |   |
         |   | x |
      Test Passed: Value deep equals [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 2 }]
      Completed in 17ms
      Completed in 21ms
      You have passed all of the tests! :)
      

      Maybe a very simple bug;-)...

    • smile67 Avatar

      And here is the result for your first test ("Attempt button"), console.log for my solution before returning the result:

       Sample test
       Log
      [ { x: 0, y: 0 },
       { x: 0, y: 1 },
        { x: 0, y: 2 },
        { x: 0, y: 3 },
        { x: 0, y: 4 },
        { x: 0, y: 5 },
        { x: 0, y: 6 },
        { x: 0, y: 7 } ]
      TypeError: Cannot read property '0' of null
          at getColorDistance
          at findNextPixel
          at magicWandR
              at begin
          at it
              at /runner/frameworks/javascript/cw-2.js:159:11
          at Promise._execute
          at Promise._resolveFromExecutor
          at new Promise
          at describe
                  at Object.handleError
          at [eval]:4:18
      
    • MichaelSel Avatar

      Can you paste your code? I want to see if I can reproduce this issue... Thanks for taking the time to help

    • smile67 Avatar

      This comment has been hidden.

    • smile67 Avatar

      @MichaelSel: Can you plaese check my last comment (2 days old) - i only updated the text, so you probably got no new message... thanks;-)...

    • MichaelSel Avatar

      Hi! Thank you so much for helping out!

      You are right that (3,1)-(4,1) is above the threshold. BUT (3,0)-(4,1) is within the threshold! 154-134 + 138-51 + 136-118 = 20 + 87 + 18 = 125 :)

      You also need to look at pixels diagonally

      Or was your confusion about which two pixels to compare with the threshold? Are you always comparing the new pixel to the original pixel? If so, then no. It should be compared to the neighboring pixels. I'll make it clearer in the description. I really sorry about the confusion. And again, thank you for taking the time to help! Sorry about the confusion

    • MichaelSel Avatar

      I updated the description. I hope this is clearer:

    • smile67 Avatar

      This comment has been hidden.

    • smile67 Avatar

      Hi, yes for me it's clearer now (this was my confusion) - thanks;-)! So i submitted my working solution:-)! It's a good kata, well done, so thanks again for your work! I ranked it as 4kyu, probably a little bit high, but with all these tests and missunderstandings;-)... And it's a little bit harder than most similar katas of the last time... So not really too important and we will see the average voting later on.

    • MichaelSel Avatar

      I'm so happy we solve the major kinks! I agree with the ranking. It's definitely not 3kyu! But seems a little hard for 5.

      I am trying to demystify image proccessing for myself by writing katas. So far, it's working nicely :)

    • smile67 Avatar

      Yes, saw your other kata "...count frames...", probably i will solve it next time too:-)... Image processing is really interesting, there are some other katas too (like https://www.codewars.com/kata/image-processing)... You can look in my "small published kata list", there are some "older graphic- katas" too, but only C# not Javascript;-)... So keep up your good work:-)!

    • MichaelSel Avatar

      I'll check some of yours out :)